-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: changeset validating github action
- Loading branch information
1 parent
c25b726
commit bdaa734
Showing
2 changed files
with
63 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,20 @@ | ||
name: Validate PRs | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- edited | ||
|
||
jobs: | ||
validate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const { validate } = await import('${{ github.workspace }}/scripts/validate-prs.js'); | ||
await validate({ context }); |
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,43 @@ | ||
/* eslint-env node */ | ||
import read from '@changesets/read'; | ||
import conventionalCommitsParser from 'conventional-commits-parser'; | ||
|
||
export async function validate({ context }) { | ||
const { base, title, auto_merge: autoMerge } = context.payload.pull_request; | ||
|
||
if (base.startsWith('staging/')) { | ||
return true; | ||
} | ||
|
||
const { type } = conventionalCommitsParser.sync(title); | ||
|
||
console.log({ type }); | ||
|
||
if (autoMerge?.merge_method === 'rebase') { | ||
throw new Error('Validating auto-rebase PRs is not yet implemented'); | ||
// one approach could be to use `@commitlint/load` to read { from: baseBranch } | ||
// then pipe that array as a stream to conventionalcommitsparser's transform stream | ||
} | ||
|
||
const sets = await read(process.cwd()); | ||
|
||
const release = sets.reduce((greatest, type) => { | ||
switch (greatest) { | ||
case null: | ||
case 'major': | ||
return greatest; | ||
case 'minor': | ||
return type === 'major' ? type : greatest; | ||
case 'patch': | ||
return (type === 'major' || type === 'minor') ? type : greatest; | ||
} | ||
}, null); | ||
|
||
if (!release && type) { | ||
throw new Error(`PR conventional commit title has type (${type}) but no changesets were detected.`); | ||
} | ||
|
||
if (type !== release) { | ||
throw new Error(`PR conventional commit title type (${type}) does not match release type (${release}).`); | ||
} | ||
} |