-
Notifications
You must be signed in to change notification settings - Fork 16
326 lines (268 loc) · 11.2 KB
/
code-coverage-deploy.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
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
name: "Code and Documentation Coverage (Deploy)"
# see https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
on:
workflow_run:
workflows: ["Code and Documentation Coverage (PR)"]
types:
- completed
# see https://github.com/JamesIves/github-pages-deploy-action/tree/dev
permissions:
contents: write
env:
rust_release: nightly
jobs:
deploy-coverage:
name: "Info: Code Coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set shas
id: sha
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const {data: callee_run } = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
console.log(callee_run);
// from manual inspection in jq, seems to hold head.sha for PR, not
// whatever GITHUB_SHA is.
return callee_run.head_sha;
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
name: code-coverage-${{ steps.sha.outputs.result }}
workflow: code-coverage.yml
path: ./deploy
- name: Deploy to Github Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./deploy
target-folder: "coverage/${{ steps.sha.outputs.result }}"
branch: gh-pages
commit-message: "Actions: Code Coverage for ${{ steps.sha.outputs.result }}"
indexes:
needs: deploy-coverage
name: "Regenerate indexes for coverage"
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Checkout the pages repository
uses: actions/checkout@v2
with:
ref: "gh-pages"
path: "pages"
- name: Set shas
id: sha
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const {data: callee_run } = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
console.log(callee_run);
return callee_run.head_sha;
- name: "Generate indexes"
run: |
./tools/ci/genindex.py pages/coverage/
- uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./pages/coverage/
target-folder: ./coverage/
branch: gh-pages
commit-message: "Actions: Update coverage indexes"
comment:
permissions: write-all
needs: deploy-coverage
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
target
solvers/minion/vendor
solvers/chuffed/vendor
key: ${{ runner.os }}-${{ env.rust_release }}-${{ github.event.repository.updated_at }}
restore-keys: ${{ runner.os }}-${{ env.rust_release }}
- name: Set shas
id: sha
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const {data: callee_run } = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
console.log(callee_run);
// from manual inspection in jq, seems to hold head.sha for PR, not
// whatever GITHUB_SHA is.
return callee_run.head_sha;
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
name: code-coverage-${{ steps.sha.outputs.result }}
workflow: code-coverage.yml
path: ./deploy
- name: Get PR number
id: prnum
run: |
echo "num=$(cat deploy/prnumber)" > $GITHUB_OUTPUT
- name: Retrieve list of artifacts for the PR
id: find_artifacts
uses: actions/github-script@v6
with:
script: |
const prNum = process.env.num;
const artifacts = await github.rest.actions.listArtifactsForRepo({
owner: context.repo.owner,
repo: context.repo.repo
});
// Filter artifacts by PR number in their name
const artifactList = artifacts.data.artifacts.filter(artifact => artifact.name.includes(`coverage-${prNum}-`));
return artifactList.map((artifact) => ({
id: artifact.id,
name: artifact.name,
created_at: artifact.created_at
}));
# WARNING: Artifacts are deleted after 90 days (or per configured retention policy)
- name: Find previous artifact
id: previous-artifact
if: steps.find_artifacts.outputs.result != '[]'
uses: actions/github-script@v6
with:
result-encoding: string
script: |
// parse the output from the previous step into a JSON array
previous_artifacts = ${{ fromJson(steps.find_artifacts.outputs.result) }}
// assuming filtered and sorted the previous_artifacts by creation date in descending order
if (previous_artifacts.length > 1) {
// get the second latest artifact (since the latest would be the current one)
return previous_artifacts[1].id
}
- run: |
echo "previous_artifact_id=${{steps.previous-artifact.outputs.result}}" >> $GITHUB_ENV
- name: Install rust ${{ env.rust_release }}
run: rustup update ${{ env.rust_release }} && rustup default ${{ env.rust_release }}
- name: Generate lcov summary for main and pr
continue-on-error: true
id: lcov
run: |
sudo apt-get install -y lcov
wget https://${{github.repository_owner}}.github.io/conjure-oxide/coverage/main/lcov.info
lcov --summary lcov.info > cov.txt
echo "main<<EOFABC" >> $GITHUB_OUTPUT
echo "$(cat cov.txt | tail -n +3)" >> $GITHUB_OUTPUT
echo 'EOFABC' >> $GITHUB_OUTPUT
lcov --summary ./deploy/lcov.info > cov.txt
echo "pr<<EOFABC" >> $GITHUB_OUTPUT
echo "$(cat cov.txt | tail -n +3)" >> $GITHUB_OUTPUT
echo 'EOFABC' >> $GITHUB_OUTPUT
- name: Get doc-coverage for main and pr
id: doccov
run: |
wget https://${{github.repository_owner}}.github.io/conjure-oxide/coverage/main/doc-coverage.txt
echo "main<<EOFABC" >> $GITHUB_OUTPUT
echo "$(cat doc-coverage.txt)" >> $GITHUB_OUTPUT
echo 'EOFABC' >> $GITHUB_OUTPUT
echo "pr<<EOFABC" >> $GITHUB_OUTPUT
echo "$(cat ./deploy/doc-coverage.txt)" >> $GITHUB_OUTPUT
echo 'EOFABC' >> $GITHUB_OUTPUT
- name: Find coverage comment
uses: peter-evans/find-comment@v1
continue-on-error: true
id: fc
with:
issue-number: ${{steps.prnum.outputs.num}}
comment-author: "github-actions[bot]"
body-includes: "## Documentation Coverage"
- name: Delete coverage comment if it exists
if: steps.fc.outputs.comment-id != ''
uses: actions/github-script@v6
with:
script: |
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.fc.outputs.comment-id }}
})
- name: Download the previous lcov.info (historical) file
uses: actions/download-artifact@v2
with: |
name: code-coverage-${{ env.num }}-${{ env.previous_artifact_id }}
path: ./tools/code-coverage-diff/deploy-prev
# this will be used for future visualizations in the coverage report (requiring external python libs)
- name: Install python dependencies
run: |
pip install -r tools/code-coverage-diff/requirements.txt
- name: Calculate current coverage difference PR <> main
id: coveragediff
run: |
# pipeline lcov relevant stats to python script
python ./tools/code-coverage-diff/calculate_coverage_difference.py ${{ steps.lcov.outputs.main }} ${{ steps.lcov.outputs.pr }} > ./tools/code-coverage-diff/lcov/coverage_diff.txt
# store into environment variable
echo "diff<<EOFABC" >> $GITHUB_OUTPUT
cat ./tools/code-coverage-diff/lcov/coverage_diff.txt >> $GITHUB_ENV
echo 'EOFABC' >> $GITHUB_OUTPUT
# create summary of previous (historical) lcov summary for main and pr
lcov --summary ./tools/code-coverage-diff/deploy-prev/code-coverage-${{ env.num }}-${{ env.previous_artifact_id }} > historical_coverage_lcov.txt
echo "hist_main_summary<<EOFABC" >> $GITHUB_OUTPUT
echo "$(cat historical_coverage_lcov.txt | tail -n +3)" >> $GITHUB_OUTPUT
echo 'EOFABC' >> $GITHUB_OUTPUT
- name: Calculate coverage difference with previous historical lcov artifact
id: historicalcoveragediff
run: |
# call python script to compare historical previous main coverage with current main coverage
python ./tools/code-coverage-diff/calculate_coverage_difference.py ${{ steps.lcov.outputs.main }} ${{ steps.coveragediff.outputs.hist_main_summary }} > ./tools/code-coverage-diff/lcov/hist_coverage_diff.txt
# store into output variable for comment display
echo "hist_diff<<EOFABC" >> $GITHUB_OUTPUT
cat ./tools/code-coverage-diff/lcov/hist_coverage_diff.txt >> $GITHUB_ENV
echo 'EOFABC' >> $GITHUB_OUTPUT
- name: Create coverage comment
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ steps.prnum.outputs.num }}
body: |
## Code and Documentation Coverage Report
### Documentation Coverage
<details>
<summary>Click to view documentation coverage for this PR</summary>
```
${{ steps.doccov.outputs.pr }}
```
</details>
<details>
<summary>Click to view documentation coverage for main</summary>
```
${{ steps.doccov.outputs.main }}
```
</details>
### Code Coverage Summary
**This PR**: [Detailed Report](https://${{ github.repository_owner }}.github.io/conjure-oxide/coverage/${{ steps.sha.outputs.result }}/index.html)
```
${{ steps.lcov.outputs.pr }}
```
**Main**: [Detailed Report](https://${{ github.repository_owner }}.github.io/conjure-oxide/coverage/main/index.html)
```
${{ steps.lcov.outputs.main }}
```
### Coverage Main & PR Coverage Change
```diff
${{ steps.coveragediff.outputs.diff }}
```
### Previous Main Coverage Change
```diff
${{ steps.historicalcoveragediff.outputs.hist_diff }}
```