From df0dddde8e9dd0bae342f10719a722e95e8f2ff6 Mon Sep 17 00:00:00 2001 From: ShifZhan <252984256+MioYuuIH@users.noreply.github.com> Date: Thu, 9 Jul 2026 14:42:37 +0800 Subject: [PATCH] ci: add release promotion automation --- .github/workflows/pack-bundle.yml | 4 +- .github/workflows/promote-develop-to-main.yml | 142 ++++++++++++++++++ .github/workflows/release-please.yml | 65 ++++++++ 3 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/promote-develop-to-main.yml create mode 100644 .github/workflows/release-please.yml diff --git a/.github/workflows/pack-bundle.yml b/.github/workflows/pack-bundle.yml index 2d80de1..96a2557 100644 --- a/.github/workflows/pack-bundle.yml +++ b/.github/workflows/pack-bundle.yml @@ -157,8 +157,8 @@ jobs: BUNDLE=$(ls auplc-bundle-*.tar.gz) TAG="${{ github.event.workflow_run.head_branch }}" - # Upload to the existing release. Releases are created manually with - # proper release notes before tagging; CI only attaches the bundle. + # Upload to the release created by the release workflow. If the + # release is not available yet, keep the bundle artifact for retry. if gh release view "${TAG}" &>/dev/null; then gh release upload "${TAG}" "${BUNDLE}" --clobber echo "Bundle uploaded to release ${TAG}" diff --git a/.github/workflows/promote-develop-to-main.yml b/.github/workflows/promote-develop-to-main.yml new file mode 100644 index 0000000..13bbc6d --- /dev/null +++ b/.github/workflows/promote-develop-to-main.yml @@ -0,0 +1,142 @@ +# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +name: Promote Develop to Main + +on: + workflow_dispatch: + inputs: + head_branch: + description: 'Integration branch to promote' + required: true + default: develop + type: string + base_branch: + description: 'Release branch that receives the promotion PR' + required: true + default: main + type: string + enable_auto_merge: + description: 'Enable auto-merge for the promotion PR after checks pass' + required: true + default: false + type: boolean + +permissions: + contents: read + pull-requests: write + issues: write + +concurrency: + group: promote-${{ inputs.head_branch }}-to-${{ inputs.base_branch }} + cancel-in-progress: false + +jobs: + open-promotion-pr: + name: Open promotion PR + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.RELEASE_AUTOMATION_TOKEN || github.token }} + BASE_BRANCH: ${{ inputs.base_branch }} + HEAD_BRANCH: ${{ inputs.head_branch }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Create or reuse promotion PR + id: promote + run: | + set -euo pipefail + + git fetch --no-tags origin "${BASE_BRANCH}" "${HEAD_BRANCH}" + + ahead=$(git rev-list --count "origin/${BASE_BRANCH}..origin/${HEAD_BRANCH}") + behind=$(git rev-list --count "origin/${HEAD_BRANCH}..origin/${BASE_BRANCH}") + + echo "ahead=${ahead}" >> "${GITHUB_OUTPUT}" + echo "behind=${behind}" >> "${GITHUB_OUTPUT}" + + if [[ "${ahead}" == "0" ]]; then + echo "${HEAD_BRANCH} has no commits to promote into ${BASE_BRANCH}." + echo "pr_url=" >> "${GITHUB_OUTPUT}" + exit 0 + fi + + existing_pr=$( + gh pr list \ + --base "${BASE_BRANCH}" \ + --head "${HEAD_BRANCH}" \ + --state open \ + --json url \ + --jq '.[0].url // ""' + ) + + if [[ -n "${existing_pr}" ]]; then + echo "Reusing existing promotion PR: ${existing_pr}" + echo "pr_url=${existing_pr}" >> "${GITHUB_OUTPUT}" + gh pr comment "${existing_pr}" --body \ + "Promotion check refreshed: ${HEAD_BRANCH} is ${ahead} commit(s) ahead of ${BASE_BRANCH} and ${behind} commit(s) behind." + exit 0 + fi + + body_file=$(mktemp) + cat > "${body_file}" <> "${GITHUB_OUTPUT}" + + - name: Enable auto-merge + if: inputs.enable_auto_merge && steps.promote.outputs.pr_url != '' + run: gh pr merge --auto --merge "${{ steps.promote.outputs.pr_url }}" + + - name: Summarize promotion + run: | + { + echo "## Promotion summary" + echo + echo "- Head branch: \`${HEAD_BRANCH}\`" + echo "- Base branch: \`${BASE_BRANCH}\`" + echo "- Commits ahead: \`${{ steps.promote.outputs.ahead }}\`" + echo "- Commits behind: \`${{ steps.promote.outputs.behind }}\`" + if [[ -n "${{ steps.promote.outputs.pr_url }}" ]]; then + echo "- Promotion PR: ${{ steps.promote.outputs.pr_url }}" + else + echo "- Promotion PR: not created because there are no commits to promote" + fi + } >> "${GITHUB_STEP_SUMMARY}" diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..02451ad --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,65 @@ +# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +name: Release Please + +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: write + issues: write + pull-requests: write + +concurrency: + group: release-please-${{ github.ref }} + cancel-in-progress: false + +jobs: + release-please: + name: Prepare or publish release + runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} + version: ${{ steps.release.outputs.version }} + steps: + - name: Run release-please + id: release + uses: googleapis/release-please-action@v4 + with: + token: ${{ secrets.RELEASE_AUTOMATION_TOKEN || github.token }} + target-branch: main + release-type: simple + + - name: Summarize release-please result + run: | + { + echo "## Release Please summary" + echo + echo "- Release created: \`${{ steps.release.outputs.release_created || 'false' }}\`" + echo "- Tag: \`${{ steps.release.outputs.tag_name || 'not created' }}\`" + echo "- Version: \`${{ steps.release.outputs.version || 'not created' }}\`" + echo + echo "Use a repository secret named \`RELEASE_AUTOMATION_TOKEN\` from a" + echo "GitHub App or fine-grained PAT if tag or release events must" + echo "trigger downstream workflows." + } >> "${GITHUB_STEP_SUMMARY}"