|
| 1 | +name: Cut Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: 'Version bump type' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + |
| 15 | +jobs: |
| 16 | + cut-release: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v6 |
| 25 | + |
| 26 | + - name: Compute new version |
| 27 | + id: version |
| 28 | + run: | |
| 29 | + CURRENT=$(grep '^version:' charts/repo-guard/Chart.yaml | awk '{print $2}') |
| 30 | + MAJOR=$(echo "$CURRENT" | cut -d. -f1) |
| 31 | + MINOR=$(echo "$CURRENT" | cut -d. -f2) |
| 32 | + PATCH=$(echo "$CURRENT" | cut -d. -f3) |
| 33 | + case "${{ github.event.inputs.bump }}" in |
| 34 | + major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; |
| 35 | + minor) MINOR=$((MINOR + 1)); PATCH=0 ;; |
| 36 | + patch) PATCH=$((PATCH + 1)) ;; |
| 37 | + esac |
| 38 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 39 | + echo "Current version: $CURRENT → New version: $NEW_VERSION" |
| 40 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 41 | +
|
| 42 | + - name: Update versions in Chart.yaml and Makefile |
| 43 | + run: | |
| 44 | + NEW_VERSION=${{ steps.version.outputs.new_version }} |
| 45 | + sed -i "s/^version: .*/version: $NEW_VERSION/" charts/repo-guard/Chart.yaml |
| 46 | + sed -i "s/^appVersion: .*/appVersion: \"$NEW_VERSION\"/" charts/repo-guard/Chart.yaml |
| 47 | + sed -i "s|^IMG ?= \(.*\):.*|IMG ?= \1:$NEW_VERSION|" Makefile |
| 48 | +
|
| 49 | + - name: Create and auto-merge Pull Request |
| 50 | + id: pr |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN_PR }} |
| 53 | + run: | |
| 54 | + NEW_VERSION=${{ steps.version.outputs.new_version }} |
| 55 | + BRANCH_NAME="release-$NEW_VERSION" |
| 56 | +
|
| 57 | + git config user.name "github-actions[bot]" |
| 58 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 59 | +
|
| 60 | + git checkout -b "$BRANCH_NAME" |
| 61 | + git add charts/repo-guard/Chart.yaml Makefile |
| 62 | + git commit -s -m "chore: prepare release $NEW_VERSION" |
| 63 | + git push origin "$BRANCH_NAME" |
| 64 | +
|
| 65 | + PR_URL=$(gh pr create \ |
| 66 | + --title "chore: prepare release $NEW_VERSION" \ |
| 67 | + --body "Automated version bump to $NEW_VERSION for release." \ |
| 68 | + --head "$BRANCH_NAME" \ |
| 69 | + --base main) |
| 70 | +
|
| 71 | + echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT" |
| 72 | + echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT" |
| 73 | +
|
| 74 | + gh pr merge "$PR_URL" --auto --squash |
| 75 | +
|
| 76 | + - name: Wait for PR to merge |
| 77 | + env: |
| 78 | + GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN_PR }} |
| 79 | + run: | |
| 80 | + PR_URL=${{ steps.pr.outputs.pr_url }} |
| 81 | + echo "Waiting for PR to merge: $PR_URL" |
| 82 | + for i in $(seq 1 30); do |
| 83 | + STATE=$(gh pr view "$PR_URL" --json state -q '.state') |
| 84 | + if [ "$STATE" = "MERGED" ]; then |
| 85 | + echo "PR merged." |
| 86 | + exit 0 |
| 87 | + fi |
| 88 | + echo "State: $STATE, attempt $i/30 — waiting 20s..." |
| 89 | + sleep 20 |
| 90 | + done |
| 91 | + echo "Timed out waiting for PR to merge." >&2 |
| 92 | + exit 1 |
| 93 | +
|
| 94 | + - name: Create GitHub release |
| 95 | + env: |
| 96 | + GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN_PR }} |
| 97 | + run: | |
| 98 | + NEW_VERSION=${{ steps.version.outputs.new_version }} |
| 99 | + # Fetch the latest main so the tag points at the merge commit |
| 100 | + git fetch origin main |
| 101 | + git checkout main |
| 102 | + git pull origin main |
| 103 | +
|
| 104 | + gh release create "v$NEW_VERSION" \ |
| 105 | + --title "v$NEW_VERSION" \ |
| 106 | + --generate-notes \ |
| 107 | + --target main |
0 commit comments