Skip to content

Commit 79a2167

Browse files
authored
ci: save test reports to artifacts (#2189)
1 parent 0ae52a0 commit 79a2167

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

.github/workflows/codeql.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,20 @@ on:
1313

1414
jobs:
1515
analyze:
16-
name: Analyze
1716
runs-on: ubuntu-latest
1817
permissions:
1918
actions: read
2019
contents: read
2120
security-events: write
22-
2321
steps:
24-
- name: Clone repository
25-
uses: actions/checkout@v6
22+
- uses: actions/checkout@v6
2623
with:
2724
persist-credentials: false
28-
29-
- name: Initialize CodeQL
30-
uses: github/codeql-action/init@v4
25+
- uses: github/codeql-action/init@v4
3126
with:
3227
languages: 'javascript'
3328
queries: +security-and-quality
34-
35-
- name: Autobuild
36-
uses: github/codeql-action/autobuild@v4
37-
38-
- name: Perform CodeQL Analysis
39-
uses: github/codeql-action/analyze@v4
29+
- uses: github/codeql-action/autobuild@v4
30+
- uses: github/codeql-action/analyze@v4
4031
with:
4132
category: '/language:javascript'

.github/workflows/test-report.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Test Report
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test-report:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v5
17+
- run: corepack enable
18+
- uses: actions/setup-node@v6
19+
with:
20+
node-version: 24
21+
cache: yarn
22+
- run: yarn install
23+
- run: yarn playwright install --with-deps chromium
24+
- run: yarn test:regression
25+
- uses: actions/upload-artifact@v4
26+
with:
27+
name: svgo-test-report
28+
path: /tmp/svgo.${{ github.sha }}/svgo-test-report.json
29+
if-no-files-found: error

test/regression/lib.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @fileoverview Utilities to manage manage regression tests.
33
*/
44

5+
import { exec } from 'node:child_process';
56
import crypto from 'node:crypto';
67
import path from 'node:path';
78
import fs from 'node:fs/promises';
@@ -53,7 +54,7 @@ export async function printReport(report) {
5354
5455
▶ Metrics
5556
Bytes Saved: ${bytesToHumanReadable(report.metrics.bytesSaved)}
56-
Time Taken: ${secsToHumanReadable(/** @type {number} */ (report.metrics.timeTakenSecs))}
57+
Time Taken: ${secsToHumanReadable(report.metrics.timeTakenSecs)}
5758
Peak Memory Alloc: ${bytesToHumanReadable(report.metrics.peakMemoryAlloc, 'KiB')}${
5859
shouldHaveMatched.length !== 0
5960
? picocolors.red(
@@ -134,3 +135,19 @@ export function toBulletPointList(arr, bullet = '*') {
134135
export function pathToPosix(filepath) {
135136
return filepath.replaceAll(path.sep, path.posix.sep);
136137
}
138+
139+
/**
140+
* @returns {Promise<string>}
141+
*/
142+
export async function getCommitRef() {
143+
return new Promise((res, rej) => {
144+
exec('git rev-parse HEAD', (err, stdout) => {
145+
if (err) {
146+
rej(err);
147+
return;
148+
}
149+
150+
res(stdout.trim());
151+
});
152+
});
153+
}

test/regression/regression-io.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs/promises';
22
import { tmpdir } from 'node:os';
33
import path from 'node:path';
4+
import { getCommitRef } from './lib.js';
45

56
/**
67
* @typedef Files
@@ -40,7 +41,9 @@ import path from 'node:path';
4041
* with POSIX file separators.
4142
*/
4243

43-
export const TEMP_DIR_PATH = path.join(tmpdir(), 'svgo.2a5HM7nlGG');
44+
const GIT_COMMIT_REF = await getCommitRef();
45+
46+
export const TEMP_DIR_PATH = path.join(tmpdir(), `svgo.${GIT_COMMIT_REF}`);
4447
export const REGRESSION_FIXTURES_PATH = path.join(
4548
TEMP_DIR_PATH,
4649
'regression-fixtures',
@@ -80,8 +83,8 @@ export async function writeReport(data) {
8083
/**
8184
* @returns {Promise<Partial<TestReport>>}
8285
*/
83-
export async function readReport() {
84-
const text = await fs.readFile(OPTIMIZATION_REPORT_PATH, 'utf-8');
86+
export async function readReport(path = OPTIMIZATION_REPORT_PATH) {
87+
const text = await fs.readFile(path, 'utf-8');
8588
return JSON.parse(text);
8689
}
8790

0 commit comments

Comments
 (0)