-
Notifications
You must be signed in to change notification settings - Fork 38
234 lines (197 loc) · 7.48 KB
/
ci.yml
File metadata and controls
234 lines (197 loc) · 7.48 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
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
227
228
229
230
231
232
233
234
name: Linmo CI
on:
push:
branches:
- main
pull_request:
branches:
- main
# Cancel in-progress runs for the same PR/branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Least-privilege permissions
permissions:
contents: read
jobs:
# Fast-running lint job to catch formatting issues early
lint:
runs-on: ubuntu-24.04
name: Code Quality Checks
timeout-minutes: 10
env:
CLANG_FORMAT_VERSION: 18
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install linting tools
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang-format-${{ env.CLANG_FORMAT_VERSION }} shfmt
- name: Check code formatting
run: .ci/check-format.sh
- name: Check newline at end of files
run: .ci/check-newline.sh
# Build and test matrix - GNU and LLVM run in parallel after lint passes
# GNU: Full test suite (build + app tests + functional tests)
# LLVM: Build-only validation (verifies cross-toolchain compatibility)
matrix-tests:
runs-on: ubuntu-24.04
name: ${{ matrix.toolchain }} toolchain
needs: lint
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
toolchain: [GNU, LLVM]
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install QEMU
if: matrix.toolchain == 'GNU'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-riscv32
- name: Set toolchain name
id: toolchain
run: echo "name=$(echo '${{ matrix.toolchain }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Cache toolchain
uses: actions/cache@v5
id: cache-toolchain
with:
path: riscv
key: riscv32-${{ steps.toolchain.outputs.name }}-${{ hashFiles('.ci/setup-toolchain.sh') }}
- name: Setup ${{ matrix.toolchain }} toolchain
if: steps.cache-toolchain.outputs.cache-hit != 'true'
run: .ci/setup-toolchain.sh ${{ steps.toolchain.outputs.name }}
- name: Configure toolchain environment
run: |
echo "$PWD/riscv/bin" >> "$GITHUB_PATH"
echo "CROSS_COMPILE=riscv32-unknown-elf-" >> "$GITHUB_ENV"
echo "TOOLCHAIN_TYPE=${{ steps.toolchain.outputs.name }}" >> "$GITHUB_ENV"
- name: Verify toolchain
run: |
if [ "${{ matrix.toolchain }}" = "GNU" ]; then
riscv32-unknown-elf-gcc --version
qemu-system-riscv32 --version
else
riscv32-unknown-elf-clang --version
fi
- name: Build kernel
run: make -j$(nproc)
- name: Run app tests
id: test
continue-on-error: true
if: matrix.toolchain == 'GNU'
run: |
output=$(.ci/run-app-tests.sh 2>&1) || true
delimiter=$(openssl rand -hex 8)
echo "TEST_OUTPUT<<$delimiter" >> $GITHUB_OUTPUT
echo "$output" >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
- name: Run functional tests
id: functional_test
continue-on-error: true
if: matrix.toolchain == 'GNU'
run: |
output=$(.ci/run-functional-tests.sh 2>&1) || true
delimiter=$(openssl rand -hex 8)
echo "FUNCTIONAL_TEST_OUTPUT<<$delimiter" >> $GITHUB_OUTPUT
echo "$output" >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
- name: Collect test data
if: always()
run: |
set -euo pipefail
COMMIT_SHA="${{ github.sha }}"
COMMIT_SHORT=$(git rev-parse --short HEAD 2>/dev/null || echo "${{ github.sha }}" | cut -c1-7)
GITHUB_REPO="${{ github.repository }}"
if [ "${{ matrix.toolchain }}" = "LLVM" ]; then
# LLVM: Build-only validation, skip tests
mkdir -p test-results
echo "${{ steps.toolchain.outputs.name }}" > test-results/toolchain
echo "$COMMIT_SHA" > test-results/commit_sha
echo "$COMMIT_SHORT" > test-results/commit_short
echo "$GITHUB_REPO" > test-results/github_repo
echo "skipped" > test-results/crash_exit_code
echo "skipped" > test-results/functional_exit_code
# Generate skipped status for all apps
for app in $(find app/ -name "*.c" -exec basename {} .c \; | sort); do
echo "$app=skipped" >> test-results/apps_data
done
# Generate skipped status for functional tests
echo "mutex=skipped" > test-results/functional_data
echo "semaphore=skipped" >> test-results/functional_data
# Generate skipped status for functional test criteria
printf '%s\n' \
"mutex:fairness=skipped" \
"mutex:mutual_exclusion=skipped" \
"mutex:data_consistency=skipped" \
"mutex:overall=skipped" \
"semaphore:overall=skipped" \
> test-results/functional_criteria_data
echo "LLVM: Build validation only (tests skipped)"
else
# GNU: Full test suite
.ci/ci-tools.sh collect-data "${{ steps.toolchain.outputs.name }}" "$COMMIT_SHA" "$COMMIT_SHORT" "$GITHUB_REPO" "${{ steps.test.outputs.TEST_OUTPUT }}" "${{ steps.functional_test.outputs.FUNCTIONAL_TEST_OUTPUT }}"
fi
- name: Upload test results
if: always()
uses: actions/upload-artifact@v6
with:
name: test-results-${{ matrix.toolchain }}
path: test-results/
retention-days: 7
if-no-files-found: warn
# Aggregate results from all toolchain builds
test-summary:
runs-on: ubuntu-24.04
needs: matrix-tests
if: always()
timeout-minutes: 10
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download test results
uses: actions/download-artifact@v7
with:
pattern: test-results-*
path: all-test-results/
- name: Generate test summary
id: summary
run: |
.ci/ci-tools.sh aggregate all-test-results test-summary.toml
if [ -f test-summary.toml ]; then
echo "generated=true" >> $GITHUB_OUTPUT
cat test-summary.toml
else
echo "generated=false" >> $GITHUB_OUTPUT
echo "Warning: test-summary.toml not generated"
fi
- name: Upload test summary
if: steps.summary.outputs.generated == 'true'
uses: actions/upload-artifact@v6
with:
name: test-summary
path: test-summary.toml
retention-days: 30
- name: Post PR comment
if: github.event_name == 'pull_request' && steps.summary.outputs.generated == 'true'
continue-on-error: true
run: .ci/ci-tools.sh post-comment test-summary.toml ${{ github.event.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check final status
run: |
if [ ! -f test-summary.toml ]; then
echo "Error: test-summary.toml not found"
exit 1
fi
status=$(grep -A1 '^\[summary\]' test-summary.toml | grep 'status =' | cut -d'"' -f2)
echo "Overall status: $status"
if [ "$status" = "passed" ]; then
echo "All tests passed"
else
echo "Tests failed"
grep -E '(failed|error)' test-summary.toml || true
exit 1
fi