Skip to content

Commit 6036436

Browse files
committed
fix: populate previous reports with info about the run they came from
1 parent 646f98c commit 6036436

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/ctrf/enrichers.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GitHubContext } from '../types'
22
import { Report } from 'ctrf'
3+
import * as core from '@actions/core'
34

45
/**
56
* Enriches the current CTRF report with details from the GitHub Actions context.
@@ -38,6 +39,32 @@ export function enrichCurrentReportWithRunDetails(
3839
return extendedReport
3940
}
4041

42+
/**
43+
* Enriches a CTRF report with details from a GitHub Actions workflow run.
44+
*
45+
* @param report - The CTRF report to enrich.
46+
* @param run - The GitHub Actions workflow run details.
47+
* @returns The updated CTRF report with enriched run details.
48+
*/
49+
export function enrichPreviousReportWithRunDetails(
50+
report: Report,
51+
run: import('@octokit/openapi-types').components['schemas']['workflow-run']
52+
): Report {
53+
const extendedReport = report
54+
55+
core.debug(`enriching ${run.id} / ${run.html_url}`)
56+
57+
extendedReport.results.environment = extendedReport.results.environment ?? {}
58+
59+
extendedReport.results.environment.buildId = run.id.toString()
60+
extendedReport.results.environment.buildNumber = run.run_number.toString()
61+
extendedReport.results.environment.buildUrl = run.html_url
62+
extendedReport.results.environment.buildName =
63+
run.name == null ? undefined : run.name
64+
65+
return extendedReport
66+
}
67+
4168
/**
4269
* Removes the test.extra.durations property from each test if it exists.
4370
*

src/ctrf/metrics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '../client/github'
88
import { isMatchingWorkflowRun } from '../github'
99
import { Inputs, GitHubContext } from '../types'
10+
import { enrichPreviousReportWithRunDetails } from './enrichers'
1011
import { enrichReportWithInsights } from 'ctrf'
1112
import type { Report } from 'ctrf'
1213
import { storePreviousResults } from './previous-results'
@@ -100,10 +101,9 @@ export async function processPreviousResultsAndMetrics(
100101
if (isMatching) {
101102
core.debug(`Attempting to process artifacts for run ${run.id}`)
102103
try {
103-
const artifacts = await processArtifactsFromRun(
104-
run,
105-
inputs.artifactName
106-
)
104+
const artifacts = (
105+
await processArtifactsFromRun(run, inputs.artifactName)
106+
).map(artifact => enrichPreviousReportWithRunDetails(artifact, run))
107107
core.debug(
108108
`Retrieved ${artifacts.length} artifacts from run ${run.id}`
109109
)

0 commit comments

Comments
 (0)