Skip to content

Commit 34eea7b

Browse files
authored
Check github labels for breaking changes (#909)
build: check github labels for breaking changes
1 parent 6971fff commit 34eea7b

File tree

2 files changed

+58
-12
lines changed

2 files changed

+58
-12
lines changed

.github/release.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
changelog:
1919
categories:
20+
- title: Breaking Changes
21+
labels: [release-breaking]
2022
- title: New Features
2123
labels: [release-features]
22-
- title: Improvments
23-
labels: [release-improvments]
24+
- title: Improvements
25+
labels: [release-improvements]
2426
- title: Bug fixes
2527
labels: [release-bugfix]

.github/workflows/periodic_release.yaml

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,37 @@ permissions:
2424
actions: write
2525

2626
jobs:
27-
create-release-branch:
28-
environment:
29-
name: release
27+
validate-ref:
3028
runs-on: ubuntu-latest
29+
steps:
30+
- name: Check ref
31+
run: |
32+
if [[ "${{ github.ref_type }}" != "branch" ]]; then
33+
echo "::error::This workflow must be run on a Branch, not a Tag."
34+
exit 1
35+
fi
36+
37+
if [[ "${{ github.ref_name }}" != "main" ]]; then
38+
echo "::error::This workflow must be run on a main branch."
39+
exit 1
40+
fi
41+
42+
compute-release-branch:
43+
needs: [validate-ref]
44+
runs-on: ubuntu-latest
45+
outputs:
46+
skip_push: ${{ steps.compute_branch_name.outputs.skip_push }}
47+
new_branch_name: ${{ steps.compute_branch_name.outputs.new_branch_name }}
3148
steps:
3249
- name: Checkout repository
3350
uses: actions/checkout@v4
3451
with:
3552
fetch-depth: 0
3653
fetch-tags: true
37-
- name: Compute Next Version and Push Branch
54+
- name: Compute Next Version
3855
id: compute_branch_name
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3958
run: |
4059
LATEST_BRANCH=$(git branch -r | grep -oE 'origin/release-[0-9]+\.[0-9]+' | sort -V | tail -n 1)
4160
@@ -53,17 +72,26 @@ jobs:
5372
if [ "$COMMIT_COUNT" -eq 0 ]; then
5473
echo "No new changes detected compared to $LATEST_BRANCH."
5574
echo "Skipping release branch creation."
56-
echo "skipped=true" >> $GITHUB_OUTPUT
75+
echo "skip_push=true" >> $GITHUB_OUTPUT
5776
exit 0
5877
fi
5978
6079
VERSION_STR=$(echo "$LATEST_BRANCH" | sed 's/origin\/release-//')
6180
CURRENT_MAJOR=$(echo "$VERSION_STR" | cut -d. -f1)
6281
CURRENT_MINOR=$(echo "$VERSION_STR" | cut -d. -f2)
6382
64-
echo "Scanning commits between $LATEST_BRANCH and HEAD for 'BREAKING' keyword..."
83+
echo "Retrieving pull request labels between $LATEST_BRANCH and HEAD..."
84+
LABELS=$(git log $LATEST_BRANCH..HEAD --pretty=format:"%s" \
85+
| grep -oE "#[0-9]+" \
86+
| tr -d "#" \
87+
| xargs -I {} gh pr view {} --json labels --jq '.labels[].name' \
88+
| sort \
89+
| uniq)
90+
91+
echo "Pull request labels:"
92+
echo "$LABELS"
6593
66-
if git log "$LATEST_BRANCH"..HEAD --pretty=format:"%s" | grep -q "BREAKING"; then
94+
if echo "$LABELS" | grep -q "release-breaking"; then
6795
NEW_MAJOR=$((CURRENT_MAJOR + 1))
6896
NEW_MINOR=0
6997
echo "BREAKING detected. Bumping Major version."
@@ -76,14 +104,30 @@ jobs:
76104
NEW_BRANCH_NAME="release-$NEW_MAJOR.$NEW_MINOR"
77105
echo "New release branch calculated: $NEW_BRANCH_NAME"
78106
echo "new_branch_name=$NEW_BRANCH_NAME" >> $GITHUB_OUTPUT
79-
echo "skipped=false" >> $GITHUB_OUTPUT
107+
echo "skip_push=false" >> $GITHUB_OUTPUT
80108
109+
create-release-branch:
110+
needs: [compute-release-branch]
111+
environment:
112+
name: release
113+
runs-on: ubuntu-latest
114+
steps:
115+
- name: Checkout repository
116+
if: needs.compute-release-branch.outputs.skip_push != 'true'
117+
uses: actions/checkout@v4
118+
with:
119+
fetch-depth: 0
120+
fetch-tags: true
121+
- name: Push the branch
122+
if: needs.compute-release-branch.outputs.skip_push != 'true'
123+
run: |
124+
NEW_BRANCH_NAME="${{needs.compute-release-branch.outputs.new_branch_name}}"
81125
git checkout -b "$NEW_BRANCH_NAME"
82126
git push origin "$NEW_BRANCH_NAME"
83127
84128
echo "Successfully pushed $NEW_BRANCH_NAME"
85129
- name: Run release branch versioning
86-
if: steps.compute_branch_name.outputs.skipped != 'true'
130+
if: needs.compute-release-branch.outputs.skip_push != 'true'
87131
env:
88132
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89-
run: gh workflow run release_branch_versioning.yaml --ref ${{ steps.compute_branch_name.outputs.new_branch_name }}
133+
run: gh workflow run release_branch_versioning.yaml --ref ${{needs.compute-release-branch.outputs.new_branch_name}}

0 commit comments

Comments
 (0)