forked from rust-bitcoin/rust-bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (76 loc) · 3.26 KB
/
semver-checks-pr-label.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 -n 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\n\nTo see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section.'
});
// 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']
});