-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add breaking change pr check ci (#9050)
* chore: add breaking change pr check ci * apply review * apply review
- Loading branch information
Showing
3 changed files
with
93 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,6 @@ | ||
name: Validate Breaking Change PR | ||
description: Validate breaking change PR title and description | ||
|
||
runs: | ||
using: node20 | ||
main: index.js |
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,66 @@ | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
|
||
function raiseError(message) { | ||
throw new Error(message); | ||
} | ||
|
||
async function getPullRequest() { | ||
const client = github.getOctokit(process.env.GITHUB_TOKEN); | ||
|
||
const pr = github.context.payload.pull_request; | ||
if (!pr) { | ||
throw new Error( | ||
"This action can only be invoked in `pull_request_target` or `pull_request` events. Otherwise the pull request can't be inferred.", | ||
); | ||
} | ||
|
||
const owner = pr.base.user.login; | ||
const repo = pr.base.repo.name; | ||
|
||
const { data } = await client.rest.pulls.get({ | ||
owner, | ||
repo, | ||
pull_number: pr.number, | ||
}); | ||
|
||
return data; | ||
} | ||
|
||
function checkTitle(title) { | ||
if (/^[a-z]+(\([a-z-]+\))?!: /.test(title)) { | ||
raiseError( | ||
`Do not use exclamation mark ('!') to indicate breaking change in the PR Title.`, | ||
); | ||
} | ||
} | ||
|
||
function checkDescription(body, labels) { | ||
if (!labels.some(label => label.name === 'breaking change')) { | ||
return; | ||
} | ||
const [firstLine, secondLine] = body.split(/\r?\n/); | ||
|
||
if (!firstLine || !/^BREAKING CHANGE:/.test(firstLine)) { | ||
raiseError( | ||
`Breaking change PR body should start with "BREAKING CHANGE:". See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`, | ||
); | ||
} | ||
if (!secondLine) { | ||
raiseError( | ||
`The description of breaking change is missing. See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`, | ||
); | ||
} | ||
} | ||
|
||
async function run() { | ||
const pullRequest = await getPullRequest(); | ||
try { | ||
checkTitle(pullRequest.title); | ||
checkDescription(pullRequest.body, pullRequest.labels); | ||
} catch (e) { | ||
core.setFailed(e.message); | ||
} | ||
} | ||
|
||
run(); |
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,21 @@ | ||
name: Semantic Breaking Change PR | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
- labeled | ||
- unlabeled | ||
|
||
jobs: | ||
main: | ||
name: Validate Breaking Change PR | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/prepare-install | ||
- uses: ./.github/actions/breaking-pr-check | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |