Skip to content

Commit 9b4ab96

Browse files
BuonOmorafiss
authored andcommitted
feat(ci): collect flaky results
Get one single table with every results from flaky tests.
1 parent e63c1a6 commit 9b4ab96

File tree

4 files changed

+120
-21
lines changed

4 files changed

+120
-21
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,51 @@ jobs:
2626
name: Test Results
2727
needs: [test]
2828
steps:
29-
- run: |
29+
- name: Check Success
30+
run: |
3031
result="${{ needs.test.result }}"
32+
3133
if [[ $result == "success" || $result == "skipped" ]]; then
34+
echo "All tests passed :taco:" >>$GITHUB_STEP_SUMMARY
3235
exit 0
3336
else
3437
exit 1
3538
fi
39+
- name: Download Reports
40+
if: failure()
41+
uses: actions/download-artifact@v4
42+
with:
43+
path: reports
44+
- name: Aggregate Reports
45+
if: failure()
46+
run: |
47+
cat <<EOF >>$GITHUB_STEP_SUMMARY
48+
# Failing Tests
49+
50+
<table>
51+
<thead>
52+
<tr>
53+
<th></th>
54+
<th>Test</th>
55+
</tr>
56+
</thead>
57+
<tbody>
58+
EOF
59+
60+
jq --slurp --raw-output '
61+
map(.failed_tests|map("\(.klass)#\(.NAME)")) | flatten | unique | sort | to_entries[]
62+
| "<tr><td><strong>\(.key)</strong></td><td>\(.value)</td></tr>"
63+
' reports/*/report.json >>$GITHUB_STEP_SUMMARY
64+
65+
cat <<EOF >>$GITHUB_STEP_SUMMARY
66+
</tbody>
67+
</table>
68+
EOF
69+
70+
echo >>$GITHUB_STEP_SUMMARY
71+
echo '```json' >>$GITHUB_STEP_SUMMARY
72+
jq --slurp --compact-output '.' reports/*/report.json >>$GITHUB_STEP_SUMMARY
73+
echo '```' >>$GITHUB_STEP_SUMMARY
3674
3775
test:
3876
runs-on: ubuntu-latest
@@ -42,11 +80,20 @@ jobs:
4280
# https://www.cockroachlabs.com/docs/releases/release-support-policy
4381
crdb: [v24.3, v25.1, v25.2, v25.3]
4482
ruby: ["3.4"]
45-
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }}
83+
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
4684
steps:
4785
- name: Set Up Actions
4886
uses: actions/checkout@v4
4987
- uses: ./.github/actions/test-runner
88+
id: test
5089
with:
5190
crdb: ${{ matrix.crdb }}
5291
ruby: ${{ matrix.ruby }}
92+
env:
93+
JSON_REPORTER: "report.json"
94+
- name: Upload Report
95+
if: ${{ failure() && steps.test.conclusion == 'failure' }}
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: report-${{ matrix.crdb }}-${{ matrix.ruby }}
99+
path: report.json

.github/workflows/flaky.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ jobs:
5353
ruby: ${{ fromJSON(needs.prepare-matrix.outputs.ruby) }}
5454
seed: ${{ fromJSON(needs.prepare-matrix.outputs.seeds) }}
5555
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }} seed=${{ matrix.seed }})
56-
env:
57-
SEED: ${{ matrix.seed }}
5856
steps:
5957
- name: Set Up Actions
6058
uses: actions/checkout@v4
@@ -64,6 +62,52 @@ jobs:
6462
crdb: ${{ matrix.crdb }}
6563
ruby: ${{ matrix.ruby }}
6664
TESTOPTS: --fail-fast
67-
- name: Bisect failing test
65+
env:
66+
JSON_REPORTER: "report.json"
67+
SEED: ${{ matrix.seed }}
68+
- name: Upload Report
6869
if: ${{ failure() && steps.test.conclusion == 'failure' }}
69-
run: bin/minitest_bisect ${{ matrix.seed }}
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: report-${{ matrix.crdb }}-${{ matrix.ruby }}-${{ matrix.seed }}
73+
path: report.json
74+
collect:
75+
if: failure()
76+
needs: test
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Download Reports
80+
uses: actions/download-artifact@v4
81+
with:
82+
path: reports
83+
- name: Aggregate Reports
84+
run: |
85+
cat <<EOF >> $GITHUB_STEP_SUMMARY
86+
# Failing Tests
87+
88+
<table>
89+
<thead>
90+
<tr>
91+
<th>Seed</th>
92+
<th>Time</th>
93+
<th>Failure</th>
94+
</tr>
95+
</thead>
96+
<tbody>
97+
EOF
98+
99+
jq --slurp --raw-output '
100+
sort_by(.total_time)[]
101+
| {seed, time: .total_time | strftime("%H:%M:%S"), failure: .failed_tests[0].NAME }
102+
| "<tr><td>\(.seed)</td><td>\(.time)</td><td>\(.failure)</td></tr>"
103+
' reports/*/report.json >> $GITHUB_STEP_SUMMARY
104+
105+
106+
cat <<EOF >> $GITHUB_STEP_SUMMARY
107+
</tbody>
108+
</table>
109+
EOF
110+
echo >> $GITHUB_STEP_SUMMARY
111+
echo '```json' >> $GITHUB_STEP_SUMMARY
112+
jq --slurp --compact-output '.' reports/*/report.json >> $GITHUB_STEP_SUMMARY
113+
echo '```' >> $GITHUB_STEP_SUMMARY

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ group :development, :test do
5656
gem "debug"
5757
gem "minitest-bisect", github: "BuonOmo/minitest-bisect", branch: "main"
5858
gem "minitest-excludes", "~> 2.0.1"
59-
gem "minitest-github_action_reporter", github: "BuonOmo/minitest-github_action_reporter", require: "minitest/github_action_reporter_plugin"
6059
gem "ostruct", "~> 0.6"
6160

6261
# Gems used for tests meta-programming.

test/cases/helper_cockroachdb.rb

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,33 @@ def with_postgresql_datetime_type(type)
169169

170170
ActiveRecord::TestCase.prepend(SetDatetimeInCockroachDBAdapter)
171171

172-
if ENV["GITHUB_ACTIONS"]
173-
require "minitest/github_action_reporter"
174-
172+
if ENV["JSON_REPORTER"]
173+
puts "Generating JSON report: #{ENV["JSON_REPORTER"]}"
175174
module Minitest
176-
module GithubActionReporterExt
177-
def gh_link(loc)
178-
return super unless loc.include?("/gems/")
179-
180-
path, _, line = loc[%r(/(?:test|spec|lib)/.*)][1..].rpartition(":")
181-
182-
rails_version = "v#{ActiveRecord::VERSION::STRING}"
183-
"#{ENV["GITHUB_SERVER_URL"]}/rails/rails/blob/#{rails_version}/activerecord/#{path}#L#{line}"
184-
rescue
185-
warn "Failed to generate link for #{loc}"
175+
class JSONReporter < StatisticsReporter
176+
def report
186177
super
178+
io.write(
179+
{
180+
seed: Minitest.seed,
181+
assertions: assertions,
182+
count: count,
183+
failed_tests: results,
184+
total_time: total_time,
185+
failures: failures,
186+
errors: errors,
187+
warnings: warnings,
188+
skips: skips,
189+
}.to_json
190+
)
187191
end
188192
end
189-
GithubActionReporter.prepend(GithubActionReporterExt)
193+
194+
def self.plugin_json_reporter_init(*)
195+
reporter << JSONReporter.new(File.open(ENV["JSON_REPORTER"], "w"))
196+
end
197+
198+
self.extensions << "json_reporter"
190199
end
191200
end
192201

0 commit comments

Comments
 (0)