Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix report config file err #90

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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