Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ jobs:
| time | Test execution time [ms] |
| url | Check run URL |
| url_html | Check run URL HTML |
| slug_prefix| Random anchor links slug prefix generated for the summary headers |

## Supported formats

Expand Down
28 changes: 28 additions & 0 deletions __tests__/utils/slugger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {DEFAULT_OPTIONS} from '../../src/report/get-report.js'
import {slug} from '../../src/utils/slugger.js'

describe('slugger', () => {
it('adds prefix from report options to generated slug', () => {
const result = slug('r0s1', {
...DEFAULT_OPTIONS,
slugPrefix: 'prefix-'
})

expect(result).toEqual({
id: 'user-content-prefix-r0s1',
link: '#user-content-prefix-r0s1'
})
})

it('sanitizes custom prefix using existing slug normalization', () => {
const result = slug('r0', {
...DEFAULT_OPTIONS,
slugPrefix: ' my /custom_prefix?.'
})

expect(result).toEqual({
id: 'user-content-my-customprefix-r0',
link: '#user-content-my-customprefix-r0'
})
})
})
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ outputs:
description: Check run URL
url_html:
description: Check run URL HTML
slug_prefix:
description: Random prefix added to generated report anchor slugs for this action run
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down
12 changes: 10 additions & 2 deletions dist/index.js

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

7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {GitHub} from '@actions/github/lib/utils'
import {randomBytes} from 'node:crypto'

import {ArtifactProvider} from './input-providers/artifact-provider.js'
import {LocalFileProvider} from './input-providers/local-file-provider.js'
Expand Down Expand Up @@ -49,6 +50,7 @@ class TestReporter {
readonly workDirInput = core.getInput('working-directory', {required: false})
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
readonly useActionsSummary = core.getInput('use-actions-summary', {required: false}) === 'true'
readonly slugPrefix = `tr-${randomBytes(4).toString('base64url')}-`
readonly badgeTitle = core.getInput('badge-title', {required: false})
readonly reportTitle = core.getInput('report-title', {required: false})
readonly collapsed = core.getInput('collapsed', {required: false}) as 'auto' | 'always' | 'never'
Expand Down Expand Up @@ -144,6 +146,7 @@ class TestReporter {
core.setOutput('failed', failed)
core.setOutput('skipped', skipped)
core.setOutput('time', time)
core.setOutput('slug_prefix', this.slugPrefix)

if (this.failOnError && isFailed) {
core.setFailed(`Failed test were found and 'fail-on-error' option is set to ${this.failOnError}`)
Expand Down Expand Up @@ -174,7 +177,7 @@ class TestReporter {
}
}

const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle, reportTitle, collapsed} = this
const {listSuites, listTests, slugPrefix, onlySummary, useActionsSummary, badgeTitle, reportTitle, collapsed} = this

const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
Expand All @@ -188,6 +191,7 @@ class TestReporter {
{
listSuites,
listTests,
slugPrefix,
baseUrl,
onlySummary,
useActionsSummary,
Expand Down Expand Up @@ -219,6 +223,7 @@ class TestReporter {
const summary = getReport(results, {
listSuites,
listTests,
slugPrefix,
baseUrl,
onlySummary,
useActionsSummary,
Expand Down
2 changes: 2 additions & 0 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const MAX_ACTIONS_SUMMARY_LENGTH = 1048576
export interface ReportOptions {
listSuites: 'all' | 'failed' | 'none'
listTests: 'all' | 'failed' | 'none'
slugPrefix: string
baseUrl: string
onlySummary: boolean
useActionsSummary: boolean
Expand All @@ -22,6 +23,7 @@ export interface ReportOptions {
export const DEFAULT_OPTIONS: ReportOptions = {
listSuites: 'all',
listTests: 'all',
slugPrefix: '',
baseUrl: '',
onlySummary: false,
useActionsSummary: true,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/slugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {ReportOptions} from '../report/get-report.js'

export function slug(name: string, options: ReportOptions): {id: string; link: string} {
const slugId = name
const slugId = `${options.slugPrefix}${name}`
.trim()
.replace(/_/g, '')
.replace(/[./\\]/g, '-')
Expand Down