Skip to content

Commit

Permalink
chore: Add label check to gha (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
k15r authored Jul 17, 2024
1 parent 62836db commit 17d29c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/pull-request-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Changes refer to particular issues, PRs or documents:

## Traceability
- [ ] The PR is linked to a GitHub issue.
- [ ] The PR has a milestone set.
- [ ] The PR has a respective `area` and `kind` label.
- [ ] The follow-up issues (if any) are linked in the `Related Issues` section.
- [ ] If the change is user-facing, the documentation has been adjusted.
- [ ] The feature is unit-tested.
Expand Down
42 changes: 41 additions & 1 deletion .github/workflows/pr-github-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,54 @@ on:
- reopened
- edited
- synchronize
- labeled
- milestoned
workflow_dispatch:

jobs:
pr-milestone-check:
runs-on: ubuntu-latest
steps:
- name: Check for milestone
env:
MILESTONE: ${{ toJSON(github.event.pull_request.milestone) }}
run: |
echo "${MILESTONE}" | jq -e '.!=null' || (echo "Milestone is not set"; exit 1)
pr-label-check:
runs-on: ubuntu-latest
steps:
- name: Check for area label
if: always()
run: |
gh api --jq '.labels.[].name' /repos/${{ github.repository }}/pulls/${{ github.event.number }} | \
grep -q '^area/' || (echo "area label missing"; exit 1)
env:
GH_TOKEN: ${{ github.token }}

- name: Check for kind label
if: always()
run: |
gh api --jq '.labels.[].name' /repos/${{ github.repository }}/pulls/${{ github.event.number }} | \
grep -q '^kind/' || (echo "kind label missing"; exit 1)
env:
GH_TOKEN: ${{ github.token }}

- name: Check if kind label matches pr title prefix
run: |
kind_label=$( gh api --jq '.labels.[].name' /repos/${{ github.repository }}/pulls/${{ github.event.number }} | grep '^kind/')
kind_label_to_pr_title_prefix='{"kind/bug":"fix","kind/feature":"feat","kind/docs":"docs","kind/chore":"chore","kind/flaky-test":"test","kind/missing-test":"test","kind/failing-test":"test","kind/deps":"deps"}'
prefix=$(echo $kind_label_to_pr_title_prefix | jq -r ".\"$kind_label\"")
echo "${{ github.event.pull_request.title }}" | grep '^'$prefix || (echo "PR title should start with $prefix"; exit 1)
env:
GH_TOKEN: ${{ github.token }}


pr-title-check:
runs-on: ubuntu-latest
steps:
- name: Validate title
uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017
uses: amannn/action-semantic-pull-request@47b15d52c5c30e94a17ec87eb8dd51ff5221fed9
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down

0 comments on commit 17d29c9

Please sign in to comment.