From 6b34cc3c18d129f823ddb1e8a1434e198b9a1050 Mon Sep 17 00:00:00 2001 From: Reshama Shaikh Date: Fri, 29 Nov 2024 10:42:26 -0500 Subject: [PATCH] GH action to require a semver label --- .github/workflows/assign-semver.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/assign-semver.yml diff --git a/.github/workflows/assign-semver.yml b/.github/workflows/assign-semver.yml new file mode 100644 index 000000000..4e3528a63 --- /dev/null +++ b/.github/workflows/assign-semver.yml @@ -0,0 +1,22 @@ +name: Require semver label before merge + +on: + pull_request: + types: [opened, edited, labeled, unlabeled, synchronize] + +jobs: + require-label: + runs-on: ubuntu-latest + + steps: + - name: Check for required labels + uses: actions/github-script@v6 + with: + script: | + const requiredLabels = ['Semver-Major', 'Semver-Minor', 'Semver-Patch']; + const labels = context.payload.pull_request.labels.map(label => label.name); + const hasRequiredLabel = requiredLabels.some(label => labels.includes(label)); + + if (!hasRequiredLabel) { + core.setFailed(`Pull request must have one of the following labels: ${requiredLabels.join(', ')}`); + } \ No newline at end of file