Skip to content

Commit

Permalink
fix report config file err (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M authored Jul 25, 2024
1 parent 54dad06 commit e621151
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
15 changes: 9 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand All @@ -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);
Expand Down Expand Up @@ -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}`);
}
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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}`);
}
Expand Down
7 changes: 5 additions & 2 deletions src/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand All @@ -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);
Expand Down

0 comments on commit e621151

Please sign in to comment.