-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3073 from NomicFoundation/add-changeset-check
Add changeset check
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); |