From e6395776857b4419b24e92fa085eeff97e78b299 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 13 Nov 2025 10:50:28 -0800 Subject: [PATCH] ci: add backport labels automatically when a new minor version is released (#6615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .github/workflows/release-branch-create.yaml | 72 +++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-branch-create.yaml b/.github/workflows/release-branch-create.yaml index 434100ff3..88d7d53bc 100644 --- a/.github/workflows/release-branch-create.yaml +++ b/.github/workflows/release-branch-create.yaml @@ -153,8 +153,78 @@ jobs: echo "EOF" } >> $GITHUB_OUTPUT - - name: Post summary + - name: Ensure release labels if: steps.check_version.outputs.is_minor_bump == 'true' + env: + GH_TOKEN: ${{ secrets.PR_GH_TOKEN || secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + + BRANCH_BASE="${{ steps.check_version.outputs.branch_base }}" + + if [[ -z "$BRANCH_BASE" ]]; then + echo "::error::Branch base not set; unable to manage labels" + exit 1 + fi + + declare -A COLORS=( + [core]="4361ee" + [cloud]="4f6ef5" + ) + + for PREFIX in core cloud; do + LABEL="${PREFIX}/${BRANCH_BASE}" + COLOR="${COLORS[$PREFIX]}" + DESCRIPTION="Backport PRs for ${PREFIX} ${BRANCH_BASE}" + + if gh label view "$LABEL" >/dev/null 2>&1; then + gh label edit "$LABEL" \ + --color "$COLOR" \ + --description "$DESCRIPTION" + echo "🔄 Updated label $LABEL" + else + gh label create "$LABEL" \ + --color "$COLOR" \ + --description "$DESCRIPTION" + echo "✨ Created label $LABEL" + fi + done + + MIN_LABELS_TO_KEEP=3 + MAX_LABELS_TO_FETCH=200 + + for PREFIX in core cloud; do + mapfile -t LABELS < <( + gh label list \ + --json name \ + --limit "$MAX_LABELS_TO_FETCH" \ + --jq '.[].name' | + grep -E "^${PREFIX}/[0-9]+\.[0-9]+$" | + sort -t/ -k2,2V + ) + + TOTAL=${#LABELS[@]} + + if (( TOTAL <= MIN_LABELS_TO_KEEP )); then + echo "ℹ️ Nothing to prune for $PREFIX labels" + continue + fi + + REMOVE_COUNT=$((TOTAL - MIN_LABELS_TO_KEEP)) + + if (( REMOVE_COUNT > 1 )); then + REMOVE_COUNT=1 + fi + + for ((i=0; i