Go Release Build #2
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: Go Release Build | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release Version (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| notes: | |
| description: 'Release Notes (optional)' | |
| required: false | |
| type: string | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.24' | |
| - name: Go Cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/go/pkg/mod | |
| ~/.cache/go-build | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Get current date for version fallback | |
| id: date | |
| run: echo "DATE=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV | |
| - name: Set release version | |
| # Use provided input version, or fall back to date if empty (though input is required in this setup) | |
| # This step ensures the version is available as an environment variable. | |
| run: | | |
| RELEASE_VERSION=${{ inputs.version }} | |
| if [ -z "$RELEASE_VERSION" ]; then | |
| RELEASE_VERSION="v0.0.0-${{ env.DATE }}" # Fallback for safety, though input is required | |
| fi | |
| echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV | |
| echo "Building version: $RELEASE_VERSION" | |
| - name: Build and package for Linux | |
| run: | | |
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o SBOLogProcessor | |
| tar -czvf SBOLogProcessor-linux-amd64-${{ env.RELEASE_VERSION }}.tar.gz SBOLogProcessor | |
| working-directory: ./ # Adjust if your main.go is in a subfolder | |
| - name: Build and package for Windows | |
| run: | | |
| CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o SBOLogProcessor.exe | |
| zip SBOLogProcessor-windows-amd64-${{ env.RELEASE_VERSION }}.zip SBOLogProcessor.exe | |
| working-directory: ./ | |
| - name: Build and package for macOS (AMD64) | |
| run: | | |
| CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o SBOLogProcessor | |
| tar -czvf SBOLogProcessor-darwin-amd64-${{ env.RELEASE_VERSION }}.tar.gz SBOLogProcessor | |
| working-directory: ./ | |
| - name: Build and package for macOS (ARM64 - Apple Silicon) | |
| run: | | |
| CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${{ env.RELEASE_VERSION }}" -o SBOLogProcessor | |
| tar -czvf SBOLogProcessor-darwin-arm64-${{ env.RELEASE_VERSION }}.tar.gz SBOLogProcessor | |
| working-directory: ./ | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.RELEASE_VERSION }} | |
| name: Release ${{ env.RELEASE_VERSION }} | |
| body: ${{ inputs.notes }} # Use the provided release notes | |
| draft: true # Set to true if you want to review before publishing | |
| prerelease: ${{ contains(env.RELEASE_VERSION, 'rc') || contains(env.RELEASE_VERSION, 'beta') || contains(env.RELEASE_VERSION, 'alpha') }} # Auto-detect prerelease from version string | |
| files: | | |
| SBOLogProcessor-linux-amd64-${{ env.RELEASE_VERSION }}.tar.gz | |
| SBOLogProcessor-windows-amd64-${{ env.RELEASE_VERSION }}.zip | |
| SBOLogProcessor-darwin-amd64-${{ env.RELEASE_VERSION }}.tar.gz | |
| SBOLogProcessor-darwin-arm64-${{ env.RELEASE_VERSION }}.tar.gz | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub Actions |