Skip to content

Update label-checker to only look for exactly 1 kind/* label #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions .github/workflows/PRLabelChecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for specific labels
- name: Ensure exactly one "kind/*" label is applied
run: |
# ignore dependabot PRs
if [[ ${{ github.actor }} == "dependabot[bot]" ]]; then
echo "Ignoring dependabot PRs."
exit 0
fi
# Fetch repository labels from the GitHub API
REPO_LABELS=$(gh api repos/${{ github.repository }}/labels --jq '.[].name')

# Fetch labels applied to the current PR
# Count the number of "kind/*" labels directly from the PR labels
PR_NUMBER=${{ github.event.pull_request.number }}
PR_LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels.[] | .name')
KIND_LABEL_COUNT=$(gh pr view "$PR_NUMBER" --json labels -q '.labels.[].name' | grep -c '^kind/')

# Check if any PR label matches a repository label
for PR_LABEL in $PR_LABELS; do
if echo "$REPO_LABELS" | grep -qw "$PR_LABEL"; then
echo "Label '$PR_LABEL' matches a repository label."
exit 0
fi
done

echo "None of the PR labels match repository labels."
exit 1
if [[ "$KIND_LABEL_COUNT" -eq 1 ]]; then
echo "✅ Exactly one 'kind/*' label is applied."
exit 0
else
echo "❌ PR must have exactly one 'kind/*' label, but found $KIND_LABEL_COUNT."
exit 1
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading