Skip to content

Commit db70ba2

Browse files
authored
Merge pull request #227 from rtk-ai/develop
Next Release
2 parents 92bd851 + efe1816 commit db70ba2

2 files changed

Lines changed: 191 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,60 @@ jobs:
148148
git config user.email "github-actions[bot]@users.noreply.github.com"
149149
git tag -fa latest -m "Latest stable release (${{ needs.release-please.outputs.tag_name }})"
150150
git push origin latest --force
151+
152+
# ═══════════════════════════════════════════════
153+
# POST-RELEASE: back-merge release commits to develop
154+
# ═══════════════════════════════════════════════
155+
#
156+
# release-please commits (version bumps + CHANGELOG) land only on main, so
157+
# develop falls one commit behind on every release. Without this job the
158+
# drift accumulates and the next develop -> main PR carries no-op churn.
159+
back-merge-develop:
160+
name: Back-merge main into develop
161+
needs: [release-please, build-release]
162+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
163+
runs-on: ubuntu-latest
164+
permissions:
165+
contents: write
166+
pull-requests: write
167+
steps:
168+
# The default workflow token cannot open PRs in this org; mint a
169+
# short-lived token from the configured GitHub App instead.
170+
- uses: actions/create-github-app-token@v3
171+
id: app-token
172+
with:
173+
app-id: ${{ secrets.APP_CLIENT_ID }}
174+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
175+
176+
- uses: actions/checkout@v4
177+
with:
178+
fetch-depth: 0
179+
ref: develop
180+
token: ${{ steps.app-token.outputs.token }}
181+
182+
- name: Open back-merge PR
183+
env:
184+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
185+
TAG: ${{ needs.release-please.outputs.tag_name }}
186+
run: |
187+
git config user.name "github-actions[bot]"
188+
git config user.email "github-actions[bot]@users.noreply.github.com"
189+
190+
BRANCH="chore/back-merge-main-${TAG}"
191+
git checkout -b "$BRANCH"
192+
193+
# Fast-forward when possible (release-please commits are linear on
194+
# top of develop); fall back to a merge commit if develop diverged.
195+
if ! git merge origin/main --ff-only 2>/dev/null; then
196+
git merge origin/main --no-edit \
197+
-m "chore: back-merge main into develop (${TAG})"
198+
fi
199+
200+
git push origin "$BRANCH"
201+
202+
gh pr create \
203+
--base develop \
204+
--head "$BRANCH" \
205+
--title "chore: sync release ${TAG} into develop" \
206+
--body "Automated back-merge of release-please commits from \`main\` into \`develop\` so the next \`develop -> main\` PR stays free of release-commit drift." \
207+
--label "automated"

