Skip to content

Incompatible changes will lead to added labels and failing actions #4

Incompatible changes will lead to added labels and failing actions

Incompatible changes will lead to added labels and failing actions #4

name: Compatibility Check
on:
pull_request:
jobs:
compatible:
name: Is change incompatible
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- name: Run script
id: check_incompatibility
run: |
cd .github/compatibility
npm ci
npm run check
- name: Add label PR on failure
if: failure() && steps.check_incompatibility.outcome == 'failure' # Only runs if your script failed.
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'incompatible-changes',
color: 'FF0000'
}).catch(err => console.log(`Label already exists`))
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['incompatible-changes']
})
github-token: ${{secrets.GITHUB_TOKEN}}
- name: Remove label PR on success
if: steps.check_incompatibility.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const labelName = "incompatible-changes"; // replace with your label name
github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: labelName,
color: 'FF0000'
}).catch(err => console.log(`Label already exists`))
try {
// Try to remove the label
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: labelName,
});
console.log(`Label '${labelName}' has been removed`);
} catch (error) {
// If the label does not exist, do nothing and log a message
if (error.status === 404) {
console.log(`Label '${labelName}' does not exist, nothing to do`);
} else {
// If it's another type of error, re-throw to see the error details in the workflow log
throw error;
}
}
github-token: ${{secrets.GITHUB_TOKEN}}