|
| 1 | +name: Tag Hotfix |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [closed] |
| 5 | + branches: [master] |
| 6 | + |
| 7 | +jobs: |
| 8 | + tag-hotfix: |
| 9 | + # Only run if PR was merged and branch name starts with hotfix/v |
| 10 | + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'hotfix/v') |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + ref: master |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Configure Git |
| 22 | + run: | |
| 23 | + git config user.name "github-actions[bot]" |
| 24 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 25 | +
|
| 26 | + - name: Create and push tag |
| 27 | + run: | |
| 28 | + # Extract version from branch name (hotfix/vX.X.X -> vX.X.X) |
| 29 | + VERSION=$(echo "${{ github.event.pull_request.head.ref }}" | sed 's/hotfix\///') |
| 30 | + # Use PR title as tag message |
| 31 | + git tag -a "$VERSION" -m "${{ github.event.pull_request.title }}" |
| 32 | + git push origin "$VERSION" |
| 33 | + echo "Created and pushed tag: $VERSION" |
| 34 | +
|
| 35 | + - name: Cherry-pick to alpha |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ github.token }} |
| 38 | + run: | |
| 39 | + # Get the merge commit SHA |
| 40 | + MERGE_COMMIT=${{ github.event.pull_request.merge_commit_sha }} |
| 41 | + VERSION=$(echo "${{ github.event.pull_request.head.ref }}" | sed 's/hotfix\///') |
| 42 | +
|
| 43 | + # Fetch alpha branch |
| 44 | + git fetch origin alpha |
| 45 | + git checkout alpha |
| 46 | +
|
| 47 | + # Create a branch for the cherry-pick |
| 48 | + git checkout -b cherry-pick/hotfix-${VERSION}-alpha |
| 49 | +
|
| 50 | + # Cherry-pick the commits from the hotfix (excluding merge commit itself) |
| 51 | + if git cherry-pick -x $MERGE_COMMIT -m 1; then |
| 52 | + echo "Cherry-pick succeeded" |
| 53 | + else |
| 54 | + echo "Cherry-pick had conflicts. Aborting and creating PR with instructions." |
| 55 | + git cherry-pick --abort |
| 56 | + fi |
| 57 | +
|
| 58 | + # Push the cherry-pick branch |
| 59 | + git push -u origin cherry-pick/hotfix-${VERSION}-alpha |
| 60 | +
|
| 61 | + # Always create a PR (protected branches require PRs) |
| 62 | + gh pr create --base alpha --head cherry-pick/hotfix-${VERSION}-alpha \ |
| 63 | + --title "Cherry-pick: Hotfix ${VERSION} to alpha" \ |
| 64 | + --body "## Cherry-pick Hotfix ${VERSION} to alpha |
| 65 | +
|
| 66 | + This PR cherry-picks the hotfix from master to alpha. |
| 67 | +
|
| 68 | + Original PR: #${{ github.event.pull_request.number }} |
| 69 | + Merge commit: ${MERGE_COMMIT} |
| 70 | +
|
| 71 | + --- |
| 72 | + *This PR was created automatically by the hotfix-tag workflow.*" |
| 73 | +
|
| 74 | + echo "Created PR for cherry-pick to alpha" |
| 75 | +
|
| 76 | + - name: Cherry-pick to beta |
| 77 | + env: |
| 78 | + GH_TOKEN: ${{ github.token }} |
| 79 | + run: | |
| 80 | + # Get the merge commit SHA |
| 81 | + MERGE_COMMIT=${{ github.event.pull_request.merge_commit_sha }} |
| 82 | + VERSION=$(echo "${{ github.event.pull_request.head.ref }}" | sed 's/hotfix\///') |
| 83 | +
|
| 84 | + # Fetch beta branch |
| 85 | + git fetch origin beta |
| 86 | + git checkout beta |
| 87 | +
|
| 88 | + # Create a branch for the cherry-pick |
| 89 | + git checkout -b cherry-pick/hotfix-${VERSION}-beta |
| 90 | +
|
| 91 | + # Cherry-pick the commits from the hotfix |
| 92 | + if git cherry-pick -x $MERGE_COMMIT -m 1; then |
| 93 | + echo "Cherry-pick succeeded" |
| 94 | + else |
| 95 | + echo "Cherry-pick had conflicts. Aborting and creating PR with instructions." |
| 96 | + git cherry-pick --abort |
| 97 | + fi |
| 98 | +
|
| 99 | + # Push the cherry-pick branch |
| 100 | + git push -u origin cherry-pick/hotfix-${VERSION}-beta |
| 101 | +
|
| 102 | + # Always create a PR (protected branches require PRs) |
| 103 | + gh pr create --base beta --head cherry-pick/hotfix-${VERSION}-beta \ |
| 104 | + --title "Cherry-pick: Hotfix ${VERSION} to beta" \ |
| 105 | + --body "## Cherry-pick Hotfix ${VERSION} to beta |
| 106 | +
|
| 107 | + This PR cherry-picks the hotfix from master to beta. |
| 108 | +
|
| 109 | + Original PR: #${{ github.event.pull_request.number }} |
| 110 | + Merge commit: ${MERGE_COMMIT} |
| 111 | +
|
| 112 | + --- |
| 113 | + *This PR was created automatically by the hotfix-tag workflow.*" |
| 114 | +
|
| 115 | + echo "Created PR for cherry-pick to beta" |
| 116 | +
|
| 117 | + - name: Delete hotfix branch |
| 118 | + env: |
| 119 | + GH_TOKEN: ${{ github.token }} |
| 120 | + run: | |
| 121 | + BRANCH="${{ github.event.pull_request.head.ref }}" |
| 122 | + gh api -X DELETE "repos/${{ github.repository }}/git/refs/heads/${BRANCH}" || true |
| 123 | + echo "Deleted branch: $BRANCH" |
0 commit comments