Skip to content

Commit fbdbbca

Browse files
author
casianaoprut
committed
modified summary action to receive a md and a html file
1 parent 41e4ae2 commit fbdbbca

File tree

3 files changed

+64
-22
lines changed

3 files changed

+64
-22
lines changed

src/model/Action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export interface Action {
88
export interface DefaultAction extends Action {
99
with?: WithAction;
1010
produces?: Map<string, string>
11-
summaryFile?: string;
11+
summaryMdFile?: string;
12+
summaryHtmlFile?: string;
1213
}
1314

1415
export interface WithAction {

src/parser/instrument-parser.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export function parseInstrument(instrumentsDirPath: string, instrumentDir: strin
3838
initVariableProvider()
3939
const instrumentPath = path.resolve(instrumentsDirPath, instrumentDir)
4040
missionContext.addVariable(INSTRUMENT_NAME, file.name)
41+
missionContext.addVariable(`${file.name}SummaryMd`, 'null')
42+
missionContext.addVariable(`${file.name}SummaryHtml`, 'null')
4143
missionContext.addVariable(INSTRUMENT_DIR_NAME, instrumentDir)
4244
missionContext.addVariable(INSTRUMENT_PATH, instrumentPath)
4345
missionContext.addVariable(INSTRUMENT_RESULTS, path.resolve(<string>missionContext.getVariable(RESULTS_UNPACK_DIR), file.name))
@@ -103,21 +105,34 @@ function parseCommands(commandsObject: any, instrumentKey: string, actionKey: st
103105
}
104106

105107
function parseDefaultAction(defaultActionObject: any, instrumentKey: string, actionKey: string): DefaultAction {
108+
if (defaultActionObject.summaryFile !== undefined)
109+
throw new Error(`Invalid field 'summaryFile' in action '${actionKey}' of instrument '${instrumentKey}'. Use 'summaryMdFile' and 'summaryHtmlFile'.`)
110+
106111
const action: DefaultAction = {
107112
name: actionKey,
108113
commandsContext: parseCommands(defaultActionObject.commands, instrumentKey, actionKey),
109114
with: parseWith(defaultActionObject.with),
110115
produces: parseProduces(defaultActionObject.produces),
111-
summaryFile: defaultActionObject.summaryFile
112-
? replaceMissionContextVariables(defaultActionObject.summaryFile)
116+
summaryMdFile: defaultActionObject.summaryMdFile
117+
? replaceMissionContextVariables(defaultActionObject.summaryMdFile)
118+
: undefined,
119+
summaryHtmlFile: defaultActionObject.summaryHtmlFile
120+
? replaceMissionContextVariables(defaultActionObject.summaryHtmlFile)
113121
: undefined,
114122
}
115123

116-
if (actionKey === summaryActionKey && action.summaryFile) {
124+
if (actionKey === summaryActionKey) {
117125
const instrumentName = missionContext.getVariable(INSTRUMENT_NAME)!
118-
missionContext.addVariable(`${instrumentName}Summary`, path.resolve(
119-
missionContext.getVariable(INSTRUMENT_PATH)!, action.summaryFile
120-
))
126+
127+
if (action.summaryMdFile)
128+
missionContext.addVariable(`${instrumentName}SummaryMd`, path.resolve(
129+
missionContext.getVariable(INSTRUMENT_PATH)!, action.summaryMdFile
130+
))
131+
132+
if (action.summaryHtmlFile)
133+
missionContext.addVariable(`${instrumentName}SummaryHtml`, path.resolve(
134+
missionContext.getVariable(INSTRUMENT_PATH)!, action.summaryHtmlFile
135+
))
121136
}
122137

123138
return action
@@ -198,4 +213,4 @@ function initVariableProvider(): void {
198213
actionEnvVarProvider = new VariableProvider()
199214
variableHandler.addParametersProvider(missionCommandVarProvider, missionActionVarProvider, commandVarProvider, actionVarProvider)
200215
variableHandler.addEnvironmentVariablesProviders(missionCommandEnvVarProvider, missionActionEnvVarProvider, missionEnvVarProvider, commandEnvVarProvider, actionEnvVarProvider)
201-
}
216+
}

src/runner/default-actions/summary-action-runner.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,61 @@ import fs from 'fs'
22
import path from 'node:path'
33
import {DefaultAction} from '../../model/Action'
44
import {runCommand} from '../command-runner'
5+
import {missionContext} from '../../context/MissionContext'
6+
7+
interface SummaryActionResult {
8+
summaryMdFilePath: string | null
9+
summaryHtmlFilePath: string | null
10+
}
511

612
export async function runSummaryAction(
713
action: DefaultAction,
814
instrumentPath: string,
915
instrumentName: string
10-
): Promise<string | null> {
11-
const summaryFilePath = action.summaryFile
12-
? path.resolve(instrumentPath, action.summaryFile)
16+
): Promise<SummaryActionResult> {
17+
const summaryMdFilePath = action.summaryMdFile
18+
? path.resolve(instrumentPath, action.summaryMdFile)
19+
: null
20+
const summaryHtmlFilePath = action.summaryHtmlFile
21+
? path.resolve(instrumentPath, action.summaryHtmlFile)
1322
: null
23+
const expectedSummaryFiles = [summaryMdFilePath, summaryHtmlFilePath].filter((filePath): filePath is string => filePath !== null)
1424

15-
// If summaryFile is declared and already exists, skip commands
16-
if (summaryFilePath && fs.existsSync(summaryFilePath)) {
17-
return summaryFilePath
25+
if (expectedSummaryFiles.length > 0 && expectedSummaryFiles.every(filePath => fs.existsSync(filePath))) {
26+
updateSummaryVariables(instrumentName, summaryMdFilePath, summaryHtmlFilePath)
27+
return {
28+
summaryMdFilePath,
29+
summaryHtmlFilePath,
30+
}
1831
}
1932

20-
// Run generation commands if defined
2133
if (action.commandsContext && action.commandsContext.length > 0) {
2234
for (const commandContext of action.commandsContext) {
2335
await runCommand(commandContext, commandContext.dir ?? instrumentPath, instrumentName)
2436
}
2537
}
2638

27-
// Return the summary file path if it was declared and now exists
28-
if (summaryFilePath) {
29-
if (fs.existsSync(summaryFilePath)) {
30-
return summaryFilePath
31-
}
32-
console.warn(`Instrument ${instrumentName}: summary file not found at ${summaryFilePath}`)
39+
if (summaryMdFilePath && !fs.existsSync(summaryMdFilePath))
40+
console.warn(`Instrument ${instrumentName}: summary markdown file not found at ${summaryMdFilePath}`)
41+
42+
if (summaryHtmlFilePath && !fs.existsSync(summaryHtmlFilePath))
43+
console.warn(`Instrument ${instrumentName}: summary HTML file not found at ${summaryHtmlFilePath}`)
44+
45+
updateSummaryVariables(instrumentName, summaryMdFilePath, summaryHtmlFilePath)
46+
47+
return {
48+
summaryMdFilePath: summaryMdFilePath && fs.existsSync(summaryMdFilePath) ? summaryMdFilePath : null,
49+
summaryHtmlFilePath: summaryHtmlFilePath && fs.existsSync(summaryHtmlFilePath) ? summaryHtmlFilePath : null,
3350
}
51+
}
3452

35-
return null
53+
function updateSummaryVariables(instrumentName: string, summaryMdFilePath: string | null, summaryHtmlFilePath: string | null): void {
54+
missionContext.addVariable(
55+
`${instrumentName}SummaryMd`,
56+
summaryMdFilePath && fs.existsSync(summaryMdFilePath) ? summaryMdFilePath : 'null'
57+
)
58+
missionContext.addVariable(
59+
`${instrumentName}SummaryHtml`,
60+
summaryHtmlFilePath && fs.existsSync(summaryHtmlFilePath) ? summaryHtmlFilePath : 'null'
61+
)
3662
}

0 commit comments

Comments
 (0)