From f4618cb12af169c6f110093af62920600d4dbbb7 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Thu, 17 Oct 2024 12:52:36 -0500 Subject: [PATCH] Making the label check case-insensitive --- .../workflows/github-actions-check-labels.yml | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/github-actions-check-labels.yml b/.github/workflows/github-actions-check-labels.yml index 652c5dcf1a..ebd6499fd7 100644 --- a/.github/workflows/github-actions-check-labels.yml +++ b/.github/workflows/github-actions-check-labels.yml @@ -13,24 +13,18 @@ jobs: GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} steps: - - name: Check for required Semver labels - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const requiredLabels = ['Major', 'Minor', 'Patch']; - const { data: labels } = await github.rest.issues.listLabelsOnIssue({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }); - const presentLabels = labels.map(label => label.name); - const presentRequiredLabel = requiredLabels.filter(label => presentLabels.includes(label)); + - name: Check for Semver label + run: | + LABELS=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") + SEMVER_PATTERN="^(major|minor|patch)$" - if (presentRequiredLabels.length === 0) { - core.setFailed('Your pull request is missing a required Semver label: (${requiredLabels.join(', ')})'); - } else if (presentRequiredLabels.length > 1) { - core.setFailed('Your pull request has multiple Semver labels. Please use only one.') - } else { - console.log('Pull request has a required Semver label.'); - } + SEMVER_LABEL=$(echo "$LABELS" | grep -iE "$SEMVER_PATTERN" || true) + + if [ -z "$SEMVER_LABEL" ]; then + echo "No valid Semver label found. Please add one of: major, minor, patch (case-insensitive)" + exit 1 + else + echo "Valid Semver label found: $SEMVER_LABEL" + NORMALIZED_LABEL=$(echo "$SEMVER_LABEL" | tr '[:upper:]' '[:lower:]') + echo "Normalized label: $NORMALIZED_LABEL" + fi \ No newline at end of file