Repository navigation
51 lines (51 loc) · 1.79 KB
/
Copy pathlabel.yml
File metadata and controls
51 lines (51 loc) · 1.79 KB
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
name: Manage Labels
on:
workflow_run:
workflows: ["Test Everything"]
types: [completed]
jobs:
label-job:
name: Manage Labels
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/download-artifact@v8
with:
name: test-result
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const result = fs.readFileSync('test-result.txt', 'utf8').trim();
const labelName = 'tests-passed';
let pr = context.payload.workflow_run.pull_requests[0];
if (!pr) {
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.payload.workflow_run.head_repository.owner.login}:${context.payload.workflow_run.head_branch}`,
});
pr = prs[0];
}
if (!pr) {
console.log('No PR associated with this workflow run');
return;
}
const issue_number = pr.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
if (result === 'success') {
await github.rest.issues.addLabels({ issue_number, owner, repo, labels: [labelName] });
} else {
try {
await github.rest.issues.removeLabel({ issue_number, owner, repo, name: labelName });
} catch (e) {
if (e.status !== 404) throw e;
}
}