diff --git a/.github/workflows/IssueLabelChecker.yml b/.github/workflows/IssueLabelChecker.yml index 4409efa..fd4664b 100644 --- a/.github/workflows/IssueLabelChecker.yml +++ b/.github/workflows/IssueLabelChecker.yml @@ -14,9 +14,22 @@ jobs: - uses: actions/checkout@v6 - name: Check and Add label run: | - LABELS=$(gh issue view ${{ github.event.issue.number }} --json labels -q '.labels[].name') - if [[ $LABELS != *"needs review"* ]]; then - gh issue edit ${{ github.event.issue.number }} --add-label "needs review" + # The cryptic head -c -1 is because otherwise gh always terminates output with a newline + readarray -d $'\0' lifecycles < <(gh issue view ${{ github.event.issue.number }} --json labels -q '[.labels[] | .name | select(startswith("lifecycle/"))] | join("\u0000")' | head -c -1) + if [[ ${#lifecycles[@]} -ne 1 ]]; then + if [[ ${#lifecycles[@]} -ge 1 ]]; then + echo 'Too many lifecycle labels; replacing all with `lifecycle/needs-review`' + fi + commands=() + for label in "${lifecycles[@]}"; do + if [[ "$label" != "lifecycle/needs-review" ]]; then + echo "Removing label ${label}" + commands+=("--remove-label" "${label}") + fi + done + echo 'Adding `lifecycle/needs-review`' + commands+=("--add-label" "lifecycle/needs-review") + gh issue edit ${{ github.event.issue.number }} "${commands[@]}" fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/PRLabelChecker.yml b/.github/workflows/PRLabelChecker.yml index 36b0977..9e16fdb 100644 --- a/.github/workflows/PRLabelChecker.yml +++ b/.github/workflows/PRLabelChecker.yml @@ -12,18 +12,18 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - - name: Check for specific labels + - name: Ensure exactly one "kind/*" label is applied run: | - PR_NUMBER=$(echo ${{ github.event.pull_request.number }}) - LABELS_JSON=$(gh pr view $PR_NUMBER --json labels -q '.labels.[] | .name') - REQUIRED_LABELS=("chore" "ignore" "breaking-change" "enhancement" "feature" "dependencies" "bug" "security" "performance" "refactor" "testing" "documentation" "github-actions") - for REQUIRED_LABEL in "${REQUIRED_LABELS[@]}"; do - if echo "$LABELS_JSON" | grep -q "$REQUIRED_LABEL"; then - echo "One of the required labels is present" - exit 0 - fi - done - echo "None of the required labels are present" - exit 1 + # Count the number of "kind/*" labels directly from the PR labels + PR_NUMBER=${{ github.event.pull_request.number }} + KIND_LABEL_COUNT=$(gh pr view "$PR_NUMBER" --json labels -q '.labels.[].name' | grep -c '^kind/') + + 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 }} \ No newline at end of file