ci: add multi-dist build step

This commit is contained in:
Marc 2024-01-31 23:53:09 -05:00
parent 27df322a50
commit 4468a70870
Signed by: marc
GPG key ID: 048E042F22B5DC79
2 changed files with 34 additions and 2 deletions

View file

@ -10,7 +10,7 @@ env:
GO_VERSION: '1.21'
jobs:
tests:
test:
name: "Tests"
runs-on: ubuntu-latest
steps:
@ -39,3 +39,23 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- run: . integration/install_specific_version.sh
build:
name: "Build"
runs-on: ubuntu-latest
needs: [test,format,integration-tests]
strategy:
matrix:
dist: ["darwin_amd64", "darwin_arm64", "linux_amd64"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- run: PROD=$PROD GOOS=${DIST%_*} GOARCH=${DIST#*_} . script/build.sh
env:
DIST: ${{ matrix.dist }}
PROD: ${{ github.ref == 'refs/heads/main' && '1' || '' }}
- uses: actions/upload-artifact@v4
with:
name: build-${{matrix.dist}}
path: ./build/**/*

View file

@ -1,3 +1,15 @@
#!/usr/bin/bash
go build .
OS=$(GOOS=$GOOS go env GOOS)
ARCH=$(GOARCH=$GOARCH go env GOARCH)
if [[ -z "$PROD" ]]; then
CURRENT_COMMIT=$(git rev-parse HEAD)
BUILD_PATH="build/$OS-$ARCH-$CURRENT_COMMIT"
mkdir -p $BUILD_PATH
GOOS=$OS GOARCH=$ARCH go build -o $BUILD_PATH -v -x .
else
BUILD_PATH="build/$OS-$ARCH"
mkdir -p $BUILD_PATH .
GOOS=$OS GOARCH=$ARCH go build -o $BUILD_PATH -ldflags "-w -s" .
fi