-
Notifications
You must be signed in to change notification settings - Fork 91
190 lines (170 loc) · 6.46 KB
/
code-analysis.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: "Code analysis"
on:
workflow_call:
inputs:
os:
required: false
type: string
default: "ubuntu-22.04-amd64"
full-scan:
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
os:
required: false
type: string
default: "ubuntu-22.04-amd64"
full-scan:
required: false
type: boolean
default: false
jobs:
build-docker-image:
uses: ./.github/workflows/build-docker-artifact.yaml
secrets: inherit
with:
os: ${{ inputs.os }}
clang-tidy:
needs: build-docker-image
env:
ARCH_NAME: wormhole_b0
runs-on:
- build
- in-service
steps:
- name: Verify ccache availability
shell: bash
run: |
if [ ! -d "/mnt/MLPerf/ccache" ]; then
echo "::error title=ccache-mlperf-not-mounted::NFS drive is not mounted; build machine not properly provisioned."
exit 1
fi
if [ ! -d "$HOME/.ccache-ci" ]; then
echo "::error title=ccache-not-provisioned::Ccache is not properly provisioned."
exit 1
fi
- name: Set up dynamic env vars for build
run: |
echo "TT_METAL_HOME=$(pwd)" >> $GITHUB_ENV
echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV
- name: Generate docker tag
id: generate-docker-tag
uses: ./.github/actions/generate-docker-tag
with:
image: tt-metalium/${{ inputs.os }}
- name: Docker login
uses: docker/login-action@v3
with:
registry: https://ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull docker image
run: docker pull ${{ env.TT_METAL_DOCKER_IMAGE_TAG }}
- name: Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
clean: true
- name: Determine merge base
if: github.ref_name != 'main' && !inputs.full-scan
run: |
echo "Current branch: ${{ github.ref_name }}"
MERGE_BASE=$(git merge-base ${{ github.ref_name }} origin/main)
echo "Merge base between ${{ github.ref_name }} and main: $MERGE_BASE"
echo "MERGE_BASE=$MERGE_BASE" >> $GITHUB_ENV
- name: Check out baseline
if: github.ref_name != 'main' && !inputs.full-scan
uses: actions/checkout@v4
with:
ref: ${{ env.MERGE_BASE }}
fetch-depth: 0
submodules: recursive
clean: true
- name: Create baseline
if: github.ref_name != 'main' && !inputs.full-scan
uses: addnab/docker-run-action@v3
with:
image: ${{ env.TT_METAL_DOCKER_IMAGE_TAG }}
options: |
--rm
--tmpfs /tmp
-u ${{ env.RUNNER_UID }}:${{ env.RUNNER_GID }}
--group-add 1457
-v ${{ github.workspace }}:${{ github.workspace }}
-v /etc/passwd:/etc/passwd:ro
-v /etc/shadow:/etc/shadow:ro
-v /etc/bashrc:/etc/bashrc:ro
-v /home/ubuntu/.ccache-ci:/home/ubuntu/.ccache
-v /mnt/MLPerf/ccache:/mnt/MLPerf/ccache
-e ARCH_NAME=${{ env.ARCH_NAME }}
-e CARGO_HOME=${{ github.workspace }}/.cargo
-w ${{ github.workspace }}
run: |
set -eu # basic shell hygiene
# /tmp is a tmpfs; more efficient than persisted storage
mkdir -p /tmp/ccache
export CCACHE_TEMPDIR=/tmp/ccache
# Zero out the stats so we can see how we did this build
# NOTE: may be inaccurate if we have >1 build runner on the same machine, using the same local cache
ccache -z
# Suppress clang-tidy to first get an up-to-date build tree
ln -sf /usr/bin/true ./clang-tidy-shim
cmake --preset clang-tidy -DCMAKE_CXX_CLANG_TIDY=$(pwd)/clang-tidy-shim -DCMAKE_C_CLANG_TIDY=$(pwd)/clang-tidy-shim
nice -n 19 cmake --build --preset clang-tidy
mkdir -p out
ccache -s > out/ccache.stats
- name: Publish Ccache summary
if: github.ref_name != 'main' && !inputs.full-scan
run: |
echo '## CCache Summary (baseline)' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat out/ccache.stats >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive
clean: false
- name: Analyze code with clang-tidy
uses: addnab/docker-run-action@v3
with:
image: ${{ env.TT_METAL_DOCKER_IMAGE_TAG }}
options: |
--rm
--tmpfs /tmp
-u ${{ env.RUNNER_UID }}:${{ env.RUNNER_GID }}
--group-add 1457
-v ${{ github.workspace }}:${{ github.workspace }}
-v /etc/passwd:/etc/passwd:ro
-v /etc/shadow:/etc/shadow:ro
-v /etc/bashrc:/etc/bashrc:ro
-v /home/ubuntu/.ccache-ci:/home/ubuntu/.ccache
-v /mnt/MLPerf/ccache:/mnt/MLPerf/ccache
-e ARCH_NAME=${{ env.ARCH_NAME }}
-e CARGO_HOME=${{ github.workspace }}/.cargo
-w ${{ github.workspace }}
run: |
set -eu # basic shell hygiene
# /tmp is a tmpfs; more efficient than persisted storage
mkdir -p /tmp/ccache
export CCACHE_TEMPDIR=/tmp/ccache
# Zero out the stats so we can see how we did this build
# NOTE: may be inaccurate if we have >1 build runner on the same machine, using the same local cache
ccache -z
# Restore shim to legit clang-tidy
# Symlink tomfoolery here so that Ninja believes the build command has not changed from the previous run
ln -sf $(which clang-tidy-17) ./clang-tidy-shim
cmake --preset clang-tidy -DCMAKE_CXX_CLANG_TIDY=$(pwd)/clang-tidy-shim -DCMAKE_C_CLANG_TIDY=$(pwd)/clang-tidy-shim
nice -n 19 cmake --build --preset clang-tidy
mkdir -p out
ccache -s > out/ccache.stats
- name: Publish Ccache summary
run: |
echo '## CCache Summary' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat out/ccache.stats >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY