Skip to content

Commit a41e8ae

Browse files
committed
Remvoe base path prefix from script path
1 parent 7d3a8f4 commit a41e8ae

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

dist/index.js

+36-12
Original file line numberDiff line numberDiff line change
@@ -34168,6 +34168,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3416834168
exports.generatePRComment = exports.createOrUpdateComment = exports.getActionCommentId = exports.getPullRequestNumber = void 0;
3416934169
const core = __importStar(__nccwpck_require__(2186));
3417034170
const github = __importStar(__nccwpck_require__(5438));
34171+
const k6helper_1 = __nccwpck_require__(1034);
3417134172
const { context } = github;
3417234173
const { eventName, payload } = context;
3417334174
const { repo, owner } = context.repo;
@@ -34276,10 +34277,10 @@ async function generatePRComment(testRunUrlsMap) {
3427634277
core.debug('Generating PR comment');
3427734278
let testRunUrls = '';
3427834279
for (const [scriptPath, testRunUrl] of Object.entries(testRunUrlsMap)) {
34279-
testRunUrls += `🔗 [${scriptPath}](${testRunUrl})\n`;
34280+
testRunUrls += `🔗 [${(0, k6helper_1.cleanScriptPath)(scriptPath)}](${testRunUrl})\n`;
3428034281
}
3428134282
let comment = `# Performance Test Results 🚀
34282-
34283+
3428334284
Select a test run from below to view the test progress and results on Grafana Cloud K6:
3428434285

3428534286
${testRunUrls}
@@ -34289,20 +34290,21 @@ async function generatePRComment(testRunUrlsMap) {
3428934290
pullRequestNumber = await getPullRequestNumber();
3429034291
}
3429134292
catch (error) {
34292-
core.error(`Error getting pull request number`);
34293-
core.error(error);
34293+
core.debug(`Got following error in getting pull request number`);
34294+
core.debug(error);
3429434295
}
3429534296
if (!pullRequestNumber) {
34296-
core.debug('Pull request number not found skipping comment creation');
34297+
core.warning('Unable to get pull request number for the commit, skipping comment creation');
3429734298
return;
3429834299
}
3429934300
try {
3430034301
await createOrUpdateComment(pullRequestNumber, comment);
3430134302
core.debug('Comment created successfully');
3430234303
}
3430334304
catch (error) {
34304-
core.error(`Error creating comment on pull request: ${pullRequestNumber}`);
34305-
core.error(error);
34305+
core.warning('Error creating comment on pull request');
34306+
core.debug(`Following error occurred in creating comment on pull request: ${pullRequestNumber}`);
34307+
core.debug(error);
3430634308
}
3430734309
}
3430834310
exports.generatePRComment = generatePRComment;
@@ -34387,9 +34389,17 @@ async function run() {
3438734389
set: (target, key, value) => {
3438834390
target[key] = value;
3438934391
if (Object.keys(target).length === TOTAL_TEST_RUNS) {
34390-
if (isCloud && shouldCommentCloudTestRunUrlOnPR) {
34391-
// Generate PR comment with test run URLs
34392-
allPromises.push((0, githubHelper_1.generatePRComment)(target));
34392+
// All test run cloud urls are available
34393+
if (isCloud) {
34394+
// Log test run URLs to the console
34395+
console.log('🌐 Test run URLs:');
34396+
for (const [script, url] of Object.entries(target)) {
34397+
console.log(` ${(0, k6helper_1.cleanScriptPath)(script)}: ${url}`);
34398+
}
34399+
if (shouldCommentCloudTestRunUrlOnPR) {
34400+
// Generate PR comment with test run URLs
34401+
allPromises.push((0, githubHelper_1.generatePRComment)(target));
34402+
}
3439334403
}
3439434404
}
3439534405
return true;
@@ -34708,8 +34718,8 @@ exports.parseK6Output = parseK6Output;
3470834718
"use strict";
3470934719

3471034720
Object.defineProperty(exports, "__esModule", ({ value: true }));
34711-
exports.validateTestPaths = void 0;
34712-
// Common helper functions used in the action
34721+
exports.cleanScriptPath = exports.validateTestPaths = void 0;
34722+
// Common helper functions used in the action
3471334723
const child_process_1 = __nccwpck_require__(2081);
3471434724
async function validateTestPaths(testPaths) {
3471534725
/**
@@ -34745,6 +34755,20 @@ async function validateTestPaths(testPaths) {
3474534755
return validK6TestPaths;
3474634756
}
3474734757
exports.validateTestPaths = validateTestPaths;
34758+
function cleanScriptPath(scriptPath) {
34759+
/**
34760+
* Cleans the script path by removing the base directory prefix if it is present.
34761+
*
34762+
* @export
34763+
* @param {string} scriptPath - The script path to clean
34764+
* @return {string} - Cleaned script path
34765+
*
34766+
* */
34767+
const baseDir = process.env['GITHUB_WORKSPACE'] || '';
34768+
const cleanedScriptPath = scriptPath.replace(baseDir, '');
34769+
return scriptPath.trim();
34770+
}
34771+
exports.cleanScriptPath = cleanScriptPath;
3474834772

3474934773

3475034774
/***/ }),

src/githubHelper.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core';
22
import * as github from '@actions/github';
3+
import { cleanScriptPath } from './k6helper';
34
import { TestRunUrlsMap } from './types';
45

56
const { context } = github;
@@ -131,7 +132,7 @@ export async function generatePRComment(testRunUrlsMap: TestRunUrlsMap): Promise
131132

132133
let testRunUrls = '';
133134
for (const [scriptPath, testRunUrl] of Object.entries(testRunUrlsMap)) {
134-
testRunUrls += `🔗 [${scriptPath}](${testRunUrl})\n`;
135+
testRunUrls += `🔗 [${cleanScriptPath(scriptPath)}](${testRunUrl})\n`;
135136
}
136137

137138
let comment = `# Performance Test Results 🚀

src/index.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { spawn } from 'child_process';
44
import * as fs from 'fs-extra';
55
import { generatePRComment } from './githubHelper';
66
import { parseK6Output } from './k6OutputParser';
7-
import { validateTestPaths } from './k6helper';
7+
import { cleanScriptPath, validateTestPaths } from './k6helper';
88
import { TestRunUrlsMap } from './types';
99

1010
const TEST_PIDS: number[] = [];
@@ -59,9 +59,18 @@ export async function run(): Promise<void> {
5959
set: (target: TestRunUrlsMap, key: string, value: string) => {
6060
target[key] = value;
6161
if (Object.keys(target).length === TOTAL_TEST_RUNS) {
62-
if (isCloud && shouldCommentCloudTestRunUrlOnPR) {
63-
// Generate PR comment with test run URLs
64-
allPromises.push(generatePRComment(target));
62+
// All test run cloud urls are available
63+
if (isCloud) {
64+
// Log test run URLs to the console
65+
console.log('🌐 Test run URLs:');
66+
for (const [script, url] of Object.entries(target)) {
67+
console.log(` ${cleanScriptPath(script)}: ${url}`);
68+
}
69+
70+
if (shouldCommentCloudTestRunUrlOnPR) {
71+
// Generate PR comment with test run URLs
72+
allPromises.push(generatePRComment(target));
73+
}
6574
}
6675
}
6776
return true;

src/k6helper.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Common helper functions used in the action
1+
// Common helper functions used in the action
22
import { spawn } from 'child_process';
33

44
export async function validateTestPaths(testPaths: string[]): Promise<string[]> {
@@ -44,4 +44,20 @@ export async function validateTestPaths(testPaths: string[]): Promise<string[]>
4444
await Promise.all(allPromises);
4545

4646
return validK6TestPaths;
47+
}
48+
49+
export function cleanScriptPath(scriptPath: string): string {
50+
/**
51+
* Cleans the script path by removing the base directory prefix if it is present.
52+
*
53+
* @export
54+
* @param {string} scriptPath - The script path to clean
55+
* @return {string} - Cleaned script path
56+
*
57+
* */
58+
const baseDir = process.env['GITHUB_WORKSPACE'] || '';
59+
const cleanedScriptPath = scriptPath.replace(baseDir, '');
60+
61+
return cleanedScriptPath.trim();
62+
4763
}

0 commit comments

Comments
 (0)