-
Notifications
You must be signed in to change notification settings - Fork 2
208 lines (200 loc) · 6.29 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
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
name: CI
permissions:
contents: read
actions: read
security-events: write
on:
push:
branches:
- main
paths:
- '.github/workflows/ci.yml'
- '**/*.cpp'
- '**/*.hpp'
- '**/CMakeLists.txt'
- '**/.clang-tidy'
pull_request:
branches:
- main
paths:
- '.github/workflows/ci.yml'
- '**/*.cpp'
- '**/*.hpp'
- '**/CMakeLists.txt'
- '**/.clang-tidy'
jobs:
code-style-check:
name: Code style check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@v0.17
with:
source: './compiler'
extensions: 'hpp,cpp'
clangFormatVersion: 17
build-gcc:
name: Build on Ubuntu GCC
runs-on: ubuntu-latest
needs: code-style-check
container:
image: ghcr.io/vla5924-practice/compiler-project/devcontainer:latest
options: --user root
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- name: Initialize repository
uses: actions/checkout@v4
with:
submodules: true
- name: Build
env:
CC: gcc
CXX: g++
run: |
cmake -S compiler -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_CODEGEN=ast_to_llvmir
cmake --build build --parallel
- name: Archive binaries
run: tar cf binaries.tar -C build bin
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries-ubuntu-latest-gcc
path: binaries.tar
build-clang:
name: Build on Ubuntu Clang
runs-on: ubuntu-latest
needs: code-style-check
container:
image: ghcr.io/vla5924-practice/compiler-project/devcontainer:latest
options: --user root
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- name: Initialize repository
uses: actions/checkout@v4
with:
submodules: true
- name: Build
env:
CC: clang
CXX: clang++
run: |
cmake -S compiler -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_CODEGEN=ast_to_llvmir
cmake --build build --parallel
unit-test:
name: Unit test
runs-on: ubuntu-latest
needs: build-gcc
container:
image: ghcr.io/vla5924-practice/compiler-project/devcontainer:latest
options: --user root
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries-ubuntu-latest-gcc
- name: Extract binaries
run: tar xf binaries.tar
- name: Run AST interface tests
run: ./bin/ast_test
- name: Run operation tree interface tests
run: ./bin/optree_test
- name: Run frontend tests
run: ./bin/frontend_test
- name: Run AST-based backend tests
run: ./bin/backend_ast_test
- name: Run optree-based backend tests
run: ./bin/backend_optree_test
- name: Run codegen tests (AST to LLVM IR)
run: ./bin/codegen_ast_to_llvmir_test
code-coverage:
name: Code coverage
runs-on: ubuntu-latest
needs: build-gcc
container:
image: ghcr.io/vla5924-practice/compiler-project/devcontainer:latest
options: --user root
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- name: Install dependencies
run: |
apt-get update
apt-get install -y -q --no-install-recommends lcov curl
- name: Initialize repository
uses: actions/checkout@v4
with:
submodules: true
- name: Build and run tests
run: |
cmake -S compiler -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_CODEGEN=OFF -DENABLE_COVERAGE=ON
cmake --build build --target run_tests --parallel
- name: Generate coverage report
run: cmake --build build --target coverage
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: build/coverage
- name: Post coverage to Coveralls.io
uses: coverallsapp/github-action@v2.2.3
with:
github-token: ${{ secrets.github_token }}
file: ./build/coverage.info
format: lcov
fail-on-error: false
clang-tidy:
name: Clang-tidy analysis
runs-on: ubuntu-latest
needs: code-style-check
if: github.event_name == 'pull_request'
container:
image: ghcr.io/vla5924-practice/compiler-project/devcontainer:latest
options: --user root
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- name: Install dependencies
run: |
wget --no-check-certificate -qL -O clang-tidy-sarif https://github.com/psastras/sarif-rs/releases/download/clang-tidy-sarif-v0.4.2/clang-tidy-sarif-x86_64-unknown-linux-gnu
chmod +x clang-tidy-sarif
mv clang-tidy-sarif /usr/bin
ln -s /usr/share/clang/clang-tidy-diff.py /usr/bin/clang-tidy-diff
- name: Initialize repository
uses: actions/checkout@v4
with:
fetch-depth: 50
submodules: true
- name: Configure Git
run: |
git config --global --add safe.directory $(pwd)
git fetch origin main
- name: Build compilation database
run: |
cmake -S compiler -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_CODEGEN=ast_to_llvmir
cmake --build build --parallel
- name: Run clang-tidy analysis
run: |
git diff -U0 origin/main | clang-tidy-diff -p1 -path build > clang-tidy.log
cat clang-tidy.log
clang-tidy-sarif clang-tidy.log clang-tidy.json
sed -i -E "s@${PWD}/@@" clang-tidy.json
- name: Upload report
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: clang-tidy.json
category: clang-tidy
- name: Verify result
run: |
if grep -q '"level": "error"' clang-tidy.json; then
echo "Errors were found during clang-tidy analysis."
false
fi