Skip to content

Commit d65599b

Browse files
committed
CI: auto-label patch-level version bumps for merge
1 parent a9ff325 commit d65599b

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Auto-label patch bumps
2+
3+
on:
4+
workflow_run:
5+
workflows: ["GitHub Actions CI"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
label:
14+
if: |
15+
github.repository == 'maxim-belkin/homebrew-xorg' &&
16+
github.event.workflow_run.conclusion == 'success' &&
17+
github.event.workflow_run.event == 'pull_request'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Label patch bumps
21+
env:
22+
GH_TOKEN: ${{ secrets.BUMP_GITHUB_TOKEN }}
23+
REPO: ${{ github.repository }}
24+
PR_NUMBERS: ${{ toJson(github.event.workflow_run.pull_requests.*.number) }}
25+
run: |
26+
set -uo pipefail
27+
28+
PR_LIST=$(echo "$PR_NUMBERS" | jq -r '.[]?')
29+
if [ -z "$PR_LIST" ]; then
30+
echo "No associated PRs."
31+
exit 0
32+
fi
33+
34+
for PR_NUMBER in $PR_LIST; do
35+
echo "::group::PR #$PR_NUMBER"
36+
37+
PR_DATA=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json title,baseRefName,labels)
38+
PR_TITLE=$(echo "$PR_DATA" | jq -r .title)
39+
BASE_REF=$(echo "$PR_DATA" | jq -r .baseRefName)
40+
HAS_LABEL=$(echo "$PR_DATA" | jq -r '.labels[] | select(.name == "CI-merge") | .name')
41+
42+
if [ -n "$HAS_LABEL" ]; then
43+
echo "Already has CI-merge label."
44+
echo "::endgroup::"
45+
continue
46+
fi
47+
48+
# Match bump-formula-pr title pattern: "<name> <version>"
49+
if [[ ! "$PR_TITLE" =~ ^([a-z][a-z0-9_-]*)[[:space:]]+([0-9]+(\.[0-9]+)+)$ ]]; then
50+
echo "Title '$PR_TITLE' is not a bump-formula-pr pattern, skipping."
51+
echo "::endgroup::"
52+
continue
53+
fi
54+
55+
NEW_VERSION="${BASH_REMATCH[2]}"
56+
57+
# Find the changed Formula file
58+
FORMULA_FILE=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json files --jq '.files[].path' | grep '^Formula/' | head -1)
59+
if [ -z "$FORMULA_FILE" ]; then
60+
echo "No Formula file changed, skipping."
61+
echo "::endgroup::"
62+
continue
63+
fi
64+
65+
# Get old version from the formula on the base branch
66+
OLD_CONTENT=$(gh api "repos/$REPO/contents/$FORMULA_FILE?ref=$BASE_REF" --jq .content | base64 -d)
67+
OLD_URL=$(echo "$OLD_CONTENT" | grep -oE 'url "[^"]+"' | head -1 | sed 's/url "//; s/"$//')
68+
OLD_VERSION=$(echo "$OLD_URL" | grep -oE '[0-9]+(\.[0-9]+)+' | tail -1)
69+
70+
if [ -z "$OLD_VERSION" ]; then
71+
echo "Couldn't determine old version, skipping."
72+
echo "::endgroup::"
73+
continue
74+
fi
75+
76+
echo "Version change: $OLD_VERSION -> $NEW_VERSION"
77+
78+
# Check if it's a patch-level bump (all components except last are equal)
79+
IFS='.' read -ra OLD_PARTS <<< "$OLD_VERSION"
80+
IFS='.' read -ra NEW_PARTS <<< "$NEW_VERSION"
81+
82+
if [ "${#OLD_PARTS[@]}" -ne "${#NEW_PARTS[@]}" ]; then
83+
echo "Different number of version components - not a patch bump."
84+
echo "::endgroup::"
85+
continue
86+
fi
87+
88+
IS_PATCH=true
89+
n=$((${#OLD_PARTS[@]} - 1))
90+
for ((i=0; i<n; i++)); do
91+
if [ "${OLD_PARTS[$i]}" != "${NEW_PARTS[$i]}" ]; then
92+
IS_PATCH=false
93+
break
94+
fi
95+
done
96+
97+
if [ "$IS_PATCH" = "true" ]; then
98+
echo "Patch bump - adding CI-merge label."
99+
gh api "repos/$REPO/issues/$PR_NUMBER/labels" \
100+
--method POST -f "labels[]=CI-merge" || true
101+
else
102+
echo "Minor/major bump - leaving for manual review."
103+
fi
104+
105+
echo "::endgroup::"
106+
done

0 commit comments

Comments
 (0)