Skip to content

Commit 3300fda

Browse files
authored
Merge pull request #170 from AMDResearch/ci/release-automation
ci: add release promotion automation
2 parents 2147fcb + df0dddd commit 3300fda

3 files changed

Lines changed: 209 additions & 2 deletions

File tree

.github/workflows/pack-bundle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ jobs:
157157
BUNDLE=$(ls auplc-bundle-*.tar.gz)
158158
TAG="${{ github.event.workflow_run.head_branch }}"
159159
160-
# Upload to the existing release. Releases are created manually with
161-
# proper release notes before tagging; CI only attaches the bundle.
160+
# Upload to the release created by the release workflow. If the
161+
# release is not available yet, keep the bundle artifact for retry.
162162
if gh release view "${TAG}" &>/dev/null; then
163163
gh release upload "${TAG}" "${BUNDLE}" --clobber
164164
echo "Bundle uploaded to release ${TAG}"
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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}"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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: Release Please
21+
22+
on:
23+
push:
24+
branches: [main]
25+
workflow_dispatch:
26+
27+
permissions:
28+
contents: write
29+
issues: write
30+
pull-requests: write
31+
32+
concurrency:
33+
group: release-please-${{ github.ref }}
34+
cancel-in-progress: false
35+
36+
jobs:
37+
release-please:
38+
name: Prepare or publish release
39+
runs-on: ubuntu-latest
40+
outputs:
41+
release_created: ${{ steps.release.outputs.release_created }}
42+
tag_name: ${{ steps.release.outputs.tag_name }}
43+
version: ${{ steps.release.outputs.version }}
44+
steps:
45+
- name: Run release-please
46+
id: release
47+
uses: googleapis/release-please-action@v4
48+
with:
49+
token: ${{ secrets.RELEASE_AUTOMATION_TOKEN || github.token }}
50+
target-branch: main
51+
release-type: simple
52+
53+
- name: Summarize release-please result
54+
run: |
55+
{
56+
echo "## Release Please summary"
57+
echo
58+
echo "- Release created: \`${{ steps.release.outputs.release_created || 'false' }}\`"
59+
echo "- Tag: \`${{ steps.release.outputs.tag_name || 'not created' }}\`"
60+
echo "- Version: \`${{ steps.release.outputs.version || 'not created' }}\`"
61+
echo
62+
echo "Use a repository secret named \`RELEASE_AUTOMATION_TOKEN\` from a"
63+
echo "GitHub App or fine-grained PAT if tag or release events must"
64+
echo "trigger downstream workflows."
65+
} >> "${GITHUB_STEP_SUMMARY}"

0 commit comments

Comments
 (0)