-
Notifications
You must be signed in to change notification settings - Fork 6
170 lines (160 loc) · 6.23 KB
/
ci.yaml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# See: https://docs.github.com/en/actions/writing-workflows
---
name: CI
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-formatting:
name: Check formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Install Rust
id: install-rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt
- name: Check formatting
run: cargo +${{ steps.install-rust.outputs.name }} fmt --all -- --check 2>/dev/null
check-targets:
strategy:
fail-fast: false
matrix:
include:
- name: Linux
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
# - name: macOS
# target: x86_64-apple-darwin
# os: macos-latest
# - name: Windows
# target: x86_64-pc-windows-gnu
# os: windows-latest
name: Check ${{ matrix.name }}
runs-on: ${{ matrix.os }}
needs:
- check-formatting
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Install Rust
id: install-rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.81.0
components: rustfmt
targets: ${{ matrix.target }}
- name: Build library
id: check-lib
if: ${{ always() }}
run: cargo +${{ steps.install-rust.outputs.name }} check --target ${{ matrix.target }} --workspace --keep-going --lib
- name: Build binaries
id: check-bins
if: ${{ always() }}
run: cargo +${{ steps.install-rust.outputs.name }} check --target ${{ matrix.target }} --workspace --keep-going --bins
- name: Build tests
id: check-tests
if: ${{ always() }}
run: cargo +${{ steps.install-rust.outputs.name }} check --target ${{ matrix.target }} --workspace --keep-going --tests
- name: Build examples
id: check-examples
if: ${{ always() }}
run: cargo +${{ steps.install-rust.outputs.name }} check --target ${{ matrix.target }} --workspace --keep-going --examples
- name: Run tests
id: run-tests
if: ${{ steps.check-tests.outcome == 'success' }}
run: |
cargo +${{ steps.install-rust.outputs.name }} test --target ${{ matrix.target }} --workspace --test "*" --no-fail-fast
review-pr:
name: Review PR
runs-on: ubuntu-latest
if: ${{ always() }}
needs:
- check-formatting
- check-targets
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
script: |
if (${{ needs.check-formatting.result != 'success' }} ||
${{ needs.check-targets.result != 'success' }}) {
let FORMATTING_JOB_NAME = 'Check formatting';
let VERBOSE = true;
let response = undefined;
let body = `
## ⚠️ CI failed
| Platform | Name | Status | Details |
| --- | --- | --- | --- |\n`;
function get_job_url(job_id) {
return `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${job_id}?check_suite_focus=true`;
}
function get_step_url(job_id, step_id) {
let job_url = get_job_url(job_id);
return `${job_url}#step:${step_id}:0`;
}
response = await github.rest.actions.listJobsForWorkflowRunAttempt({
...context.repo,
run_id: context.runId,
attempt_number: context.runAttempt || 1
});
let formatting_job = response.data.jobs.find(job => job.name.includes(FORMATTING_JOB_NAME));
if (formatting_job != undefined && (VERBOSE || formatting_job.conclusion == 'failure')) {
let succeed = formatting_job.conclusion == 'success' ? '✅' : '❌';
let url = get_job_url(formatting_job.id);
body += `| All | Formatting | ${succeed} | [Details](${url}) |\n`;
}
for (let job of response.data.jobs) {
if (job.name.startsWith('Check') && job.name != formatting_job.name &&
(VERBOSE || job.conclusion == 'failure')) {
let platform = job.name.split(' ')[1];
for (let step of job.steps) {
if ((step.name.startsWith('Build ') || step.name.startsWith('Run ')) &&
(VERBOSE || step.conclusion == 'failure')) {
let name = step.name;
let icon = '';
switch (step.conclusion) {
case 'success':
icon = '✅';
break;
case 'skipped':
icon = '⏩';
break;
case 'failure':
case 'cancelled':
icon = '❌';
break;
default:
// Should never reach here.
icon = '❓';
break;
}
let url = get_step_url(job.id, step.number);
body += `| ${platform} | ${name} | ${icon} | [Details](${url}) |\n`;
}
}
}
}
await github.rest.pulls.createReview({
...context.repo,
pull_number: context.issue.number,
event: 'REQUEST_CHANGES',
body: body,
});
} else {
await github.rest.pulls.createReview({
...context.repo,
pull_number: context.issue.number,
event: 'APPROVE',
});
}