forked from NomicFoundation/hardhat
-
Notifications
You must be signed in to change notification settings - Fork 4
55 lines (46 loc) · 1.49 KB
/
check-changeset-added.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
# Fails if a PR doesn't have a changeset and is not labeled
# as "no changeset needed"
name: Check that the PR has a changeset
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled
jobs:
check-if-changeset:
name: Check that PR has a changeset
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const pullNumber = context.issue.number;
const { data: files } = await github.rest.pulls.listFiles({
...context.issue,
pull_number: pullNumber
});
const changeset = files.find(
file => file.status === "added" && file.filename.startsWith(".changeset/")
);
if (changeset !== undefined) {
console.log("Changeset found:", changeset.filename);
return;
}
console.log("No changeset found");
const { data: pull } = await github.rest.pulls.get({
...context.issue,
pull_number: pullNumber
});
const noChangesetNeededLabel = pull.labels
.some(l => l.name === "no changeset needed");
if (noChangesetNeededLabel) {
console.log('The PR is labeled as "no changeset needed"');
return;
}
console.log('The PR is not labeled as "no changeset needed"');
process.exit(1);