|
| 1 | +# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 3 | +# of this software and associated documentation files (the "Software"), to deal |
| 4 | +# in the Software without restriction, including without limitation the rights |
| 5 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 6 | +# copies of the Software, and to permit persons to whom the Software is |
| 7 | +# furnished to do so, subject to the following conditions: |
| 8 | +# |
| 9 | +# The above copyright notice and this permission notice shall be included in all |
| 10 | +# copies or substantial portions of the Software. |
| 11 | +# |
| 12 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 18 | +# SOFTWARE. |
| 19 | + |
| 20 | +name: Promote Develop to Main |
| 21 | + |
| 22 | +on: |
| 23 | + workflow_dispatch: |
| 24 | + inputs: |
| 25 | + head_branch: |
| 26 | + description: 'Integration branch to promote' |
| 27 | + required: true |
| 28 | + default: develop |
| 29 | + type: string |
| 30 | + base_branch: |
| 31 | + description: 'Release branch that receives the promotion PR' |
| 32 | + required: true |
| 33 | + default: main |
| 34 | + type: string |
| 35 | + enable_auto_merge: |
| 36 | + description: 'Enable auto-merge for the promotion PR after checks pass' |
| 37 | + required: true |
| 38 | + default: false |
| 39 | + type: boolean |
| 40 | + |
| 41 | +permissions: |
| 42 | + contents: read |
| 43 | + pull-requests: write |
| 44 | + issues: write |
| 45 | + |
| 46 | +concurrency: |
| 47 | + group: promote-${{ inputs.head_branch }}-to-${{ inputs.base_branch }} |
| 48 | + cancel-in-progress: false |
| 49 | + |
| 50 | +jobs: |
| 51 | + open-promotion-pr: |
| 52 | + name: Open promotion PR |
| 53 | + runs-on: ubuntu-latest |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ secrets.RELEASE_AUTOMATION_TOKEN || github.token }} |
| 56 | + BASE_BRANCH: ${{ inputs.base_branch }} |
| 57 | + HEAD_BRANCH: ${{ inputs.head_branch }} |
| 58 | + steps: |
| 59 | + - name: Checkout repository |
| 60 | + uses: actions/checkout@v4 |
| 61 | + with: |
| 62 | + fetch-depth: 0 |
| 63 | + |
| 64 | + - name: Create or reuse promotion PR |
| 65 | + id: promote |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | +
|
| 69 | + git fetch --no-tags origin "${BASE_BRANCH}" "${HEAD_BRANCH}" |
| 70 | +
|
| 71 | + ahead=$(git rev-list --count "origin/${BASE_BRANCH}..origin/${HEAD_BRANCH}") |
| 72 | + behind=$(git rev-list --count "origin/${HEAD_BRANCH}..origin/${BASE_BRANCH}") |
| 73 | +
|
| 74 | + echo "ahead=${ahead}" >> "${GITHUB_OUTPUT}" |
| 75 | + echo "behind=${behind}" >> "${GITHUB_OUTPUT}" |
| 76 | +
|
| 77 | + if [[ "${ahead}" == "0" ]]; then |
| 78 | + echo "${HEAD_BRANCH} has no commits to promote into ${BASE_BRANCH}." |
| 79 | + echo "pr_url=" >> "${GITHUB_OUTPUT}" |
| 80 | + exit 0 |
| 81 | + fi |
| 82 | +
|
| 83 | + existing_pr=$( |
| 84 | + gh pr list \ |
| 85 | + --base "${BASE_BRANCH}" \ |
| 86 | + --head "${HEAD_BRANCH}" \ |
| 87 | + --state open \ |
| 88 | + --json url \ |
| 89 | + --jq '.[0].url // ""' |
| 90 | + ) |
| 91 | +
|
| 92 | + if [[ -n "${existing_pr}" ]]; then |
| 93 | + echo "Reusing existing promotion PR: ${existing_pr}" |
| 94 | + echo "pr_url=${existing_pr}" >> "${GITHUB_OUTPUT}" |
| 95 | + gh pr comment "${existing_pr}" --body \ |
| 96 | + "Promotion check refreshed: ${HEAD_BRANCH} is ${ahead} commit(s) ahead of ${BASE_BRANCH} and ${behind} commit(s) behind." |
| 97 | + exit 0 |
| 98 | + fi |
| 99 | +
|
| 100 | + body_file=$(mktemp) |
| 101 | + cat > "${body_file}" <<BODY |
| 102 | + ## Release promotion |
| 103 | +
|
| 104 | + This PR promotes \`${HEAD_BRANCH}\` into \`${BASE_BRANCH}\` for the next release. |
| 105 | +
|
| 106 | + - Commits ahead: ${ahead} |
| 107 | + - Commits behind: ${behind} |
| 108 | +
|
| 109 | + After this PR merges, release automation on \`${BASE_BRANCH}\` can prepare |
| 110 | + the release PR, tag, and GitHub Release. |
| 111 | + BODY |
| 112 | +
|
| 113 | + pr_url=$( |
| 114 | + gh pr create \ |
| 115 | + --base "${BASE_BRANCH}" \ |
| 116 | + --head "${HEAD_BRANCH}" \ |
| 117 | + --title "Release: promote ${HEAD_BRANCH} to ${BASE_BRANCH}" \ |
| 118 | + --body-file "${body_file}" |
| 119 | + ) |
| 120 | +
|
| 121 | + echo "Created promotion PR: ${pr_url}" |
| 122 | + echo "pr_url=${pr_url}" >> "${GITHUB_OUTPUT}" |
| 123 | +
|
| 124 | + - name: Enable auto-merge |
| 125 | + if: inputs.enable_auto_merge && steps.promote.outputs.pr_url != '' |
| 126 | + run: gh pr merge --auto --merge "${{ steps.promote.outputs.pr_url }}" |
| 127 | + |
| 128 | + - name: Summarize promotion |
| 129 | + run: | |
| 130 | + { |
| 131 | + echo "## Promotion summary" |
| 132 | + echo |
| 133 | + echo "- Head branch: \`${HEAD_BRANCH}\`" |
| 134 | + echo "- Base branch: \`${BASE_BRANCH}\`" |
| 135 | + echo "- Commits ahead: \`${{ steps.promote.outputs.ahead }}\`" |
| 136 | + echo "- Commits behind: \`${{ steps.promote.outputs.behind }}\`" |
| 137 | + if [[ -n "${{ steps.promote.outputs.pr_url }}" ]]; then |
| 138 | + echo "- Promotion PR: ${{ steps.promote.outputs.pr_url }}" |
| 139 | + else |
| 140 | + echo "- Promotion PR: not created because there are no commits to promote" |
| 141 | + fi |
| 142 | + } >> "${GITHUB_STEP_SUMMARY}" |
0 commit comments