Skip to content

Commit 729671c

Browse files
authored
chore: add release PR labeling and milestone fallback (#2311)
1 parent 2b9f8d1 commit 729671c

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

.github/workflows/release-pr-update.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,25 @@ jobs:
8282
set -euo pipefail
8383
git push --force-with-lease origin "$RELEASE_BRANCH"
8484
gh pr edit "$PR_NUMBER" --body-file release-review.md
85+
milestone_name="$(python - <<'PY'
86+
import os
87+
import re
88+
89+
branch = os.environ.get("RELEASE_BRANCH", "")
90+
version = branch.replace("release/v", "", 1)
91+
match = re.match(r"^(\d+)\.(\d+)", version)
92+
if not match:
93+
print("")
94+
else:
95+
print(f"{match.group(1)}.{match.group(2)}.x")
96+
PY
97+
)"
98+
if [ -n "$milestone_name" ]; then
99+
if ! gh pr edit "$PR_NUMBER" --add-label "project" --milestone "$milestone_name"; then
100+
echo "PR label/milestone update failed; continuing without changes." >&2
101+
fi
102+
else
103+
if ! gh pr edit "$PR_NUMBER" --add-label "project"; then
104+
echo "PR label update failed; continuing without changes." >&2
105+
fi
106+
fi

.github/workflows/release-pr.yml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,51 @@ jobs:
113113
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114114
RELEASE_VERSION: ${{ inputs.version }}
115115
run: |
116+
set -euo pipefail
116117
head_branch="release/v${RELEASE_VERSION}"
118+
milestone_name="$(python - <<'PY'
119+
import os
120+
import re
121+
122+
version = os.environ.get("RELEASE_VERSION", "")
123+
match = re.match(r"^(\d+)\.(\d+)", version)
124+
if not match:
125+
print("")
126+
else:
127+
print(f"{match.group(1)}.{match.group(2)}.x")
128+
PY
129+
)"
117130
pr_number="$(gh pr list --head "$head_branch" --base "main" --json number --jq '.[0].number // empty')"
118131
if [ -z "$pr_number" ]; then
119-
gh pr create \
120-
--title "Release ${RELEASE_VERSION}" \
121-
--body-file pr-body.md \
122-
--base "main" \
132+
create_args=(
133+
--title "Release ${RELEASE_VERSION}"
134+
--body-file pr-body.md
135+
--base "main"
123136
--head "$head_branch"
137+
--label "project"
138+
)
139+
if [ -n "$milestone_name" ]; then
140+
create_args+=(--milestone "$milestone_name")
141+
fi
142+
if ! gh pr create "${create_args[@]}"; then
143+
echo "PR create with label/milestone failed; retrying without them." >&2
144+
gh pr create \
145+
--title "Release ${RELEASE_VERSION}" \
146+
--body-file pr-body.md \
147+
--base "main" \
148+
--head "$head_branch"
149+
fi
124150
else
125-
gh pr edit "$pr_number" --title "Release ${RELEASE_VERSION}" --body-file pr-body.md
151+
edit_args=(
152+
--title "Release ${RELEASE_VERSION}"
153+
--body-file pr-body.md
154+
--add-label "project"
155+
)
156+
if [ -n "$milestone_name" ]; then
157+
edit_args+=(--milestone "$milestone_name")
158+
fi
159+
if ! gh pr edit "$pr_number" "${edit_args[@]}"; then
160+
echo "PR edit with label/milestone failed; retrying without them." >&2
161+
gh pr edit "$pr_number" --title "Release ${RELEASE_VERSION}" --body-file pr-body.md
162+
fi
126163
fi

0 commit comments

Comments
 (0)