Skip to content

Commit

Permalink
CI: Add custom build-script containing API and CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Knut Ahlers <knut@ahlers.me>
  • Loading branch information
Luzifer committed Oct 4, 2023
1 parent c02a294 commit a089113
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.build
customize.yaml
frontend/api.html
frontend/app.css
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
65 changes: 65 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/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 "${root}/.build/${3}_${1}_${2}.tgz" "${outname}"
else
log "=> Packging ${3} as ${3}_${1}_${2}.zip..."
zip "${root}/.build/${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)
version="$(git describe --tags --always || echo dev)"

log "Building version ${version}..."

log "Resetting output directory..."
rm -rf "${root}/.build"
mkdir -p "${root}/.build"

log "Building API-Server..."
go_package_all "ots" "."

log "Building OTS-CLI..."
go_package_all "ots-cli" "./cmd/ots-cli"

log "Compiling SHA256SUMS file..."
(cd "${root}/.build" && sha256sum * >SHA256SUMS)

0 comments on commit a089113

Please sign in to comment.