|
| 1 | +name: Release binary |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * 0' # Weekly Patch (Sundays) |
| 6 | + - cron: '0 0 1 * *' # Monthly Minor (1st of the month) |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version_type: |
| 10 | + description: 'Manual Release Level' |
| 11 | + required: true |
| 12 | + default: 'major' |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - major |
| 16 | + - minor |
| 17 | + - patch |
| 18 | + release_tag: |
| 19 | + description: 'Specify the new release tag name (e.g., v1.2.3)' |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + |
| 23 | + target_commit: |
| 24 | + description: 'Optional commit SHA/branch to release (leave empty for current HEAD)' |
| 25 | + required: false |
| 26 | + type: string |
| 27 | + default: '' |
| 28 | + |
| 29 | +jobs: |
| 30 | + prepare_release: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + outputs: |
| 33 | + tag: ${{ steps.bump_logic.outputs.tag }} |
| 34 | + should_release: ${{ steps.check.outputs.count > 0 }} |
| 35 | + permissions: |
| 36 | + contents: write |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + ref: ${{ github.event.inputs.target_commit || github.sha }} |
| 42 | + |
| 43 | + - name: Check for recent commits |
| 44 | + id: check |
| 45 | + run: | |
| 46 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 47 | + echo "count=1" >> $GITHUB_OUTPUT |
| 48 | + else |
| 49 | + COUNT=$(git log --since="1 week ago" --oneline | wc -l) |
| 50 | + echo "count=$COUNT" >> $GITHUB_OUTPUT |
| 51 | + fi |
| 52 | + |
| 53 | + - name: Determine Version Bump |
| 54 | + if: steps.check.outputs.count > 0 |
| 55 | + id: bump_logic |
| 56 | + run: | |
| 57 | + if [ "${{ github.event.inputs.release_tag }}" = "" ]; then |
| 58 | + BUMP="patch" |
| 59 | + if [ "$(date +%d)" = "01" ]; then BUMP="minor"; fi |
| 60 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 61 | + BUMP="${{ github.event.inputs.version_type }}" |
| 62 | + fi |
| 63 | + |
| 64 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0") |
| 65 | + # Strip the 'v' prefix |
| 66 | + BASE_VERSION=${LATEST_TAG#v} |
| 67 | + |
| 68 | + IFS='.' read -r major minor patch <<< "$BASE_VERSION" |
| 69 | + |
| 70 | + if [ "$BUMP" = "major" ]; then |
| 71 | + major=$((major + 1)); minor=0; patch=0 |
| 72 | + elif [ "$BUMP" = "minor" ]; then |
| 73 | + minor=$((minor + 1)); patch=0 |
| 74 | + else |
| 75 | + patch=$((patch + 1)) |
| 76 | + fi |
| 77 | + |
| 78 | + NEW_TAG="v$major.$minor.$patch" |
| 79 | + else |
| 80 | + NEW_TAG="${{ github.event.inputs.release_tag }}" |
| 81 | + fi |
| 82 | + echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT |
| 83 | + echo "Using version: $NEW_TAG" |
| 84 | +
|
| 85 | + - name: Draft Release Notes |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + uses: release-drafter/release-drafter@v6 |
| 89 | + with: |
| 90 | + version: ${{ steps.bump_logic.outputs.tag }} |
| 91 | + tag: ${{ steps.bump_logic.outputs.tag }} |
| 92 | + |
| 93 | + - name: Create GitHub Release |
| 94 | + if: steps.check.outputs.count > 0 |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + run: | |
| 98 | + gh release create "${{ steps.bump_logic.outputs.tag }}" \ |
| 99 | + --title "${{ steps.bump_logic.outputs.tag }}" \ |
| 100 | + --generate-notes \ |
| 101 | + --draft |
| 102 | +
|
| 103 | + upload_assets: |
| 104 | + needs: prepare_release |
| 105 | + if: needs.prepare_release.outputs.should_release == 'true' |
| 106 | + strategy: |
| 107 | + matrix: |
| 108 | + platform: [ubuntu-x86, mac-arm64] |
| 109 | + include: |
| 110 | + - platform: ubuntu-x86 |
| 111 | + runner: ubuntu-24.04 |
| 112 | + - platform: mac-arm64 |
| 113 | + runner: macos-latest |
| 114 | + runs-on: ${{ matrix.runner }} |
| 115 | + permissions: |
| 116 | + contents: write |
| 117 | + steps: |
| 118 | + - uses: actions/checkout@v4 |
| 119 | + with: |
| 120 | + fetch-depth: 0 |
| 121 | + ref: ${{ github.event.inputs.target_commit || github.ref }} |
| 122 | + |
| 123 | + - uses: ./.github/actions/environment-setup |
| 124 | + |
| 125 | + - name: Build Binaries |
| 126 | + env: |
| 127 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + run: | |
| 129 | + cd src |
| 130 | + TAG="${{ needs.prepare_release.outputs.tag }}" |
| 131 | + bazel build --show_timestamps --copt=-O3 --verbose_failures \ |
| 132 | + -- //software:unix_full_system_tar_gen |
| 133 | + 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" |
| 134 | + gh release upload "$TAG" "${{ runner.temp }}/unix_full_system_${{ needs.prepare_release.outputs.tag }}_${{ matrix.platform }}.tar.gz" |
| 135 | +
|
| 136 | + publish_release: |
| 137 | + needs: [prepare_release, upload_assets] |
| 138 | + runs-on: ubuntu-latest |
| 139 | + permissions: |
| 140 | + contents: write |
| 141 | + steps: |
| 142 | + - uses: actions/checkout@v4 |
| 143 | + with: |
| 144 | + ref: ${{ github.event.inputs.target_commit || github.sha }} |
| 145 | + - name: Undraft Release |
| 146 | + env: |
| 147 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 148 | + run: gh release edit "${{ needs.prepare_release.outputs.tag }}" --draft=false |
0 commit comments