Skip to content

chore: Speed up semantic-breaking-change-pr.yml #11286

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions .github/actions/breaking-pr-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,68 @@ name: Validate Breaking Change PR
description: Validate breaking change PR title and description

runs:
using: node20
main: index.js
using: 'composite'
steps:
- name: Check PR title and body using github-script
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
async function getPullRequest() {
const pr = context.payload.pull_request;
if (!pr) {
throw new Error("This action can only be run on pull_request events.");
}

const owner = pr.base.repo.owner.login;
const repo = pr.base.repo.name;
const pull_number = pr.number;

const { data } = await github.rest.pulls.get({
owner,
repo,
pull_number,
});

return data;
}

function checkTitle(title) {
if (/^[a-z]+(\([a-z-]+\))?!: /.test(title)) {
throw new Error(
`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)) {
throw new Error(
`Breaking change PR body should start with "BREAKING CHANGE:". See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`,
);
}

if (!secondLine) {
throw new Error(
`The description of breaking change is missing. See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`,
);
}
}

async function run() {
const pr = await getPullRequest();
checkTitle(pr.title);
checkDescription(pr.body ?? '', pr.labels);
}

try {
await run();
} catch (e) {
throw new Error(e.message ?? String(e));
}
78 changes: 0 additions & 78 deletions .github/actions/breaking-pr-check/index.js

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/semantic-breaking-change-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
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 }}
Loading