|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: 'Release tag (e.g., v0.0.0)' |
| 8 | + required: true |
| 9 | + default: 'v0.0.0' |
| 10 | + type: string |
| 11 | + confirm: |
| 12 | + description: 'Type "CONFIRM" to proceed with the release' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + pull-requests: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + validate: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Validate confirmation |
| 25 | + if: ${{ github.event.inputs.confirm != 'CONFIRM' }} |
| 26 | + run: | |
| 27 | + echo "::error::You must type 'CONFIRM' to proceed with the release" |
| 28 | + exit 1 |
| 29 | +
|
| 30 | + - name: Validate tag format |
| 31 | + run: | |
| 32 | + TAG="${{ github.event.inputs.tag }}" |
| 33 | + if [[ ! $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then |
| 34 | + echo "::error::Tag must be in format vX.Y.Z or vX.Y.Z-suffix (e.g., v1.0.0 or v1.0.0-rc1)" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | +
|
| 38 | + release: |
| 39 | + needs: validate |
| 40 | + runs-on: ubuntu-latest |
| 41 | + outputs: |
| 42 | + pr-number: ${{ steps.create-pr.outputs.pr-number }} |
| 43 | + pr-url: ${{ steps.create-pr.outputs.pr-url }} |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Configure Git |
| 53 | + run: | |
| 54 | + git config user.name "github-actions[bot]" |
| 55 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 56 | +
|
| 57 | + - name: Switch to next branch |
| 58 | + run: | |
| 59 | + git checkout next |
| 60 | + git pull origin next |
| 61 | +
|
| 62 | + - name: Rebase next with main |
| 63 | + id: rebase |
| 64 | + run: | |
| 65 | + echo "Attempting to rebase next with main..." |
| 66 | + if git rebase origin/main; then |
| 67 | + echo "β
Rebase successful" |
| 68 | + echo "rebase-success=true" >> $GITHUB_OUTPUT |
| 69 | + else |
| 70 | + echo "::error::β Rebase failed due to conflicts. Please resolve conflicts manually and try again." |
| 71 | + echo "Conflicts detected in the following files:" |
| 72 | + git status --porcelain | grep "^UU\|^AA\|^DD" || true |
| 73 | + echo "rebase-success=false" >> $GITHUB_OUTPUT |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | +
|
| 77 | + - name: Check if tag already exists |
| 78 | + run: | |
| 79 | + TAG="${{ github.event.inputs.tag }}" |
| 80 | + if git tag -l | grep -q "^${TAG}$"; then |
| 81 | + echo "::error::Tag ${TAG} already exists" |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + if git ls-remote --tags origin | grep -q "refs/tags/${TAG}$"; then |
| 85 | + echo "::error::Tag ${TAG} already exists on remote" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | +
|
| 89 | + - name: Tag the release |
| 90 | + run: | |
| 91 | + TAG="${{ github.event.inputs.tag }}" |
| 92 | + git tag -a "${TAG}" -m "Release ${TAG}" |
| 93 | + echo "β
Created tag ${TAG}" |
| 94 | +
|
| 95 | + - name: Create Pull Request |
| 96 | + id: create-pr |
| 97 | + run: | |
| 98 | + TAG="${{ github.event.inputs.tag }}" |
| 99 | + |
| 100 | + # Create PR from next to main |
| 101 | + PR_RESPONSE=$(gh pr create \ |
| 102 | + --base main \ |
| 103 | + --head next \ |
| 104 | + --title "Release ${TAG}" \ |
| 105 | + --body "This PR contains the changes for release ${TAG}. |
| 106 | +
|
| 107 | + **Release checklist:** |
| 108 | + - [ ] Review the changes |
| 109 | + - [ ] Ensure all tests pass |
| 110 | + - [ ] Verify the release notes in the draft release |
| 111 | + - [ ] Merge this PR after the release is published |
| 112 | + |
| 113 | + Created by the automated release workflow." \ |
| 114 | + --json number,url) |
| 115 | + |
| 116 | + PR_NUMBER=$(echo "$PR_RESPONSE" | jq -r '.number') |
| 117 | + PR_URL=$(echo "$PR_RESPONSE" | jq -r '.url') |
| 118 | + |
| 119 | + echo "pr-number=${PR_NUMBER}" >> $GITHUB_OUTPUT |
| 120 | + echo "pr-url=${PR_URL}" >> $GITHUB_OUTPUT |
| 121 | + echo "β
Created PR #${PR_NUMBER}: ${PR_URL}" |
| 122 | + env: |
| 123 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 124 | + |
| 125 | + - name: Push tag |
| 126 | + run: | |
| 127 | + TAG="${{ github.event.inputs.tag }}" |
| 128 | + git push origin "${TAG}" |
| 129 | + echo "β
Pushed tag ${TAG}" |
| 130 | +
|
| 131 | + - name: Wait for release to be created |
| 132 | + run: | |
| 133 | + TAG="${{ github.event.inputs.tag }}" |
| 134 | + echo "Waiting for GitHub to create the draft release..." |
| 135 | + |
| 136 | + # Wait up to 2 minutes for the release to appear |
| 137 | + for i in {1..24}; do |
| 138 | + if gh release view "${TAG}" >/dev/null 2>&1; then |
| 139 | + echo "β
Draft release created" |
| 140 | + break |
| 141 | + fi |
| 142 | + echo "Waiting for release to be created... (${i}/24)" |
| 143 | + sleep 5 |
| 144 | + done |
| 145 | + env: |
| 146 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 147 | + |
| 148 | + summary: |
| 149 | + needs: [validate, release] |
| 150 | + runs-on: ubuntu-latest |
| 151 | + if: always() && needs.release.result == 'success' |
| 152 | + |
| 153 | + steps: |
| 154 | + - name: Release Summary |
| 155 | + run: | |
| 156 | + TAG="${{ github.event.inputs.tag }}" |
| 157 | + PR_URL="${{ needs.release.outputs.pr-url }}" |
| 158 | + |
| 159 | + echo "## π Release $TAG has been initiated!" |
| 160 | + echo "" |
| 161 | + echo "### Next steps:" |
| 162 | + echo "1. π Check https://github.com/${{ github.repository }}/releases for the draft release to show up" |
| 163 | + echo "2. βοΈ Edit the new release, delete the existing notes and click the auto-generate button GitHub provides" |
| 164 | + echo "3. β¨ Add a section at the top calling out the main features" |
| 165 | + echo "4. π Publish the release" |
| 166 | + echo "5. π Merge the pull request into main: ${PR_URL}" |
| 167 | + echo "6. Post message in #gh-mcp-releases channel in Slack and then share to the other mcp channels" |
| 168 | + echo "" |
| 169 | + echo "### Resources:" |
| 170 | + echo "- π¦ Draft Release: https://github.com/${{ github.repository }}/releases/tag/$TAG" |
| 171 | + echo "- π Pull Request: ${PR_URL}" |
| 172 | + echo "" |
| 173 | + echo "The release process is now ready for your review and completion!" |
| 174 | + |
| 175 | + # Also output as job summary |
| 176 | + cat << EOF >> $GITHUB_STEP_SUMMARY |
| 177 | + ## π Release $TAG has been initiated! |
| 178 | + |
| 179 | + ### Next steps: |
| 180 | + 1. π Check [releases page](https://github.com/${{ github.repository }}/releases) for the draft release to show up |
| 181 | + 2. βοΈ Edit the new release, delete the existing notes and click the auto-generate button GitHub provides |
| 182 | + 3. β¨ Add a section at the top calling out the main features |
| 183 | + 4. π Publish the release |
| 184 | + 5. π Merge the pull request into main: [PR #${{ needs.release.outputs.pr-number }}](${PR_URL}) |
| 185 | + |
| 186 | + ### Resources: |
| 187 | + - π¦ [Draft Release](https://github.com/${{ github.repository }}/releases/tag/$TAG) |
| 188 | + - π [Pull Request](${PR_URL}) |
| 189 | + |
| 190 | + The release process is now ready for your review and completion! |
| 191 | + EOF |
0 commit comments