diff --git a/README.md b/README.md index ba804c86..adf33ec6 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ The custom report page link. - Type: String - Default: N/A -Path of the generated report html file. This file can be deployed in other Actions steps, but is not included in the artifact. If omitted, no html report is generated. +Path of the generated report html file. This file can be deployed in other Actions steps, but is not included in the artifact. If omitted, treated as `./report.html`. #### `artifact-name` (Optional) diff --git a/src/config.ts b/src/config.ts index 145c5f24..22076f0f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,7 @@ import * as core from '@actions/core'; import { statSync } from 'fs'; import { ARTIFACT_NAME } from './constants'; -import { dirname } from 'path'; +import { join } from 'path'; export interface Config { imageDirectoryPath: string; @@ -88,13 +88,6 @@ const validateReportFilePath = (path: string | undefined) => { if (path === undefined || path === '') { return; } - try { - const s = statSync(dirname(path)); - if (s.isDirectory()) return; - else throw null; - } catch (_) { - throw new Error(`'report-file-path' is not in a valid directory. Please specify path to report file.`); - } }; function validateCommentReportFormat(format: string): asserts format is 'raw' | 'summarized' { @@ -126,7 +119,15 @@ export const getConfig = (): Config => { const branch = core.getInput('branch') || 'reg_actions'; const customReportPage = core.getInput('custom-report-page') || null; validateCustomReportPage(customReportPage); - const reportFilePath = core.getInput('report-file-path'); + let reportFilePath = core.getInput('report-file-path'); + if (!reportFilePath) { + reportFilePath = './report.html'; + } + try { + if (statSync(reportFilePath).isDirectory()) { + reportFilePath = join(reportFilePath, './report.html'); + } + } catch {} validateReportFilePath(reportFilePath); const commentReportFormat = core.getInput('comment-report-format') || 'raw'; validateCommentReportFormat(commentReportFormat);