.github/workflows/next-release.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Update Next Release PR
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [develop]
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
12+
jobs:
13+
update-next-release:
14+
if: github.event.pull_request.merged == true
15+
runs-on: ubuntu-latest
16+
steps:
17+
# The default workflow token cannot open PRs in this org; mint a
18+
# short-lived token from the configured GitHub App instead.
19+
- uses: actions/create-github-app-token@v3
20+
id: app-token
21+
with:
22+
app-id: ${{ secrets.APP_CLIENT_ID }}
23+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
24+
25+
- name: Update Next Release PR
26+
env:
27+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
28+
PR_NUMBER: ${{ github.event.pull_request.number }}
29+
PR_TITLE: ${{ github.event.pull_request.title }}
30+
PR_URL: ${{ github.event.pull_request.html_url }}
31+
PR_BODY: ${{ github.event.pull_request.body }}
32+
REPO: ${{ github.repository }}
33+
ALLOWED_REPOS: "rtk-ai/icm"
34+
run: |
35+
set -euo pipefail
36+
37+
URL_PATTERN=""
38+
for repo in $ALLOWED_REPOS; do
39+
URL_PATTERN="${URL_PATTERN}|https://github\\.com/${repo}/issues/[0-9]+"
40+
done
41+
URL_PATTERN="${URL_PATTERN#|}"
42+
43+
if printf '%s' "$PR_TITLE" | grep -qiE '^feat'; then
44+
SECTION="Feats"
45+
elif printf '%s' "$PR_TITLE" | grep -qiE '^fix'; then
46+
SECTION="Fix"
47+
else
48+
SECTION="Other"
49+
fi
50+
51+
ISSUE_REFS=""
52+
if [ -n "$PR_BODY" ]; then
53+
ISSUE_REFS=$(echo "$PR_BODY" \
54+
| grep -oiE "(closes|fixes|resolves):?\s+#[0-9]+|${URL_PATTERN}" \
55+
| grep -oE '#[0-9]+|issues/[0-9]+' \
56+
| sed 's|issues/|#|' \
57+
| sort -u \
58+
|| true)
59+
fi
60+
61+
ENTRY="- ${PR_TITLE} [#${PR_NUMBER}](${PR_URL})"
62+
if [ -n "$ISSUE_REFS" ]; then
63+
CLOSES_PARTS=""
64+
while IFS= read -r ref; do
65+
[ -z "$ref" ] && continue
66+
NUM="${ref#\#}"
67+
ISSUE_URL="https://github.com/${REPO}/issues/${NUM}"
68+
if [ -n "$CLOSES_PARTS" ]; then
69+
CLOSES_PARTS="${CLOSES_PARTS}, [${ref}](${ISSUE_URL}) (to verify)"
70+
else
71+
CLOSES_PARTS="Closes [${ref}](${ISSUE_URL}) (to verify)"
72+
fi
73+
done <<< "$ISSUE_REFS"
74+
ENTRY="${ENTRY} — ${CLOSES_PARTS}"
75+
fi
76+
77+
NEXT_PR=$(gh pr list \
78+
--repo "$REPO" \
79+
--label next-release \
80+
--base main \
81+
--head develop \
82+
--state open \
83+
--json number,body \
84+
--jq '.[0] // empty')
85+
86+
NEXT_PR_NUMBER=""
87+
if [ -n "$NEXT_PR" ]; then
88+
NEXT_PR_NUMBER=$(echo "$NEXT_PR" | jq -r '.number')
89+
fi
90+
91+
if [ -z "$NEXT_PR_NUMBER" ]; then
92+
TEMPLATE="### Feats
93+
94+
### Fix
95+
96+
### Other"
97+
98+
PR_CREATE_URL=$(gh pr create \
99+
--repo "$REPO" \
100+
--base main \
101+
--head develop \
102+
--title "Next Release" \
103+
--label next-release \
104+
--body "$TEMPLATE")
105+
106+
NEXT_PR_NUMBER=$(echo "$PR_CREATE_URL" | grep -oE '/pull/[0-9]+' | grep -oE '[0-9]+')
107+
CURRENT_BODY="$TEMPLATE"
108+
else
109+
CURRENT_BODY=$(echo "$NEXT_PR" | jq -r '.body')
110+
fi
111+
112+
SECTION_HEADER="### ${SECTION}"
113+
export ENTRY
114+
if echo "$CURRENT_BODY" | grep -qF "$SECTION_HEADER"; then
115+
UPDATED_BODY=$(echo "$CURRENT_BODY" | awk -v section="$SECTION_HEADER" '
116+
$0 == section {
117+
print
118+
print ENVIRON["ENTRY"]
119+
next
120+
}
121+
{ print }
122+
')
123+
else
124+
UPDATED_BODY="${CURRENT_BODY}
125+
126+
${SECTION_HEADER}
127+
${ENTRY}"
128+
fi
129+
130+
gh pr edit "$NEXT_PR_NUMBER" \
131+
--repo "$REPO" \
132+
--body "$UPDATED_BODY"
133+
134+
echo "Updated Next Release PR #${NEXT_PR_NUMBER} — added entry to ### ${SECTION}"

0 commit comments

Comments
 (0)