Release binary #11
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: Release binary | |
| on: | |
| schedule: | |
| - cron: '0 0 * * 0' # Weekly Patch (Sundays) | |
| - cron: '0 0 1 * *' # Monthly Minor (1st of the month) | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: 'Manual Release Level' | |
| required: true | |
| default: 'major' | |
| type: choice | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| release_tag: | |
| description: 'Specify the new release tag name (e.g., v1.2.3)' | |
| required: false | |
| type: string | |
| target_commit: | |
| description: 'Optional commit SHA/branch to release (leave empty for current HEAD)' | |
| required: false | |
| type: string | |
| default: '' | |
| jobs: | |
| prepare_release: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.bump_logic.outputs.tag }} | |
| should_release: ${{ steps.check.outputs.count > 0 }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.inputs.target_commit || github.sha }} | |
| - name: Check for recent commits | |
| id: check | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "count=1" >> $GITHUB_OUTPUT | |
| else | |
| COUNT=$(git log --since="1 week ago" --oneline | wc -l) | |
| echo "count=$COUNT" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Determine Version Bump | |
| if: steps.check.outputs.count > 0 | |
| id: bump_logic | |
| run: | | |
| if [ "${{ github.event.inputs.release_tag }}" = "" ]; then | |
| BUMP="patch" | |
| if [ "$(date +%d)" = "01" ]; then BUMP="minor"; fi | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| BUMP="${{ github.event.inputs.version_type }}" | |
| fi | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0") | |
| # Strip the 'v' prefix | |
| BASE_VERSION=${LATEST_TAG#v} | |
| IFS='.' read -r major minor patch <<< "$BASE_VERSION" | |
| if [ "$BUMP" = "major" ]; then | |
| major=$((major + 1)); minor=0; patch=0 | |
| elif [ "$BUMP" = "minor" ]; then | |
| minor=$((minor + 1)); patch=0 | |
| else | |
| patch=$((patch + 1)) | |
| fi | |
| NEW_TAG="v$major.$minor.$patch" | |
| else | |
| NEW_TAG="${{ github.event.inputs.release_tag }}" | |
| fi | |
| echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT | |
| echo "Using version: $NEW_TAG" | |
| - name: Draft Release Notes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| uses: release-drafter/release-drafter@v6 | |
| with: | |
| version: ${{ steps.bump_logic.outputs.tag }} | |
| tag: ${{ steps.bump_logic.outputs.tag }} | |
| - name: Create GitHub Release | |
| if: steps.check.outputs.count > 0 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "${{ steps.bump_logic.outputs.tag }}" \ | |
| --title "${{ steps.bump_logic.outputs.tag }}" \ | |
| --generate-notes \ | |
| --draft | |
| upload_assets: | |
| needs: prepare_release | |
| if: needs.prepare_release.outputs.should_release == 'true' | |
| strategy: | |
| matrix: | |
| platform: [ubuntu-x86, mac-arm64] | |
| include: | |
| - platform: ubuntu-x86 | |
| runner: ubuntu-24.04 | |
| - platform: mac-arm64 | |
| runner: macos-latest | |
| runs-on: ${{ matrix.runner }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.inputs.target_commit || github.ref }} | |
| - uses: ./.github/actions/environment-setup | |
| - name: Build Binaries | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| cd src | |
| TAG="${{ needs.prepare_release.outputs.tag }}" | |
| bazel build --show_timestamps --copt=-O3 --verbose_failures \ | |
| -- //software:unix_full_system_tar_gen | |
| mv bazel-bin/software/unix_full_system_tar_gen.tar.gz "${{ runner.temp }}/unix_full_system_${{ needs.prepare_release.outputs.tag }}_${{ matrix.platform }}.tar.gz" | |
| gh release upload "$TAG" "${{ runner.temp }}/unix_full_system_${{ needs.prepare_release.outputs.tag }}_${{ matrix.platform }}.tar.gz" | |
| publish_release: | |
| needs: [prepare_release, upload_assets] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.target_commit || github.sha }} | |
| - name: Undraft Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: gh release edit "${{ needs.prepare_release.outputs.tag }}" --draft=false |