diff --git a/dist/index.js b/dist/index.js index ba805d3..bcbe0bf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10751,7 +10751,9 @@ const GITHUB_REPOSITORY_OWNER = process.env.GITHUB_REPOSITORY_OWNER; const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY; const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE; -async function generateGithubReportFile(token, reportConfigFileName = 'github-report.yaml') { +const DEFAULT_GITHUB_REPORT_CONFIG = 'default-github-report.yaml'; + +async function generateGithubReportFile(token, reportConfigFileName = DEFAULT_GITHUB_REPORT_CONFIG) { if (!GITHUB_REPOSITORY || !GITHUB_REPOSITORY_OWNER) { throw new Error('GITHUB_REPOSITORY or GITHUB_REPOSITORY_OWNER is not set.'); } @@ -10763,9 +10765,10 @@ async function generateGithubReportFile(token, reportConfigFileName = 'github-re "project-name": projectName, }; + const isDefaultConfig = reportConfigFileName === DEFAULT_GITHUB_REPORT_CONFIG; let content = {}; - if (reportConfigFileName) { + if (!isDefaultConfig) { try { const data = await external_fs_.promises.readFile(external_path_.join(GITHUB_WORKSPACE, reportConfigFileName), 'utf8'); const { github, ...rest } = load(data); @@ -10873,12 +10876,12 @@ async function run() { if (flags) params.push(...parseFlagsToArray(flags)); - // If everything is fine and github-report is set, generate the yaml config file. - if (githubReport == true) { + // If everything is fine and github-report is set, generate the yaml config file. + if (githubReport) { // create default config file with name `github-report.yaml` await generateGithubReportFile(githubToken); - params.push(`-rc=github-report.yaml`); - } else if (reportConfig != null) { + params.push(`-rc=${DEFAULT_GITHUB_REPORT_CONFIG}`); + } else if (reportConfig && reportConfig.trim().length > 0) { await generateGithubReportFile(githubToken, reportConfig); params.push(`-rc=${reportConfig}`); } diff --git a/src/index.js b/src/index.js index 9f3b25a..d2c7bee 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import * as installer from './installer'; -import { generateGithubReportFile } from './yaml'; +import { generateGithubReportFile, DEFAULT_GITHUB_REPORT_CONFIG } from './yaml'; import { parseFlagsToArray } from './utils'; const fs = require('fs'); @@ -75,12 +75,12 @@ async function run() { if (flags) params.push(...parseFlagsToArray(flags)); - // If everything is fine and github-report is set, generate the yaml config file. - if (githubReport == true) { + // If everything is fine and github-report is set, generate the yaml config file. + if (githubReport) { // create default config file with name `github-report.yaml` await generateGithubReportFile(githubToken); - params.push(`-rc=github-report.yaml`); - } else if (reportConfig != null) { + params.push(`-rc=${DEFAULT_GITHUB_REPORT_CONFIG}`); + } else if (reportConfig && reportConfig.trim().length > 0) { await generateGithubReportFile(githubToken, reportConfig); params.push(`-rc=${reportConfig}`); } diff --git a/src/yaml.js b/src/yaml.js index b253f70..218165a 100644 --- a/src/yaml.js +++ b/src/yaml.js @@ -7,7 +7,9 @@ const GITHUB_REPOSITORY_OWNER = process.env.GITHUB_REPOSITORY_OWNER; const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY; const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE; -export async function generateGithubReportFile(token, reportConfigFileName = 'github-report.yaml') { +export const DEFAULT_GITHUB_REPORT_CONFIG = 'default-github-report.yaml'; + +export async function generateGithubReportFile(token, reportConfigFileName = DEFAULT_GITHUB_REPORT_CONFIG) { if (!GITHUB_REPOSITORY || !GITHUB_REPOSITORY_OWNER) { throw new Error('GITHUB_REPOSITORY or GITHUB_REPOSITORY_OWNER is not set.'); } @@ -19,9 +21,10 @@ export async function generateGithubReportFile(token, reportConfigFileName = 'gi "project-name": projectName, }; + const isDefaultConfig = reportConfigFileName === DEFAULT_GITHUB_REPORT_CONFIG; let content = {}; - if (reportConfigFileName) { + if (!isDefaultConfig) { try { const data = await fs.promises.readFile(path.join(GITHUB_WORKSPACE, reportConfigFileName), 'utf8'); const { github, ...rest } = yaml.load(data);