ayagmar commented on code in PR #14738:
URL: https://github.com/apache/lucene/pull/14738#discussion_r2899935507
##########
.github/workflows/backport.sh:
##########
@@ -0,0 +1,229 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+echo "📊 Fetching PR data..."
+PR_DATA=$(gh pr view "$PR_NUMBER" --json labels,milestone,title)
+PR_LABELS=$(echo "$PR_DATA" | jq -r '.labels[].name |
select(test("^backport/"; "i"))')
+PR_MILESTONE=$(echo "$PR_DATA" | jq -r '.milestone.title // ""')
+PR_TITLE=$(echo "$PR_DATA" | jq -r '.title // "Unknown title"')
+PR_MERGE_COMMIT_SHA="${PR_MERGE_COMMIT_SHA:-unknown}"
+DRY_RUN="${BACKPORT_DRY_RUN:-true}"
+
+normalize_version() {
+ local raw="$1"
+ local trimmed
+ local normalized=""
+ trimmed=$(echo "$raw" | sed -E 's/^[[:space:]]+|[[:space:]]+$//g')
+ if [[ $trimmed =~ ([0-9]+(\.[0-9]+)*) ]]; then
+ normalized="${BASH_REMATCH[1]}"
+ fi
+ echo "$normalized"
+}
+
+is_valid_sha() {
+ local sha="$1"
+ [[ "$sha" =~ ^[0-9a-f]{7,40}$ ]]
+}
+
+create_comment() {
+ if [ "$DRY_RUN" = "true" ]; then
+ echo "[dry-run] Would comment on PR #$PR_NUMBER:"
+ echo "$1"
+ return 0
+ fi
+ gh pr comment "$PR_NUMBER" --body "$1"
+}
+
+add_label() {
+ if [ "$DRY_RUN" = "true" ]; then
+ echo "[dry-run] Would add label '$1' on PR #$PR_NUMBER"
+ return 0
+ fi
+ gh pr edit "$PR_NUMBER" --add-label "$1" 2>/dev/null || true
+}
+
+publish_outputs() {
+ local has_targets="$1"
+ local targets_json="$2"
+
+ if [ -n "${GITHUB_OUTPUT:-}" ]; then
+ {
+ echo "dry_run=$DRY_RUN"
+ echo "has_targets=$has_targets"
+ echo "targets<<EOF"
+ echo "$targets_json"
+ echo "EOF"
+ } >> "$GITHUB_OUTPUT"
+ fi
+}
+
+if [ -z "$PR_LABELS" ] && [ -z "$PR_MILESTONE" ]; then
+ echo "ℹ️ No backport labels or milestone found. Nothing to do."
+ publish_outputs "false" "[]"
+ exit 0
+fi
+
+if [ "$DRY_RUN" != "true" ] && ! is_valid_sha "$PR_MERGE_COMMIT_SHA"; then
+ create_comment "❌ **Automatic backports skipped**
+
+Invalid merge commit SHA was provided by workflow context:
\`$PR_MERGE_COMMIT_SHA\`.
+
+Backports are skipped for safety."
+ add_label "backport-failed"
+ publish_outputs "false" "[]"
+ exit 0
+fi
+
+echo "🏷️ Ensuring backport labels exist..."
+if [ "$DRY_RUN" = "true" ]; then
+ echo "[dry-run] Skipping label creation"
+else
+ gh label create "backport" --description "Automated backport workflow"
--color "0366d6" 2>/dev/null || true
+ gh label create "backport-failed" --description "Backport failed" --color
"d73a49" 2>/dev/null || true
+fi
+
+echo "🌿 Caching branch information..."
+ALL_BRANCHES=$(git for-each-ref --format='%(refname:strip=3)'
refs/remotes/origin | grep -v '^HEAD$' | sort)
+declare -ra TARGET_BRANCH_TEMPLATES=(
Review Comment:
they're not, nice catch!
I trimmed the resolver to Lucene’s branch conventions only:
- `branch_<major>x`
- `branch_<major>_<minor>`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]