Skip to content

Commit e639577

Browse files
ci: add backport labels automatically when a new minor version is released (#6615)
add the `core/x.yy` and `cloud/x.yy` labels (used for backporting) automatically when a minor version is released (and the previous version is made into RC). By "add labels" I mean add them into the repo's list of available labels that can be used in the UI. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6615-ci-add-backport-labels-automatically-when-a-new-minor-version-is-released-2a36d73d365081ed8c56ef650b665078) by [Unito](https://www.unito.io)
1 parent 596add9 commit e639577

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

.github/workflows/release-branch-create.yaml

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,78 @@ jobs:
153153
echo "EOF"
154154
} >> $GITHUB_OUTPUT
155155
156-
- name: Post summary
156+
- name: Ensure release labels
157157
if: steps.check_version.outputs.is_minor_bump == 'true'
158+
env:
159+
GH_TOKEN: ${{ secrets.PR_GH_TOKEN || secrets.GITHUB_TOKEN }}
160+
run: |
161+
set -euo pipefail
162+
163+
BRANCH_BASE="${{ steps.check_version.outputs.branch_base }}"
164+
165+
if [[ -z "$BRANCH_BASE" ]]; then
166+
echo "::error::Branch base not set; unable to manage labels"
167+
exit 1
168+
fi
169+
170+
declare -A COLORS=(
171+
[core]="4361ee"
172+
[cloud]="4f6ef5"
173+
)
174+
175+
for PREFIX in core cloud; do
176+
LABEL="${PREFIX}/${BRANCH_BASE}"
177+
COLOR="${COLORS[$PREFIX]}"
178+
DESCRIPTION="Backport PRs for ${PREFIX} ${BRANCH_BASE}"
179+
180+
if gh label view "$LABEL" >/dev/null 2>&1; then
181+
gh label edit "$LABEL" \
182+
--color "$COLOR" \
183+
--description "$DESCRIPTION"
184+
echo "🔄 Updated label $LABEL"
185+
else
186+
gh label create "$LABEL" \
187+
--color "$COLOR" \
188+
--description "$DESCRIPTION"
189+
echo "✨ Created label $LABEL"
190+
fi
191+
done
192+
193+
MIN_LABELS_TO_KEEP=3
194+
MAX_LABELS_TO_FETCH=200
195+
196+
for PREFIX in core cloud; do
197+
mapfile -t LABELS < <(
198+
gh label list \
199+
--json name \
200+
--limit "$MAX_LABELS_TO_FETCH" \
201+
--jq '.[].name' |
202+
grep -E "^${PREFIX}/[0-9]+\.[0-9]+$" |
203+
sort -t/ -k2,2V
204+
)
205+
206+
TOTAL=${#LABELS[@]}
207+
208+
if (( TOTAL <= MIN_LABELS_TO_KEEP )); then
209+
echo "ℹ️ Nothing to prune for $PREFIX labels"
210+
continue
211+
fi
212+
213+
REMOVE_COUNT=$((TOTAL - MIN_LABELS_TO_KEEP))
214+
215+
if (( REMOVE_COUNT > 1 )); then
216+
REMOVE_COUNT=1
217+
fi
218+
219+
for ((i=0; i<REMOVE_COUNT; i++)); do
220+
OLD_LABEL="${LABELS[$i]}"
221+
gh label delete "$OLD_LABEL" --yes
222+
echo "🗑️ Removed old label $OLD_LABEL"
223+
done
224+
done
225+
226+
- name: Post summary
227+
if: always() && steps.check_version.outputs.is_minor_bump == 'true'
158228
run: |
159229
CURRENT_VERSION="${{ steps.check_version.outputs.current_version }}"
160230
RESULTS="${{ steps.create_branches.outputs.results }}"

0 commit comments

Comments
 (0)