Skip to content
This repository was archived by the owner on Sep 21, 2024. It is now read-only.

Commit be0786a

Browse files
committed
chore: Report flakes in CI
1 parent 3a17db9 commit be0786a

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
target:
5+
required: true
6+
type: string
7+
secrets:
8+
GITHUB_TOKEN:
9+
required: true
10+
11+
name: 'Workflow Analysis'
12+
13+
jobs:
14+
report-test-flakes:
15+
name: 'Report test flakes'
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
steps:
21+
- uses: actions/download-artifact@v3
22+
- name: Parse test results
23+
run: |
24+
RESULTS_PATH="./test-results-${{ inputs.target }}/test-results.log"
25+
26+
csplit -q "$RESULTS_PATH" %^------------%
27+
28+
if [[ -f "./xx00" ]]; then
29+
SUMMARY=`tail ./xx00 -n+2`
30+
31+
if [[ "$SUMMARY" =~ 'FLAKY' ]]; then
32+
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
33+
{
34+
echo "summary<<EOF"
35+
echo "$SUMMARY"
36+
echo "EOF"
37+
} >> $GITHUB_OUTPUT
38+
fi
39+
fi
40+
- name: Report flakes
41+
uses: actions/github-script@v6
42+
with:
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
script: |
45+
const { data: comments } = await github.rest.issues.listComments({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
issue_number: context.issue.number,
49+
});
50+
51+
const flakeyTestsHeader = 'Test flake analysis: ${{ inputs.target }}';
52+
const existingComment = comments.find(comment => {
53+
return comment.user.type === 'Bot' && comment.body.includes(flakeyTestsHeader)
54+
});
55+
56+
let body;
57+
58+
if (${{ steps['Parse test results'].outputs.summary }}) {
59+
body = `${flakeyTestsHeader}
60+
61+
\`\`\`shell
62+
${{ steps['Parse test results'].outputs.summary }}
63+
\`\`\`
64+
`;
65+
} else {
66+
body = `${flakeyTestsHeader}
67+
68+
No flakes detected!
69+
`;
70+
}
71+
72+
if (existingComment) {
73+
github.rest.issues.updateComment({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
comment_id: existingComment.id,
77+
body
78+
})
79+
} else {
80+
github.rest.issues.createComment({
81+
issue_number: context.issue.number,
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
body
85+
})
86+
}

.github/workflows/run_test_suite.yaml

+14-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
ipfs_version: v0.17.0
8080
run_daemon: true
8181
- name: 'Run Rust native target tests'
82-
run: cargo nextest run --features test-kubo,headers --retries 5 --color always
82+
run: cargo nextest run --features test-kubo,headers --retries 5 --color always 2>&1 | tee test-results.log
8383
env:
8484
NOOSPHERE_LOG: academic
8585

@@ -106,9 +106,21 @@ jobs:
106106
ipfs_version: v0.17.0
107107
run_daemon: true
108108
- name: 'Run Rust native target tests'
109-
run: cargo nextest run --features test-kubo,headers --retries 5 --color always
109+
run: cargo nextest run --features test-kubo,headers --retries 5 --color always 2>&1 | tee test-results.log
110110
env:
111111
NOOSPHERE_LOG: academic
112+
- uses: actions/upload-artifact@v3
113+
with:
114+
name: test-results-linux
115+
path: ./test-results.log
116+
117+
report-test-flakes:
118+
name: 'Report test flakes (Linux)'
119+
needs: ['run-test-suite-linux']
120+
uses: ./.github/workflows/report_test_flakes.yaml
121+
secrets: inherit
122+
with:
123+
target: 'linux'
112124

113125
run-test-suite-linux-rocksdb:
114126
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)