-
Notifications
You must be signed in to change notification settings - Fork 16
98 lines (93 loc) · 2.86 KB
/
ci.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
86
87
88
89
90
91
92
93
94
95
96
97
98
name: PullRequestChecker
# Since there are PRs sent from external users, do not trigger automatically but manually
on:
pull_request_target:
types: [labeled]
jobs:
check:
if: contains(github.event.pull_request.labels.*.name, 'run-check')
runs-on: ubuntu-latest
steps:
- name: Checkout User's PR
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Use Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: 18.x
- name: Install dependencies
run: npm install
- name: Lint
run: npm run lint-check
- name: Format
run: npm run format-check
- name: Test
run: npm run test
remove-label:
needs: check
if: always()
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Remove run-check label
uses: actions/github-script@v5
with:
script: |
const issue_number = context.issue.number;
const label = 'run-check';
github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
name: label
});
notify-failer:
needs: check
if: always()
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: If CI fails, notify the user who created the PR
if: ${{ needs.check.result == 'failure' }}
uses: actions/github-script@v5
with:
script: |
const issue_number = context.issue.number;
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue_number,
});
const pr_author = pr.data.user.login;
const message = `@${pr_author} The CI checks failed. Please review the errors and push fixes.`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
notify-success:
needs: check
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: If the CI is successful, notify the user who created the PR.
if: ${{ needs.check.result == 'success' }}
uses: actions/github-script@v5
with:
script: |
const issue_number = context.issue.number;
const message = `The CI checks passed.`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});