From a44c191829acd5dc56303c6cdd4e5f212b48309a Mon Sep 17 00:00:00 2001 From: Adam Haeger Date: Mon, 21 Oct 2024 13:41:16 +0200 Subject: [PATCH] Created github action to check that a label has been added before merge (#2605) * Created github action to check that a label has been added before merging * added case for ignore for release --- .github/workflows/check-label-added.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/check-label-added.yml diff --git a/.github/workflows/check-label-added.yml b/.github/workflows/check-label-added.yml new file mode 100644 index 000000000..1fe3f5164 --- /dev/null +++ b/.github/workflows/check-label-added.yml @@ -0,0 +1,21 @@ +name: "Label Check" +on: + pull_request: + types: [opened, edited, labeled, unlabeled, synchronize] + +jobs: + check-label: + runs-on: ubuntu-latest + steps: + - name: Check labels + uses: actions/github-script@v6 + with: + script: | + const labels = context.payload.pull_request.labels; + const hasIgnoreLabel = labels.some(label => label.name === 'ignore-for-release'); + if (!hasIgnoreLabel) { + const hasMatchingLabel = labels.some(label => /^kind\/.*/.test(label.name)); + if (!hasMatchingLabel) { + core.setFailed('The PR must have at least one label matching the pattern "kind/*", unless it has the "ignore-for-release" label.'); + } + }