diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 6b150b85..88684a73 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -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' diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml new file mode 100644 index 00000000..0cf5606c --- /dev/null +++ b/.github/workflows/test-report.yml @@ -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 diff --git a/test/regression/lib.js b/test/regression/lib.js index 17e76684..fad2888c 100644 --- a/test/regression/lib.js +++ b/test/regression/lib.js @@ -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} + */ +export async function getCommitRef() { + return new Promise((res, rej) => { + exec('git rev-parse HEAD', (err, stdout) => { + if (err) { + rej(err); + return; + } + + res(stdout.trim()); + }); + }); +} diff --git a/test/regression/regression-io.js b/test/regression/regression-io.js index b25724ff..c7246d35 100644 --- a/test/regression/regression-io.js +++ b/test/regression/regression-io.js @@ -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>} */ -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); }