-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (139 loc) · 4.65 KB
/
rust.yml
File metadata and controls
165 lines (139 loc) · 4.65 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
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
name: Rust
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
issues: write
pull-requests: write
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Cargo build
uses: actions/cache@v3
with:
path: rook/target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('rook/Cargo.lock') }}
- name: Check formatting
working-directory: rook
run: |
# Redirecting log output to the parent directory to consolidate logs from multiple steps.
cargo fmt -- --check > ../fmt-log.txt 2>&1
FMT_STATUS=$?
cat ../fmt-log.txt
exit $FMT_STATUS
- name: Lint with Clippy
working-directory: rook
run: |
cargo clippy -- -D warnings > ../clippy-log.txt 2>&1
CLIPPY_STATUS=$?
cat ../clippy-log.txt
exit $CLIPPY_STATUS
- name: Build
working-directory: rook
run: |
cargo build --verbose > ../build-log.txt 2>&1
BUILD_STATUS=$?
cat ../build-log.txt
exit $BUILD_STATUS
- name: Run tests
working-directory: rook
run: |
cargo test --verbose > ../test-log.txt 2>&1
TEST_STATUS=$?
cat ../test-log.txt
exit $TEST_STATUS
- name: Capture failure reason
if: failure()
# Switch to the repository root to access log files generated in earlier steps.
working-directory: .
run: |
echo "" > full-log.txt
if [ -f fmt-log.txt ]; then
echo "=== Formatting Log ===" >> full-log.txt
cat fmt-log.txt >> full-log.txt
fi
if [ -f clippy-log.txt ]; then
[ -s full-log.txt ] && echo "" >> full-log.txt
echo "=== Clippy Log ===" >> full-log.txt
cat clippy-log.txt >> full-log.txt
fi
if [ -f build-log.txt ]; then
[ -s full-log.txt ] && echo "" >> full-log.txt
echo "=== Build Log ===" >> full-log.txt
cat build-log.txt >> full-log.txt
fi
if [ -f test-log.txt ]; then
[ -s full-log.txt ] && echo "" >> full-log.txt
echo "=== Test Log ===" >> full-log.txt
cat test-log.txt >> full-log.txt
fi
tail -n 20 full-log.txt > summary.txt
- name: Upload failure summary
if: failure()
uses: actions/upload-artifact@v4
with:
name: failure-summary
path: summary.txt
notify-on-failure:
needs: build
runs-on: ubuntu-latest
if: failure() && github.event_name == 'pull_request'
steps:
- name: Download failure summary
uses: actions/download-artifact@v4
with:
name: failure-summary
path: .
- name: Read failure summary
id: read_summary
run: |
cat summary.txt > comment.txt
- name: Post failure comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const runUrl = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`;
let summary = fs.readFileSync('comment.txt', 'utf8');
// Truncate the summary to 500 characters to ensure the comment remains concise
// and avoids exceeding potential length constraints for GitHub comments.
if (summary.length > 500) {
summary = summary.substring(0, 500);
}
const commentBody = [
'**?? Blunder** 😵💫',
'Your CI made a critical mistake on the board.',
'',
'<details>',
'<summary><b>❌ Failure Details</b></summary>',
'',
'```',
summary,
'```',
'',
'</details>',
'',
`See the full battle logs here: [View Logs](${runUrl})`,
'',
'_Time to rethink your next move!_'
].join('\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});