From b7769cb57f434c8475d8eabde1fae452c5a5640f Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 21 Aug 2024 10:07:58 -0500 Subject: [PATCH] Check that each PR has one of the semver labels Fixes https://github.com/con/duct/issues/137 --- .github/workflows/labels.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/labels.yaml diff --git a/.github/workflows/labels.yaml b/.github/workflows/labels.yaml new file mode 100644 index 00000000..e0fba7ea --- /dev/null +++ b/.github/workflows/labels.yaml @@ -0,0 +1,25 @@ +name: Check PR Labels + +on: + pull_request: + types: [opened, labeled, unlabeled, synchronize] + +jobs: + check_labels: + runs-on: ubuntu-latest + steps: + - name: Check PR Labels + uses: actions/github-script@v6 + with: + script: | + const requiredPattern = /^semver-.*/; + const labels = context.payload.pull_request.labels.map(label => label.name); + + // Check if one of the labels matches the pattern + const hasMatchingLabel = labels.some(label => requiredPattern.test(label)); + + if (!hasMatchingLabel) { + core.setFailed(`The pull request must have a label matching the pattern 'somestring-*'.`); + } else { + console.log('PR has a valid label'); + }