Skip to content

Commit

Permalink
👷 Let Github report flaky tests
Browse files Browse the repository at this point in the history
Added an action that processes the flaky test log file, so that the
annotations can be logged in the Job summaries.
  • Loading branch information
sergei-maertens committed Apr 4, 2024
1 parent 2b12c84 commit 2701593
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/actions/report-flaky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
12 changes: 12 additions & 0 deletions .github/actions/report-flaky/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

name: Report flaky tests
description: Parses log file for flaky tests and adds annotations for them
inputs:
logFile:
description: Log file containing the flaky test logs
required: true
default: 'log/flaky.jsonl'
runs:
using: 'node20'
main: 'report_flaky.js'
69 changes: 69 additions & 0 deletions .github/actions/report-flaky/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .github/actions/report-flaky/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "report-flaky",
"version": "1.0.0",
"description": "Flaky test reporter action",
"main": "report_flaky.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.1"
}
}
26 changes: 26 additions & 0 deletions .github/actions/report-flaky/report_flaky.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Taken from: https://nodejs.org/api/readline.html#readline_example_read_file_stream_line_by_line
const fs = require('node:fs');
const readline = require('node:readline');

const core = require('@actions/core');

const logFilePath = core.getInput('logFile');

async function emitAnnotations() {
const fileStream = fs.createReadStream(logFilePath);

const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
});
// Note: we use the crlfDelay option to recognize all instances of CR LF
// ('\r\n') in input.txt as a single line break.

for await (const line of rl) {
// each line is expected to be valid JSON
const logRecord = JSON.parse(line);
core.warning(logRecord.msg, {file: logRecord.file, startLine: logRecord.line});
}
}

emitAnnotations();
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ jobs:
DB_PASSWORD: ''
DEBUG: 'true'

- run: npm ci
working-directory: .github/actions/report-flaky
- uses: ./.github/actions/report-flaky

- name: Run JS tests
run: npm test

Expand Down Expand Up @@ -180,6 +184,10 @@ jobs:
DB_PASSWORD: ''
DEBUG: 'true'

- run: npm ci
working-directory: .github/actions/report-flaky
- uses: ./.github/actions/report-flaky

e2etests:
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 0 additions & 2 deletions src/openforms/formio/tests/test_api_fileupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ def do_upload() -> str:

session_uuids = set(self.client.session[UPLOADS_SESSION_KEY])

log_flaky()

# Flaky test - provide some debug output
if session_uuids != uuids:
log_flaky()
Expand Down

0 comments on commit 2701593

Please sign in to comment.