-
Notifications
You must be signed in to change notification settings - Fork 0
357 lines (313 loc) · 13.5 KB
/
pr-development-workflow.yml
File metadata and controls
357 lines (313 loc) · 13.5 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
name: PR development - Build and Run Tests Workflow
# if statements modified to avoid: https://stackoverflow.com/questions/69354003/github-action-job-fire-when-previous-job-skipped
on:
workflow_call:
inputs:
os:
required: true
type: string
arch:
required: true
type: string
permissions:
contents: read
env:
REGISTRY: ghcr.io
DOCKERIMAGE: ghcr.io/algebraic-programming/taskr/buildenv
defaults:
run:
shell: bash
jobs:
check-dockerfile-modifications-with-base:
runs-on: ${{ inputs.os }}
outputs:
dockerfile-modified: ${{ steps.check-dockerfile.outputs.dockerfile-modified }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Check the PR diff using the current branch and the base branch of the PR
- name: Run git diff
run: |
git diff --name-only origin/main ${{ github.event.pull_request.head.sha }} > ${{ runner.temp }}/diff.txt
- name: Check if Dockerfile was modified
id: check-dockerfile
env:
MODIFIED_FILES_PATH: ${{ runner.temp }}/diff.txt
run: |
echo "$(git rev-parse origin/main)"
echo "$(git rev-parse ${{ github.event.pull_request.head.sha }})"
cat $MODIFIED_FILES_PATH
if cat $MODIFIED_FILES_PATH | grep -q 'buildenv/Dockerfile' ; then
echo "Dockerfile was modified"
echo "dockerfile-modified=true" >> $GITHUB_OUTPUT
else
echo "Dockerfile was not modified"
echo "dockerfile-modified=false" >> $GITHUB_OUTPUT
fi
check-dockerfile-modifications-with-last-commit:
runs-on: ${{ inputs.os }}
outputs:
dockerfile-modified: ${{ steps.check-dockerfile.outputs.dockerfile-modified }}
steps:
- name: Checkout repository
id: checkout-base
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
# Check the PR diff using the current branch and the base branch of the PR
- name: Run git diff
run: |
git diff --name-only HEAD^ HEAD > ${{ runner.temp }}/diff.txt
- name: Check if Dockerfile was modified
id: check-dockerfile
env:
MODIFIED_FILES_PATH: ${{ runner.temp }}/diff.txt
run: |
echo "HEAD^: $(git rev-parse HEAD^)"
echo "HEAD: $(git rev-parse HEAD)"
cat $MODIFIED_FILES_PATH
if cat $MODIFIED_FILES_PATH | grep -q 'buildenv/Dockerfile' ; then
echo "Dockerfile was modified"
echo "dockerfile-modified=true" >> $GITHUB_OUTPUT
else
echo "Dockerfile was not modified"
echo "dockerfile-modified=false" >> $GITHUB_OUTPUT
fi
check-docker-artifact-existence:
runs-on: ${{ inputs.os }}
# Trigger only if there are modification to the dockerfile and a temporary image should be used
outputs:
artifact-exists: ${{ steps.temporary-docker-exists.outputs.artifact-exists }}
artifact-run-id: ${{ steps.temporary-docker-exists.outputs.artifact-run-id }}
steps:
- name: Fetch artifacts JSON
run: |
curl https://api.github.com/repos/${{ github.repository }}/actions/artifacts?per_page=100&name=buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar > artifacts.json
cat artifacts.json
- name: Check artifact existence
id: temporary-docker-exists
run: |
echo "Running on ${{ inputs.arch }}"
# count how many artifacts match our branch & name
COUNT=$(cat artifacts.json \
| jq --arg branch "${{github.head_ref}}" --arg name "buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar" \
'[ .artifacts[]
| select(.workflow_run.head_branch==$branch and .name==$name)
] | length')
# export found=true/false (and the count if you like)
if [ "$COUNT" -gt 0 ]; then
echo "artifact-exists=true" >> $GITHUB_OUTPUT
echo "artifact-exists=true"
else
echo "artifact-exists=false" >> $GITHUB_OUTPUT
echo "artifact-run-id=none" >> $GITHUB_OUTPUT
echo "artifact-exists=false"
echo "artifact-run-id=none"
exit 0
fi
ARTIFACT_ID=$(cat artifacts.json | jq -r --arg branch "${{github.head_ref}}" --arg name "buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar" \
'
.artifacts
| map(select(.workflow_run.head_branch == $branch and .name == $name))
| max_by(.created_at)
| .workflow_run.id
' )
echo "artifact-run-id=$ARTIFACT_ID"
echo "artifact-run-id=$ARTIFACT_ID" >> $GITHUB_OUTPUT
build-image:
runs-on: ${{ inputs.os }}
needs: [check-dockerfile-modifications-with-last-commit]
if: ${{ needs.check-dockerfile-modifications-with-last-commit.outputs.dockerfile-modified == 'true' }}
outputs:
new-artifact-run-id: ${{ steps.get-new-run-id.outputs.new-artifact-run-id }}
permissions:
contents: read
attestations: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker metadata
id: dockermeta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKERIMAGE }}
tags: ${{ inputs.arch }}-latest
- name: Build docker image
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}:.build-tools/containers/buildenv"
push: false
tags: ${{ steps.dockermeta.outputs.tags }}
labels: ${{ steps.dockermeta.outputs.labels }}
build-args: ARCH=${{ inputs.arch }}
outputs: type=docker,dest=/tmp/buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar
- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar
path: /tmp/buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar
compression-level: 9
- name: Get the new run id
id: get-new-run-id
run: |
echo "new-artifact-run-id=${{ github.run_id }}" >> $GITHUB_OUTPUT
# Build TaskR and run tests on the locally built image
compile-and-test-local-custom-image:
runs-on: ${{ inputs.os }}
permissions:
pull-requests: write
needs:
[
build-image,
check-docker-artifact-existence,
check-dockerfile-modifications-with-base,
]
if: |
always() &&
(contains(needs.build-image.result, 'success') || contains(needs.build-image.result, 'skipped')) &&
contains(needs.check-dockerfile-modifications-with-base.outputs.dockerfile-modified , 'true')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Download new local docker image
if: ${{ needs.build-image.result == 'success' }}
uses: actions/download-artifact@v4
with:
name: buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar
path: ${{ runner.temp }}
run-id: ${{ needs.build-image.outputs.new-artifact-run-id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Download local docker image
if: ${{ needs.build-image.result == 'skipped' }}
uses: actions/download-artifact@v4
with:
name: buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar
path: ${{ runner.temp }}
run-id: ${{ needs.check-docker-artifact-existence.outputs.artifact-run-id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Load local image
run: |
docker load --input ${{ runner.temp }}/buildenv-${{ github.event.number }}-${{ inputs.arch }}.tar
docker image ls -a
- name: Start local container
run: |
docker run --name taskr --shm-size=1024M --privileged -v $PWD:/home/hicr/taskr -w /home/hicr/taskr -td ${{ env.DOCKERIMAGE }}:${{ inputs.arch }}-latest bash
- name: Dry-run compilation
run: docker exec -u hicr taskr bash -c "meson setup build -Dbuildtype=debug -Db_coverage=true -DdistributedEngines=mpi,lpf,none -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true -DexecutionStateType=nosv,boost -DprocessingUnitType=nosv,pthreads -DbuildPyTaskR=true -DbuildInstrumentation=false && meson compile -C build"
- name: Compile
run: docker exec -u hicr taskr bash -c "meson compile -C build"
- name: Running tests and creating coverage report
run: |
echo "Running Tests..."
docker exec -u hicr taskr bash -c "meson setup build -Dbuildtype=debug -Db_coverage=true -DdistributedEngines=mpi,none -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true -DexecutionStateType=nosv,boost -DprocessingUnitType=nosv,pthreads -DbuildPyTaskR=true -DbuildInstrumentation=false && meson compile -C build && meson test -C build"
echo "Creating coverage report..."
docker exec -u hicr taskr bash -c "ninja -C build coverage"
docker stop taskr
docker container rm taskr
- uses: actions/upload-artifact@v4
with:
name: build-local-${{ inputs.arch }}
path: build/
# Build TaskR and run tests and the remote image
compile-and-test-standard:
runs-on: ${{ inputs.os }}
needs: [check-dockerfile-modifications-with-base]
if: |
always() &&
contains(needs.check-dockerfile-modifications-with-base.outputs.dockerfile-modified , 'false')
container:
image: ghcr.io/algebraic-programming/taskr/buildenv:latest
options: --user hicr
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Dry-run compilation
run: source /home/hicr/.bashrc && meson setup build -Dbuildtype=debug -Db_coverage=true -DdistributedEngines=mpi,lpf,none -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true -DexecutionStateType=nosv,boost -DprocessingUnitType=nosv,pthreads -DbuildPyTaskR=true -DbuildInstrumentation=false && meson compile -C build
- name: Running tests and creating coverage report
shell: bash
env:
LD_PRELOAD: /usr/local/lib/libnosv.so
run: |
source /home/hicr/.bashrc
meson setup build -Dbuildtype=debug -Db_coverage=true -DdistributedEngines=mpi,none -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true -DexecutionStateType=nosv,boost -DprocessingUnitType=nosv,pthreads -DbuildPyTaskR=true -DbuildInstrumentation=false
meson compile -C build
meson test -C build
echo "Creating coverage report..."
ninja -C build coverage
- uses: actions/upload-artifact@v4
with:
name: build-standard-${{ inputs.arch }}
path: build/
analyze-coverage-report:
runs-on: ubuntu-latest
needs: [compile-and-test-standard, compile-and-test-local-custom-image]
permissions:
pull-requests: write
if: |
always() &&
(contains(needs.compile-and-test-standard.result, 'success') || contains(needs.compile-and-test-local-custom-image.result, 'success'))
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create temp build folder
run: |
mkdir ${{ runner.temp }}/build
- name: Download standard coverage file
if: ${{ needs.compile-and-test-standard.result == 'success' }}
uses: actions/download-artifact@v4
with:
name: build-standard-${{ inputs.arch }}
path: ${{ runner.temp }}/build
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Download local coverage file
if: ${{ needs.compile-and-test-local-custom-image.result == 'success' }}
uses: actions/download-artifact@v4
with:
name: build-local-${{ inputs.arch }}
path: ${{ runner.temp }}/build
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Copy build folder in repo
run: |
mv ${{ runner.temp }}/build .
- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: build/meson-logs/coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "60 80"
- name: Add arch to coverage file
run: |
sed -i '1i # Coverage ${{ inputs.arch }}' code-coverage-results.md
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' || github.event_name == 'pull_request'
with:
header: ${{ inputs.arch }}
message: |
Coverage for ${{ inputs.arch }}
recreate: true
path: code-coverage-results.md
- uses: actions/upload-artifact@v4
with:
name: meson-logs-${{ inputs.arch }}
path: build/meson-logs/