-
Notifications
You must be signed in to change notification settings - Fork 36
55 lines (45 loc) · 1.54 KB
/
enforce-semver.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: Check if SemVer label is set
on:
pull_request:
# cf: https://github.com/yogevbd/enforce-label-action#enforce-pr-labels
types: [labeled, unlabeled, opened, edited, synchronize]
env:
# see: https://github.com/pixiv/charcoal/issues/labels
SEMVER_LABELS: '["major", "minor", "patch", "beta"]'
jobs:
enforce-semver:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const { issue, repo } = context
const { data: pull } = await github.rest.issues.get({
issue_number: issue.number,
owner: repo.owner,
repo: repo.repo,
})
const labels = pull.labels.map(({ name }) => name)
const SEMVER_LABELS = JSON.parse(process.env.SEMVER_LABELS)
const result = new Set()
for (const label of labels) {
for (const semver of SEMVER_LABELS) {
if (label !== semver) {
continue
}
result.add(semver)
}
}
switch (result.size) {
case 1: {
const [next] = result.values()
console.log(`Merging this PR will be a ${next} release`)
break
}
case 0: {
throw new Error(`One of semver labels (${SEMVER_LABELS}) must be set`)
}
default: {
throw new Error(`Do not set multiple semver labels: ${labels}`)
}
}