From 04e9cda1d185ed966a502e1434b5622dbb1b2405 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 4 Oct 2023 19:14:38 +0200 Subject: [PATCH] CI: Add custom build-script containing API and CLI Signed-off-by: Knut Ahlers --- .gitignore | 1 + Makefile | 3 +-- ci/build.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 ci/build.sh diff --git a/.gitignore b/.gitignore index 794aad4..48dace5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.build customize.yaml frontend/api.html frontend/app.css diff --git a/Makefile b/Makefile index 69bf56e..f5d80eb 100644 --- a/Makefile +++ b/Makefile @@ -23,8 +23,7 @@ generate-inner: node ./ci/build.mjs publish: download_libs generate-inner generate-apidocs - curl -sSLo golang.sh https://raw.githubusercontent.com/Luzifer/github-publish/master/golang.sh - bash golang.sh + bash ./ci/build.sh translate: cd ci/translate && go run . diff --git a/ci/build.sh b/ci/build.sh new file mode 100644 index 0000000..fe0bf38 --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash +set -euo pipefail + +osarch=( + darwin/amd64 + darwin/arm64 + linux/amd64 + linux/arm + linux/arm64 + windows/amd64 +) + +function go_package() { + cd "${4}" + + local outname="${3}" + [[ $1 == windows ]] && outname="${3}.exe" + + log "=> Building ${3} for ${1}/${2}..." + CGO_ENABLED=0 GOARCH=$2 GOOS=$1 go build \ + -ldflags "-s -w -X main.version=${version}" \ + -mod=readonly \ + -trimpath \ + -o "${outname}" + + if [[ $1 == linux ]]; then + log "=> Packging ${3} as ${3}_${1}_${2}.tgz..." + tar -czf "${builddir}/${3}_${1}_${2}.tgz" "${outname}" + else + log "=> Packging ${3} as ${3}_${1}_${2}.zip..." + zip "${builddir}/${3}_${1}_${2}.zip" "${outname}" + fi + + rm "${outname}" +} + +function go_package_all() { + for oa in "${osarch[@]}"; do + local os=$(cut -d / -f 1 <<<"${oa}") + local arch=$(cut -d / -f 2 <<<"${oa}") + (go_package "${os}" "${arch}" "${1}" "${2}") + done +} + +function log() { + echo "[$(date +%H:%M:%S)] $@" >&2 +} + +root=$(pwd) +builddir="${root}/.build" +version="$(git describe --tags --always || echo dev)" + +log "Building version ${version}..." + +log "Resetting output directory..." +rm -rf "${builddir}" +mkdir -p "${builddir}" + +log "Building API-Server..." +go_package_all "ots" "." + +log "Building OTS-CLI..." +go_package_all "ots-cli" "./cmd/ots-cli" + +log "Generating SHA256SUMS file..." +(cd "${builddir}" && sha256sum * | tee SHA256SUMS)