|
| 1 | +name: Create Release Branch |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + issue_number: |
| 7 | + description: 'Issue number for traceability' |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + dry_run: |
| 11 | + description: 'Dry run: simulate the process without making any changes' |
| 12 | + type: boolean |
| 13 | + required: false |
| 14 | + default: false |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: create-release-branch |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + |
| 25 | + validate-permissions: |
| 26 | + name: Validate permissions |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Check admin permission |
| 30 | + env: |
| 31 | + GH_TOKEN: ${{ github.token }} |
| 32 | + REPO: ${{ github.repository }} |
| 33 | + ACTOR: ${{ github.actor }} |
| 34 | + run: | |
| 35 | + permission=$(gh api "repos/${REPO}/collaborators/${ACTOR}/permission" --jq '.permission') |
| 36 | + if [ "$permission" != "admin" ]; then |
| 37 | + echo "::error::User ${ACTOR} does not have admin permission (current: ${permission})" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + echo "User ${ACTOR} has admin permission" |
| 41 | +
|
| 42 | + create-release-branch: |
| 43 | + name: Create release branch |
| 44 | + needs: validate-permissions |
| 45 | + runs-on: ubuntu-latest |
| 46 | + outputs: |
| 47 | + release_branch: ${{ steps.detect-version.outputs.release_branch }} |
| 48 | + current_major: ${{ steps.detect-version.outputs.current_major }} |
| 49 | + current_minor: ${{ steps.detect-version.outputs.current_minor }} |
| 50 | + branch_created: ${{ steps.check-branch.outputs.branch_created }} |
| 51 | + steps: |
| 52 | + - name: Checkout master |
| 53 | + uses: actions/checkout@v6 |
| 54 | + with: |
| 55 | + ref: master |
| 56 | + fetch-depth: 0 |
| 57 | + |
| 58 | + - name: Detect current version |
| 59 | + id: detect-version |
| 60 | + run: | |
| 61 | + revision=$(grep -oP '<revision>\K[^<]+' pom.xml) |
| 62 | + current_major=$(echo "$revision" | cut -d. -f1) |
| 63 | + current_minor=$(echo "$revision" | cut -d. -f2) |
| 64 | + release_branch="release-${current_major}.${current_minor}" |
| 65 | + echo "current_major=$current_major" >> "$GITHUB_OUTPUT" |
| 66 | + echo "current_minor=$current_minor" >> "$GITHUB_OUTPUT" |
| 67 | + echo "release_branch=$release_branch" >> "$GITHUB_OUTPUT" |
| 68 | + echo "Detected version: ${current_major}.${current_minor}" |
| 69 | + echo "Release branch: $release_branch" |
| 70 | +
|
| 71 | + - name: Check if release branch already exists |
| 72 | + id: check-branch |
| 73 | + env: |
| 74 | + RELEASE_BRANCH: ${{ steps.detect-version.outputs.release_branch }} |
| 75 | + run: | |
| 76 | + if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" > /dev/null 2>&1; then |
| 77 | + echo "::warning::Branch ${RELEASE_BRANCH} already exists on remote. Skipping." |
| 78 | + echo "branch_created=false" >> "$GITHUB_OUTPUT" |
| 79 | + else |
| 80 | + echo "Branch ${RELEASE_BRANCH} does not exist. Proceeding." |
| 81 | + echo "branch_created=true" >> "$GITHUB_OUTPUT" |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Create and push release branch |
| 85 | + if: inputs.dry_run != true && steps.check-branch.outputs.branch_created == 'true' |
| 86 | + env: |
| 87 | + RELEASE_BRANCH: ${{ steps.detect-version.outputs.release_branch }} |
| 88 | + run: | |
| 89 | + git checkout -b "$RELEASE_BRANCH" |
| 90 | + git push origin "$RELEASE_BRANCH" |
| 91 | + echo "Pushed branch $RELEASE_BRANCH" |
| 92 | +
|
| 93 | + - name: Dry run — skip push |
| 94 | + if: inputs.dry_run == true && steps.check-branch.outputs.branch_created == 'true' |
| 95 | + env: |
| 96 | + RELEASE_BRANCH: ${{ steps.detect-version.outputs.release_branch }} |
| 97 | + run: echo "Dry run — would create branch $RELEASE_BRANCH" |
| 98 | + |
| 99 | + create-version-bump-pr: |
| 100 | + name: Create version bump PR |
| 101 | + needs: create-release-branch |
| 102 | + runs-on: ubuntu-latest |
| 103 | + if: inputs.dry_run != true && needs.create-release-branch.outputs.branch_created == 'true' |
| 104 | + outputs: |
| 105 | + pr_url: ${{ steps.create-pr.outputs.pr_url }} |
| 106 | + steps: |
| 107 | + - name: Get GitHub App token |
| 108 | + id: app-token |
| 109 | + uses: actions/create-github-app-token@v2 |
| 110 | + with: |
| 111 | + app-id: ${{ vars.APP_REPO_WRITER_ID }} |
| 112 | + private-key: ${{ secrets.APP_REPO_WRITER_PRIVATE_KEY }} |
| 113 | + |
| 114 | + - name: Checkout master |
| 115 | + uses: actions/checkout@v6 |
| 116 | + with: |
| 117 | + ref: master |
| 118 | + token: ${{ steps.app-token.outputs.token }} |
| 119 | + |
| 120 | + - name: Calculate next version |
| 121 | + id: next-version |
| 122 | + env: |
| 123 | + CURRENT_MAJOR: ${{ needs.create-release-branch.outputs.current_major }} |
| 124 | + CURRENT_MINOR: ${{ needs.create-release-branch.outputs.current_minor }} |
| 125 | + run: | |
| 126 | + next_minor=$((CURRENT_MINOR + 1)) |
| 127 | + echo "next_minor=$next_minor" >> "$GITHUB_OUTPUT" |
| 128 | + echo "Next version: ${CURRENT_MAJOR}.${next_minor}" |
| 129 | +
|
| 130 | + - name: Create bump branch and update version |
| 131 | + env: |
| 132 | + CURRENT_MAJOR: ${{ needs.create-release-branch.outputs.current_major }} |
| 133 | + NEXT_MINOR: ${{ steps.next-version.outputs.next_minor }} |
| 134 | + run: | |
| 135 | + bump_branch="chore/bump-version-${CURRENT_MAJOR}.${NEXT_MINOR}" |
| 136 | + git checkout -b "$bump_branch" |
| 137 | + sed -i "s|<revision>${CURRENT_MAJOR}\.[0-9]\+</revision>|<revision>${CURRENT_MAJOR}.${NEXT_MINOR}</revision>|" pom.xml |
| 138 | + echo "Updated pom.xml:" |
| 139 | + grep '<revision>' pom.xml |
| 140 | + git config user.name "${{ github.actor }}" |
| 141 | + git config user.email "${{ github.actor }}@users.noreply.github.com" |
| 142 | + git add pom.xml |
| 143 | + git commit -m "Bump version for next release ${CURRENT_MAJOR}.${NEXT_MINOR}" |
| 144 | + git push origin "$bump_branch" |
| 145 | +
|
| 146 | + - name: Create PR |
| 147 | + id: create-pr |
| 148 | + env: |
| 149 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 150 | + CURRENT_MAJOR: ${{ needs.create-release-branch.outputs.current_major }} |
| 151 | + CURRENT_MINOR: ${{ needs.create-release-branch.outputs.current_minor }} |
| 152 | + NEXT_MINOR: ${{ steps.next-version.outputs.next_minor }} |
| 153 | + ISSUE_NUMBER: ${{ inputs.issue_number }} |
| 154 | + run: | |
| 155 | + body="Bump \`revision\` to \`${CURRENT_MAJOR}.${NEXT_MINOR}\` following the creation of \`release-${CURRENT_MAJOR}.${CURRENT_MINOR}\`." |
| 156 | + body="${body}"$'\n\n'"Issue: ${ISSUE_NUMBER}" |
| 157 | + pr_url=$(gh pr create \ |
| 158 | + --head "chore/bump-version-${CURRENT_MAJOR}.${NEXT_MINOR}" \ |
| 159 | + --base master \ |
| 160 | + --title "chore: bump version to ${CURRENT_MAJOR}.${NEXT_MINOR}" \ |
| 161 | + --body "$body") |
| 162 | + echo "pr_url=$pr_url" >> "$GITHUB_OUTPUT" |
| 163 | + echo "Created PR: $pr_url" |
| 164 | +
|
| 165 | + summary: |
| 166 | + name: Summary |
| 167 | + needs: [create-release-branch, create-version-bump-pr] |
| 168 | + runs-on: ubuntu-latest |
| 169 | + if: always() |
| 170 | + steps: |
| 171 | + - name: Write summary |
| 172 | + env: |
| 173 | + DRY_RUN: ${{ inputs.dry_run }} |
| 174 | + RELEASE_BRANCH: ${{ needs.create-release-branch.outputs.release_branch }} |
| 175 | + PR_URL: ${{ needs.create-version-bump-pr.outputs.pr_url }} |
| 176 | + CURRENT_MAJOR: ${{ needs.create-release-branch.outputs.current_major }} |
| 177 | + CURRENT_MINOR: ${{ needs.create-release-branch.outputs.current_minor }} |
| 178 | + run: | |
| 179 | + echo "## Release Branch Creation — JavaClasses" >> "$GITHUB_STEP_SUMMARY" |
| 180 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 181 | + if [ "$DRY_RUN" == "true" ]; then |
| 182 | + echo "### Dry run — no changes were made" >> "$GITHUB_STEP_SUMMARY" |
| 183 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 184 | + echo "- Detected version: **${CURRENT_MAJOR}.${CURRENT_MINOR}**" >> "$GITHUB_STEP_SUMMARY" |
| 185 | + echo "- Would create branch: \`${RELEASE_BRANCH}\`" >> "$GITHUB_STEP_SUMMARY" |
| 186 | + else |
| 187 | + echo "- Release branch: \`${RELEASE_BRANCH}\`" >> "$GITHUB_STEP_SUMMARY" |
| 188 | + [ -n "$PR_URL" ] && echo "- Version bump PR: $PR_URL" >> "$GITHUB_STEP_SUMMARY" |
| 189 | + fi |
0 commit comments