From 523ef92dac833e183be1feed703f709cdfed7b6d Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sat, 28 Oct 2023 22:33:34 +0200 Subject: [PATCH] use build outputs --- .github/workflows/binary-build.yml | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/binary-build.yml b/.github/workflows/binary-build.yml index a551589..f99271a 100644 --- a/.github/workflows/binary-build.yml +++ b/.github/workflows/binary-build.yml @@ -9,9 +9,23 @@ on: - latest jobs: + determine_version: + runs-on: ubuntu-latest + outputs: + build_version: ${{ steps.set_version.outputs.version }} + steps: + - id: set_version + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + echo "::set-output name=version::${GITHUB_REF#refs/tags/}" + else + echo "::set-output name=version::latest" + fi + build: name: Build runs-on: ubuntu-latest + needs: determine_version strategy: matrix: goos: [windows, darwin, linux] @@ -31,17 +45,9 @@ jobs: with: go-version: 'stable' - - name: Determine version/tag - run: | - if [[ $GITHUB_REF == refs/tags/* ]]; then - echo "BUILD_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - else - echo "BUILD_VERSION=latest" >> $GITHUB_ENV - fi - - name: Build run: | - CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o zurg-${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }} cmd/zurg/main.go + CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }} cmd/zurg/main.go # Install and use UPX to compress the binary, but exclude specific combinations - name: Install and Compress with UPX @@ -49,12 +55,12 @@ jobs: run: | sudo apt-get update sudo apt-get install -y upx-ucl - upx --best zurg-${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }} + upx --best zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }} # Zip the binary - name: Zip Binary run: | - zip zurg-${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.zip zurg-${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }} + zip zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}.zip zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }} # List files (for debugging) - name: List files @@ -63,5 +69,5 @@ jobs: - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: zurg-${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.zip - path: zurg-${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.zip + name: zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}.zip + path: zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}.zip