diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c7096ef..213c5e7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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/**/* diff --git a/script/build.sh b/script/build.sh index f7f1aad..7dfd857 100644 --- a/script/build.sh +++ b/script/build.sh @@ -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