Build binary #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build binary | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_version: | |
| description: "Release version (e.g., v2.0.0)" | |
| required: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: "stable" | |
| - name: Install ARM64 cross compiler | |
| run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu | |
| - name: Build for linux/windows (amd64 + arm64) | |
| run: | | |
| set -e | |
| mkdir -p dist/linux dist/windows | |
| TARGETS=( | |
| "linux amd64" | |
| "linux arm64" | |
| "windows amd64" | |
| "windows arm64" | |
| ) | |
| for t in "${TARGETS[@]}"; do | |
| read -r GOOS GOARCH <<< "$t" | |
| echo "Building for $GOOS/$GOARCH" | |
| ext="" | |
| outdir="dist/$GOOS" | |
| mkdir -p "$outdir" | |
| if [[ "$GOOS" == "windows" ]]; then ext=".exe"; fi | |
| if [[ "$GOOS" == "linux" ]]; then | |
| CGO_ENABLED=1 | |
| if [[ "$GOARCH" == "arm64" ]]; then | |
| export CC=aarch64-linux-gnu-gcc | |
| fi | |
| else | |
| CGO_ENABLED=0 | |
| fi | |
| CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH \ | |
| go build -o "$outdir/lanctrl-${GOOS}-${GOARCH}${ext}" ./src/main.go | |
| done | |
| shell: bash | |
| - name: Show built files | |
| run: ls -R dist | |
| shell: bash | |
| - name: Upload Windows artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binary-Windows | |
| path: dist/windows/* | |
| - name: Upload Linux artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binary-Linux | |
| path: dist/linux/* | |
| merge-artifacts: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download Windows binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binary-Windows | |
| path: combined-binaries | |
| - name: Download Linux binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binary-Linux | |
| path: combined-binaries | |
| - name: List combined contents | |
| run: ls -R combined-binaries | |
| shell: bash | |
| - name: Upload combined artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries-${{ github.event.inputs.release_version }} | |
| path: combined-binaries |