-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to enforce labels on PRs
- Loading branch information
1 parent
e2f9cfd
commit 1d8a266
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Check PR Labels | ||
|
||
on: | ||
pull_request: | ||
types: [opened, labeled, unlabeled, synchronize] | ||
|
||
jobs: | ||
check-label: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
cache: 'pip' | ||
|
||
- name: Install yq | ||
run: | | ||
pip install yq | ||
- name: Get required labels from release.yml | ||
id: get-required-labels | ||
run: | | ||
labels=$(yq e '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml | tr '\n' ' ') | ||
echo "required_labels=$labels" >> $GITHUB_OUTPUT | ||
- name: Get PR labels | ||
id: get-pr-labels | ||
run: | | ||
labels=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") | ||
echo "labels=$labels" >> $GITHUB_OUTPUT | ||
- name: Check for specific labels | ||
id: check-label | ||
run: | | ||
required_labels=(${{ steps.get-required-labels.outputs.required_labels }}) | ||
found=false | ||
for label in "${required_labels[@]}"; do | ||
if echo "${{ steps.get-pr-labels.outputs.labels }}" | grep -q "$label"; then | ||
found=true | ||
break | ||
fi | ||
done | ||
echo "label_exists=$found" >> $GITHUB_OUTPUT | ||
- name: Fail if no required labels are found | ||
if: steps.check-label.outputs.label_exists == 'false' | ||
run: | | ||
echo "None of the required labels are applied to the PR." | ||
exit 1 |