Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
chore: add breaking change pr check ci#9050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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); | ||
| } | ||
Comment on lines +58 to +63 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nit: I'd personally rather something like | ||
| } | ||
| run(); | ||
| 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 | ||
auvred marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| 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 }} | ||