|
| 1 | +name: Go Release Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Release Version (e.g., v1.0.0)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + notes: |
| 11 | + description: 'Release Notes (optional)' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Go |
| 23 | + uses: actions/setup-go@v5 |
| 24 | + with: |
| 25 | + go-version: '1.24' |
| 26 | + |
| 27 | + - name: Go Cache |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: | |
| 31 | + ~/go/pkg/mod |
| 32 | + ~/.cache/go-build |
| 33 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 34 | + restore-keys: | |
| 35 | + ${{ runner.os }}-go- |
| 36 | +
|
| 37 | + - name: Get current date for version fallback |
| 38 | + id: date |
| 39 | + run: echo "DATE=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV |
| 40 | + |
| 41 | + - name: Set release version |
| 42 | + # Use provided input version, or fall back to date if empty (though input is required in this setup) |
| 43 | + # This step ensures the version is available as an environment variable. |
| 44 | + run: | |
| 45 | + RELEASE_VERSION=${{ inputs.version }} |
| 46 | + if [ -z "$RELEASE_VERSION" ]; then |
| 47 | + RELEASE_VERSION="v0.0.0-${{ env.DATE }}" # Fallback for safety, though input is required |
| 48 | + fi |
| 49 | + echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV |
| 50 | + echo "Building version: $RELEASE_VERSION" |
| 51 | +
|
| 52 | + - name: Build and package for Linux |
| 53 | + run: | |
| 54 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o myapp-linux-amd64 |
| 55 | + tar -czvf myapp-linux-amd64-${{ env.RELEASE_VERSION }}.tar.gz myapp-linux-amd64 |
| 56 | + working-directory: ./ # Adjust if your main.go is in a subfolder |
| 57 | + |
| 58 | + - name: Build and package for Windows |
| 59 | + run: | |
| 60 | + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o myapp-windows-amd64.exe |
| 61 | + zip myapp-windows-amd64-${{ env.RELEASE_VERSION }}.zip myapp-windows-amd64.exe |
| 62 | + working-directory: ./ |
| 63 | + |
| 64 | + - name: Build and package for macOS (AMD64) |
| 65 | + run: | |
| 66 | + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o myapp-darwin-amd64 |
| 67 | + tar -czvf myapp-darwin-amd64-${{ env.RELEASE_VERSION }}.tar.gz myapp-darwin-amd64 |
| 68 | + working-directory: ./ |
| 69 | + |
| 70 | + - name: Build and package for macOS (ARM64 - Apple Silicon) |
| 71 | + run: | |
| 72 | + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o myapp-darwin-arm64 |
| 73 | + tar -czvf myapp-darwin-arm64-${{ env.RELEASE_VERSION }}.tar.gz myapp-darwin-arm64 |
| 74 | + working-directory: ./ |
| 75 | + |
| 76 | + - name: Create Release |
| 77 | + id: create_release |
| 78 | + uses: softprops/action-gh-release@v2 |
| 79 | + with: |
| 80 | + tag_name: ${{ env.RELEASE_VERSION }} |
| 81 | + name: Release ${{ env.RELEASE_VERSION }} |
| 82 | + body: ${{ inputs.notes }} # Use the provided release notes |
| 83 | + draft: true # Set to true if you want to review before publishing |
| 84 | + prerelease: ${{ contains(env.RELEASE_VERSION, 'rc') || contains(env.RELEASE_VERSION, 'beta') || contains(env.RELEASE_VERSION, 'alpha') }} # Auto-detect prerelease from version string |
| 85 | + files: | |
| 86 | + SBOLogProcessor-linux-amd64-${{ env.RELEASE_VERSION }}.tar.gz |
| 87 | + SBOLogProcessor-windows-amd64-${{ env.RELEASE_VERSION }}.zip |
| 88 | + SBOLogProcessor-darwin-amd64-${{ env.RELEASE_VERSION }}.tar.gz |
| 89 | + SBOLogProcessor-darwin-arm64-${{ env.RELEASE_VERSION }}.tar.gz |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub Actions |
0 commit comments