change pattern of binary builds

This commit is contained in:
Ben Sarmiento
2023-10-28 22:08:06 +02:00
parent c629f1c2dd
commit c1a7c48e04

View File

@@ -15,7 +15,7 @@ jobs:
strategy: strategy:
matrix: matrix:
goos: [windows, darwin, linux] goos: [windows, darwin, linux]
goarch: [386, amd64, arm, arm64] # This list can be expanded based on your requirements goarch: [386, amd64, arm, arm64]
exclude: exclude:
- goos: darwin - goos: darwin
goarch: 386 goarch: 386
@@ -29,28 +29,39 @@ jobs:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v4 uses: actions/setup-go@v4
with: with:
go-version: 'stable' # Adjust according to your Go version 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 - name: Build
run: | run: |
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o zurg-v${GITHUB_REF#refs/tags/}-${{ matrix.goos }}-${{ matrix.goarch }} cmd/zurg/main.go CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o zurg-v${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }} cmd/zurg/main.go
# Install and use UPX to compress the binary, but exclude windows/amd64 # Install and use UPX to compress the binary, but exclude specific combinations
- name: Install and Compress with UPX - name: Install and Compress with UPX
if: (matrix.goos != 'windows' && matrix.goarch != 'arm') || (matrix.goos != 'windows' && matrix.goarch != 'arm64') if: (matrix.goos != 'windows' || matrix.goarch != 'arm') && (matrix.goos != 'windows' || matrix.goarch != 'arm64')
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y upx-ucl sudo apt-get install -y upx-ucl
upx --best zurg-v${GITHUB_REF#refs/tags/}-${{ matrix.goos }}-${{ matrix.goarch }} upx --best zurg-v${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}
# Zip the binary # Zip the binary
- name: Zip Binary - name: Zip Binary
run: | run: |
zip zurg-v${GITHUB_REF#refs/tags/}-${{ matrix.goos }}-${{ matrix.goarch }}.zip zurg-v${GITHUB_REF#refs/tags/}-${{ matrix.goos }}-${{ matrix.goarch }} zip zurg-v${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.zip zurg-v${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}
# List files (for debugging)
- name: List files
run: ls -alh
- name: Upload Artifacts - name: Upload Artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: zurg-v${GITHUB_REF#refs/tags/}-${{ matrix.goos }}-${{ matrix.goarch }}.zip name: zurg-v${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.zip
path: | path: zurg-v${BUILD_VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.zip
zurg-v${GITHUB_REF#refs/tags/}-${{ matrix.goos }}-${{ matrix.goarch }}.zip