From 4dbc350978db6a32593bd3ee4bd6bafb040a3716 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Sun, 10 Nov 2024 16:36:09 +0900 Subject: [PATCH] Set default report path (#174) * fix: fix report path (#172) * fix: set default report path * fix: report file path --- README.md | 2 +- src/config.ts | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) 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);