From 4ed3df12e17910d8639fb187b61c448cee2fe142 Mon Sep 17 00:00:00 2001 From: Victor Schappert Date: Wed, 11 Dec 2024 10:33:19 -0800 Subject: [PATCH 1/4] Require exactly 1 change type label on every schema PR --- ...hub-actions-enforce-change-type-label.yaml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/github-actions-enforce-change-type-label.yaml diff --git a/.github/workflows/github-actions-enforce-change-type-label.yaml b/.github/workflows/github-actions-enforce-change-type-label.yaml new file mode 100644 index 00000000..d3a86a4b --- /dev/null +++ b/.github/workflows/github-actions-enforce-change-type-label.yaml @@ -0,0 +1,33 @@ +name: Change Type label verification + +on: + pull_request: + types: [opened, edited, labeled, unlabeled, synchronize] + +jobs: + check-label: + runs-on: ubuntu-latest + steps: + - name: Require exactly one change type label + uses: actions/github-script@v6 + with: + script: | + const allChangeTypeLabels = new Set([ + 'change type - cosmetic 🌹', + 'change type - documentation - docs team 📝', + 'change type - documentation - member 📝', + 'change type - major 🚨', + 'change type - minor 🤏', + ]); + const prLabels = context.payload.pull_request.labels.map(label => label.name); + const appliedChangeTypeLabels = prLabels.filter(prLabel => allChangeTypeLabels.has(prLabel)); + if (appliedChangeTypeLabels.length !== 1) { + const baseMessage = `The PR must have EXACTLY one of the following CHANGE TYPE labels: ${Array.from(changeTypeLabels).sort().join(', ')}. ` + let contextualMessage; + if (appliedChangeTypeLabels.length === 0) { + contextualMessage = 'It currently has no change type label. Add one.' + } else { + contextualMessage = `It currently has ${appliedChangeTypeLabels.length} change type labels (${JSON.stringify(appliedChangeTypeLabels)}). Remove one. + } + core.setFailed(baseMessage + contextualMessage); + } From a67057a0e38262cb33d5a09c17af89cb63ab9835 Mon Sep 17 00:00:00 2001 From: Victor Schappert Date: Wed, 11 Dec 2024 10:43:11 -0800 Subject: [PATCH 2/4] Fix syntax error (squash this commit) --- .github/workflows/github-actions-enforce-change-type-label.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-enforce-change-type-label.yaml b/.github/workflows/github-actions-enforce-change-type-label.yaml index d3a86a4b..8f0ded57 100644 --- a/.github/workflows/github-actions-enforce-change-type-label.yaml +++ b/.github/workflows/github-actions-enforce-change-type-label.yaml @@ -27,7 +27,7 @@ jobs: if (appliedChangeTypeLabels.length === 0) { contextualMessage = 'It currently has no change type label. Add one.' } else { - contextualMessage = `It currently has ${appliedChangeTypeLabels.length} change type labels (${JSON.stringify(appliedChangeTypeLabels)}). Remove one. + contextualMessage = `It currently has ${appliedChangeTypeLabels.length} change type labels (${JSON.stringify(appliedChangeTypeLabels)}). Remove one.` } core.setFailed(baseMessage + contextualMessage); } From d4b62bf2a98c925fc7acfadf7e67e8fb66723a9c Mon Sep 17 00:00:00 2001 From: Victor Schappert Date: Wed, 11 Dec 2024 10:45:28 -0800 Subject: [PATCH 3/4] Fix JS semantic error: wrong variable reference (Squash this commit) --- .github/workflows/github-actions-enforce-change-type-label.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-enforce-change-type-label.yaml b/.github/workflows/github-actions-enforce-change-type-label.yaml index 8f0ded57..6e1b2ec8 100644 --- a/.github/workflows/github-actions-enforce-change-type-label.yaml +++ b/.github/workflows/github-actions-enforce-change-type-label.yaml @@ -22,7 +22,7 @@ jobs: const prLabels = context.payload.pull_request.labels.map(label => label.name); const appliedChangeTypeLabels = prLabels.filter(prLabel => allChangeTypeLabels.has(prLabel)); if (appliedChangeTypeLabels.length !== 1) { - const baseMessage = `The PR must have EXACTLY one of the following CHANGE TYPE labels: ${Array.from(changeTypeLabels).sort().join(', ')}. ` + const baseMessage = `The PR must have EXACTLY one of the following CHANGE TYPE labels: ${Array.from(appliedChangeTypeLabels).sort().join(', ')}. ` let contextualMessage; if (appliedChangeTypeLabels.length === 0) { contextualMessage = 'It currently has no change type label. Add one.' From 1e3fd7f3ab895d8c3a54a9f17db3f8c464b54bb2 Mon Sep 17 00:00:00 2001 From: Victor Schappert Date: Wed, 11 Dec 2024 10:50:59 -0800 Subject: [PATCH 4/4] Fix various logic errors (Squash this commit) --- .../github-actions-enforce-change-type-label.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-actions-enforce-change-type-label.yaml b/.github/workflows/github-actions-enforce-change-type-label.yaml index 6e1b2ec8..e76cc5b9 100644 --- a/.github/workflows/github-actions-enforce-change-type-label.yaml +++ b/.github/workflows/github-actions-enforce-change-type-label.yaml @@ -22,12 +22,13 @@ jobs: const prLabels = context.payload.pull_request.labels.map(label => label.name); const appliedChangeTypeLabels = prLabels.filter(prLabel => allChangeTypeLabels.has(prLabel)); if (appliedChangeTypeLabels.length !== 1) { - const baseMessage = `The PR must have EXACTLY one of the following CHANGE TYPE labels: ${Array.from(appliedChangeTypeLabels).sort().join(', ')}. ` + const baseMessage = `The PR must have EXACTLY one of the following CHANGE TYPE labels: ${Array.from(allChangeTypeLabels).sort().join(', ')}. ` + const n = appliedChangeTypeLabels.length; let contextualMessage; - if (appliedChangeTypeLabels.length === 0) { - contextualMessage = 'It currently has no change type label. Add one.' + if (n === 0) { + contextualMessage = 'It currently has no change type label. Please ➕ add one label. 🙏' } else { - contextualMessage = `It currently has ${appliedChangeTypeLabels.length} change type labels (${JSON.stringify(appliedChangeTypeLabels)}). Remove one.` + contextualMessage = `It currently has ${n} change type labels (${JSON.stringify(appliedChangeTypeLabels)}). 🙏 Please ❌ remove ${n-1} label(s).` } core.setFailed(baseMessage + contextualMessage); }