-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (197 loc) · 7.27 KB
/
continuous-integration.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: Continuous Integration
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
CI: 1
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: 'always'
DIFF: 0
# For faster CI
RUST_LOG: 'off'
jobs:
cargo-fmt:
name: Cargo fmt
runs-on: ubuntu-latest
env:
RUST_LOG: '0'
steps:
- name: Find PR Comment
id: comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- CI COMMENT -->'
- name: Create or update PR comment
if: github.event_name == 'pull_request' && steps.comment.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v2
continue-on-error: true
with:
comment-id: ${{ steps.comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## :hourglass_flowing_sand: CI is running again... :hourglass_flowing_sand:
[Wait for it...](https://github.com/Sofi-Tech/Rust-Workers/actions/runs/${{ github.run_id }})
<!-- CI COMMENT -->
edit-mode: replace
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt
- run: cargo fmt --all -- --check
cargo-clippy:
name: Cargo clippy
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: clippy
- run: cargo clippy --all --all-targets -- -D warnings
cargo-test:
name: Cargo test
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
- name: Rust tests
run: cargo test --tests -- -Zunstable-options --report-time | tee test.txt
- name: Upload test.txt file to artifacts
uses: actions/upload-artifact@v3
with:
name: test-report
path: |
test.txt
# drop.png
if-no-files-found: error
# Above test down't exits if test fails because we are writing it in a file.
# So checking the file again to see if it was failed
- name: Fail if test fails
if: always()
run: |
if grep -q "test result: FAILED" test.txt || grep -q "due to previous error" test.txt; then
exit 1
fi
final:
name: Ok
needs:
- cargo-fmt
- cargo-clippy
- cargo-test
if: always()
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Check cancellation
id: cancelled
if: needs.cargo-fmt.result == 'cancelled' || needs.cargo-clippy.result == 'cancelled' || needs.cargo-test.result == 'cancelled'
run: echo "cancelled=true" >> $GITHUB_OUTPUT
- name: Start summary
run: |
echo "The following steps have failed in CI" > comment.md
echo >> comment.md
- name: Cargo Format
if: always() && needs.cargo-fmt.result != 'success' && needs.cargo-fmt.result != 'skipped'
run: |
echo "- Cargo Format" >> failures.md
exit 1
- name: Cargo Clippy
if: always() && needs.cargo-clippy.result != 'success' && needs.cargo-clippy.result != 'skipped'
run: |
echo "- Cargo Clippy" >> failures.md
exit 1
- name: Cargo Test
if: always() && needs.cargo-test.result != 'success' && needs.cargo-test.result != 'skipped'
run: |
echo "- Cargo Test" >> failures.md
exit 1
- name: Add failure prose text
if: failure()
run: |
echo "## :warning: CI failed :warning:" > comment.md
echo >> comment.md
echo "The following steps have failed in CI:" >> comment.md
echo >> comment.md
cat failures.md >> comment.md
echo >> comment.md
echo "See [workflow summary](https://github.com/Sofi-Tech/Rust-Workers/actions/runs/${{ github.run_id }}) for details">> comment.md
echo >> comment.md
echo "<!-- CI COMMENT -->" >> comment.md
- name: Add success prose text
if: success()
run: |
echo "## :green_circle: CI successful :green_circle:" > comment.md
echo >> comment.md
echo "Thanks" >> comment.md
echo >> comment.md
echo "<!-- CI COMMENT -->" >> comment.md
- name: Download test.txt file from artifacts
if: always() && github.event_name == 'pull_request' && steps.cancelled.outputs.cancelled != 'true'
uses: actions/download-artifact@v3
with:
name: test-report
path: report/
- name: Add Test Report
if: always() && github.event_name == 'pull_request' && steps.cancelled.outputs.cancelled != 'true'
run: |
echo "<details>" >> comment.md
echo "<summary>Test Report</summary>" >> comment.md
cat report/test.txt >> comment.md
echo "</details>" >> comment.md
# Sending image isn't possible atm
# Sending buffer exits the body limit
# echo >> comment.md
# echo "<details>" >> comment.md
# echo "<summary>Drop.png</summary>" >> comment.md
# echo "<img src=\"data:image/png;base64," >> comment.md
# base64 report/drop.png >> comment.md
# echo "\"/>" >> comment.md
# echo "</details>" >> comment.md
- name: Find PR Comment
id: comment
if: always() && github.event_name == 'pull_request' && steps.cancelled.outputs.cancelled != 'true'
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- CI COMMENT -->'
- name: Create or update PR comment
if: always() && github.event_name == 'pull_request' && steps.cancelled.outputs.cancelled != 'true'
uses: peter-evans/create-or-update-comment@v2
continue-on-error: true
with:
comment-id: ${{ steps.comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-file: 'comment.md'
edit-mode: replace
- name: It's not fine
if: failure() && steps.cancelled.outputs.cancelled != 'true'
run: exit 1
- name: It's fine
if: success() && steps.cancelled.outputs.cancelled != 'true'
run: echo Ok