ci: fix semver-checks master
This commit is contained in:
parent
11f28e2728
commit
6ab8f99731
|
@ -0,0 +1,85 @@
|
||||||
|
on: # yamllint disable-line rule:truthy
|
||||||
|
workflow_run:
|
||||||
|
workflows: [Check semver breaks]
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
|
name: Check semver breaks - Label and Comment PR
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Download:
|
||||||
|
name: Download, Unzip and Add Labels/Comments
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
# only run if CI passes on the "Check semver breaks" workflow
|
||||||
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||||
|
steps:
|
||||||
|
- name: "Download artifact"
|
||||||
|
uses: actions/github-script@v7
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
// get all artifacts from the workflow run
|
||||||
|
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
run_id: context.payload.workflow_run.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
// find the artifact that starts with 'semver-break'
|
||||||
|
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
||||||
|
return artifact.name.startsWith('semver-break');
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
// if no artifact found, exit
|
||||||
|
if (!matchArtifact) {
|
||||||
|
console.log('No semver-break artifact found');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise download the artifact
|
||||||
|
let download = await github.rest.actions.downloadArtifact({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
artifact_id: matchArtifact.id,
|
||||||
|
archive_format: 'zip',
|
||||||
|
});
|
||||||
|
|
||||||
|
// write the artifact to the workspace
|
||||||
|
let fs = require('fs');
|
||||||
|
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/semver-break.zip`, Buffer.from(download.data));
|
||||||
|
- name: "Unzip artifact"
|
||||||
|
if: ${{ hashFiles('semver-break.zip') != '' }}
|
||||||
|
run: unzip semver-break.zip
|
||||||
|
- name: "Comment and add label on PR - Semver break"
|
||||||
|
uses: actions/github-script@v7
|
||||||
|
if: ${{ hashFiles('semver-break') != '' }}
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
script: |
|
||||||
|
// sanitize and get the PR number from the semver-break file
|
||||||
|
const fs = require('fs');
|
||||||
|
let issue_number = parseInt(fs.readFileSync('semver-break', 'utf8'), 10);
|
||||||
|
|
||||||
|
// assure that is not NaN using Number.isNaN
|
||||||
|
// since does not coerce the value to a number like isNaN
|
||||||
|
if (Number.isNaN(issue_number)) {
|
||||||
|
console.log('PR_NUMBER is not a number');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// comment on the PR
|
||||||
|
await github.rest.issues.createComment({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: issue_number,
|
||||||
|
body: ':rotating_light: API BREAKING CHANGE DETECTED'
|
||||||
|
});
|
||||||
|
|
||||||
|
// add the label to the PR
|
||||||
|
await github.rest.issues.addLabels({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: issue_number,
|
||||||
|
labels: ['API break']
|
||||||
|
});
|
|
@ -22,15 +22,20 @@ jobs:
|
||||||
run: cargo binstall cargo-semver-checks --no-confirm
|
run: cargo binstall cargo-semver-checks --no-confirm
|
||||||
- name: "Run semver checker script"
|
- name: "Run semver checker script"
|
||||||
run: ./contrib/check-semver.sh
|
run: ./contrib/check-semver.sh
|
||||||
- name: "Add PR label to breaking changes"
|
- name: Save PR number
|
||||||
uses: actions-ecosystem/action-add-labels@v1
|
|
||||||
if: ${{ hashFiles('semver-break') != '' }}
|
if: ${{ hashFiles('semver-break') != '' }}
|
||||||
with:
|
env:
|
||||||
labels: "API break"
|
PR_NUMBER: ${{ github.event.number }}
|
||||||
- name: Comment PR
|
run: |
|
||||||
uses: thollander/actions-comment-pull-request@v2
|
# check if PR_NUMBER is a number
|
||||||
|
if ! [[ "$PR_NUMBER" =~ ^-?[0-9]+$ ]]; then
|
||||||
|
echo "$PR_NUMBER is not a number."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "$PR_NUMBER" > ./semver-break
|
||||||
|
- name: "Save breaking state"
|
||||||
if: ${{ hashFiles('semver-break') != '' }}
|
if: ${{ hashFiles('semver-break') != '' }}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
message: |
|
name: semver-break
|
||||||
:rotating_light: API BREAKING CHANGE DETECTED
|
path: semver-break
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue