mirror of
https://github.com/svg/svgo.git
synced 2026-01-27 07:02:06 +03:00
ci: save test reports to artifacts (#2189)
This commit is contained in:
17
.github/workflows/codeql.yml
vendored
17
.github/workflows/codeql.yml
vendored
@@ -13,29 +13,20 @@ on:
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
steps:
|
||||
- name: Clone repository
|
||||
uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v4
|
||||
- uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: 'javascript'
|
||||
queries: +security-and-quality
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v4
|
||||
- uses: github/codeql-action/autobuild@v4
|
||||
- uses: github/codeql-action/analyze@v4
|
||||
with:
|
||||
category: '/language:javascript'
|
||||
|
||||
29
.github/workflows/test-report.yml
vendored
Normal file
29
.github/workflows/test-report.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: Test Report
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test-report:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- run: corepack enable
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 24
|
||||
cache: yarn
|
||||
- run: yarn install
|
||||
- run: yarn playwright install --with-deps chromium
|
||||
- run: yarn test:regression
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: svgo-test-report
|
||||
path: /tmp/svgo.${{ github.sha }}/svgo-test-report.json
|
||||
if-no-files-found: error
|
||||
@@ -2,6 +2,7 @@
|
||||
* @fileoverview Utilities to manage manage regression tests.
|
||||
*/
|
||||
|
||||
import { exec } from 'node:child_process';
|
||||
import crypto from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs/promises';
|
||||
@@ -53,7 +54,7 @@ export async function printReport(report) {
|
||||
|
||||
▶ Metrics
|
||||
Bytes Saved: ${bytesToHumanReadable(report.metrics.bytesSaved)}
|
||||
Time Taken: ${secsToHumanReadable(/** @type {number} */ (report.metrics.timeTakenSecs))}
|
||||
Time Taken: ${secsToHumanReadable(report.metrics.timeTakenSecs)}
|
||||
Peak Memory Alloc: ${bytesToHumanReadable(report.metrics.peakMemoryAlloc, 'KiB')}${
|
||||
shouldHaveMatched.length !== 0
|
||||
? picocolors.red(
|
||||
@@ -134,3 +135,19 @@ export function toBulletPointList(arr, bullet = '*') {
|
||||
export function pathToPosix(filepath) {
|
||||
return filepath.replaceAll(path.sep, path.posix.sep);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export async function getCommitRef() {
|
||||
return new Promise((res, rej) => {
|
||||
exec('git rev-parse HEAD', (err, stdout) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
|
||||
res(stdout.trim());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { getCommitRef } from './lib.js';
|
||||
|
||||
/**
|
||||
* @typedef Files
|
||||
@@ -40,7 +41,9 @@ import path from 'node:path';
|
||||
* with POSIX file separators.
|
||||
*/
|
||||
|
||||
export const TEMP_DIR_PATH = path.join(tmpdir(), 'svgo.2a5HM7nlGG');
|
||||
const GIT_COMMIT_REF = await getCommitRef();
|
||||
|
||||
export const TEMP_DIR_PATH = path.join(tmpdir(), `svgo.${GIT_COMMIT_REF}`);
|
||||
export const REGRESSION_FIXTURES_PATH = path.join(
|
||||
TEMP_DIR_PATH,
|
||||
'regression-fixtures',
|
||||
@@ -80,8 +83,8 @@ export async function writeReport(data) {
|
||||
/**
|
||||
* @returns {Promise<Partial<TestReport>>}
|
||||
*/
|
||||
export async function readReport() {
|
||||
const text = await fs.readFile(OPTIMIZATION_REPORT_PATH, 'utf-8');
|
||||
export async function readReport(path = OPTIMIZATION_REPORT_PATH) {
|
||||
const text = await fs.readFile(path, 'utf-8');
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user