Skip to content

Commit 21d7060

Browse files
committed
[feat] Remove cloud execution initialisation logs
1 parent 723c235 commit 21d7060

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

dist/index.js

+27-10
Original file line numberDiff line numberDiff line change
@@ -34194,7 +34194,7 @@ async function getPullRequestNumber() {
3419434194
commitSHA = payload.after;
3419534195
}
3419634196
if (!commitSHA) {
34197-
console.log('Commit SHA not found, unable to get pull request number.');
34197+
core.debug('Commit SHA not found, unable to get pull request number.');
3419834198
return;
3419934199
}
3420034200
const result = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
@@ -34271,7 +34271,7 @@ async function generatePRComment(testResultUrlsMap) {
3427134271
*
3427234272
*
3427334273
* */
34274-
console.log('Generating PR comment');
34274+
core.debug('Generating PR comment');
3427534275
let testRunUrls = '';
3427634276
for (const [scriptPath, testRunUrl] of Object.entries(testResultUrlsMap)) {
3427734277
testRunUrls += `🔗 [${scriptPath}](${testRunUrl})\n`;
@@ -34284,11 +34284,11 @@ async function generatePRComment(testResultUrlsMap) {
3428434284
`;
3428534285
const pullRequestNumber = await getPullRequestNumber();
3428634286
if (!pullRequestNumber) {
34287-
console.log('Pull request number not found skipping comment creation');
34287+
core.debug('Pull request number not found skipping comment creation');
3428834288
return;
3428934289
}
3429034290
await createOrUpdateComment(pullRequestNumber, comment);
34291-
console.log('Comment created successfully');
34291+
core.debug('Comment created successfully');
3429234292
}
3429334293
exports.generatePRComment = generatePRComment;
3429434294

@@ -34349,8 +34349,8 @@ async function run() {
3434934349
set: (target, key, value) => {
3435034350
target[key] = value;
3435134351
if (Object.keys(target).length === TOTAL_TEST_RUNS) {
34352-
console.log('📊 URLs for all the tests gathered');
34353-
console.log('📊 Test URLs:', target);
34352+
core.debug('📊 URLs for all the tests gathered');
34353+
core.debug(`📊 Test URLs: ${target}`);
3435434354
if (isCloud) {
3435534355
// Generate PR comment with test run URLs
3435634356
(0, githubHelper_1.generatePRComment)(target);
@@ -34515,12 +34515,24 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3451534515
exports.parseK6Output = void 0;
3451634516
const REGEX_EXPRESSIONS = {
3451734517
scriptPath: /^\s*script:\s*(.+)$/m,
34518+
// output: https://k6cloud.grafana.net/a/k6-app/runs/123
34519+
// output: cloud (https://k6cloud.grafana.net/a/k6-app/runs/2662254)
3451834520
output: /^\s*output:\s*(.+)$/m,
34521+
outputCloudUrl: /cloud\s*\((.+)\)/,
3451934522
runningIteration: /running \(.*\), \d+\/\d+ VUs, \d+ complete and \d+ interrupted iterations/g,
3452034523
// default [ 20% ] 10 VUs 1.0s/5s
3452134524
// createBrowser [ 61% ] 035/500 VUs 0m36.5s/1m0s 5.00 iters/s
34522-
runProgress: /\[\s*(\d+)%\s*\]\s*\d+(\/\d+)? VUs/g
34523-
};
34525+
executionProgress: /\[\s*(\d+)%\s*\]\s*\d+(\/\d+)? VUs/g,
34526+
// Init [ 0% ] Loading test script...
34527+
// Init [ 0% ] Validating script options
34528+
// Run [ 17% ] 14.0s/35s
34529+
// Run [ 0% ] Initializing
34530+
cloudRunExecution: /Init|Run\s+\[\s+\d+%\s+\]/g
34531+
}, TEST_RUN_PROGRESS_MSG_REGEXES = [
34532+
REGEX_EXPRESSIONS.runningIteration,
34533+
REGEX_EXPRESSIONS.executionProgress,
34534+
REGEX_EXPRESSIONS.cloudRunExecution
34535+
];
3452434536
function extractTestRunUrl(data, testResultUrlsMap) {
3452534537
/**
3452634538
* This function extracts the script path and output URL from the k6 output.
@@ -34539,8 +34551,10 @@ function extractTestRunUrl(data, testResultUrlsMap) {
3453934551
// Extracting the output URL
3454034552
const outputMatch = data.match(REGEX_EXPRESSIONS.output);
3454134553
const output = outputMatch ? outputMatch[1] : null;
34554+
const outputCloudUrlMatch = output ? output.match(REGEX_EXPRESSIONS.outputCloudUrl) : null;
34555+
const outputCloudUrl = outputCloudUrlMatch ? outputCloudUrlMatch[1] : output;
3454234556
if (scriptPath && output) {
34543-
testResultUrlsMap[scriptPath] = output;
34557+
testResultUrlsMap[scriptPath] = outputCloudUrl || '';
3454434558
return true;
3454534559
}
3454634560
else {
@@ -34575,6 +34589,9 @@ function checkIfK6ASCIIArt(data) {
3457534589
if (!data.includes(".io")) {
3457634590
return false;
3457734591
}
34592+
// During cloud execution, the ASCII art is printed with %0A instead of \n
34593+
data = data.replace(/%0A/g, "\n");
34594+
data = data.slice(0, data.indexOf(".io") + 3);
3457834595
let K6_ASCII_ART_CHARS = [
3457934596
'|', ' ', '\n', '/',
3458034597
'‾', '(', ')', '_',
@@ -34620,7 +34637,7 @@ function parseK6Output(data, testResultUrlsMap, totalTestRuns) {
3462034637
}
3462134638
}
3462234639
const filteredLines = lines.filter((line) => {
34623-
const isRegexMatch = REGEX_EXPRESSIONS.runningIteration.test(line) || REGEX_EXPRESSIONS.runProgress.test(line);
34640+
const isRegexMatch = TEST_RUN_PROGRESS_MSG_REGEXES.some((regex) => regex.test(line));
3462434641
return !isRegexMatch;
3462534642
});
3462634643
if (filteredLines.length < lines.length) {

src/githubHelper.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function getPullRequestNumber(): Promise<number | undefined> {
3131
}
3232

3333
if (!commitSHA) {
34-
console.log('Commit SHA not found, unable to get pull request number.')
34+
core.debug('Commit SHA not found, unable to get pull request number.')
3535
return;
3636
}
3737

@@ -123,7 +123,7 @@ export async function generatePRComment(testResultUrlsMap: any) {
123123
*
124124
* */
125125

126-
console.log('Generating PR comment')
126+
core.debug('Generating PR comment')
127127

128128
let testRunUrls = '';
129129
for (const [scriptPath, testRunUrl] of Object.entries(testResultUrlsMap)) {
@@ -140,11 +140,11 @@ export async function generatePRComment(testResultUrlsMap: any) {
140140
const pullRequestNumber = await getPullRequestNumber();
141141

142142
if (!pullRequestNumber) {
143-
console.log('Pull request number not found skipping comment creation');
143+
core.debug('Pull request number not found skipping comment creation');
144144
return;
145145
}
146146

147147
await createOrUpdateComment(pullRequestNumber, comment);
148148

149-
console.log('Comment created successfully');
149+
core.debug('Comment created successfully');
150150
}

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export async function run(): Promise<void> {
2929
set: (target: { [key: string]: string }, key: string, value: string) => {
3030
target[key] = value;
3131
if (Object.keys(target).length === TOTAL_TEST_RUNS) {
32-
console.log('📊 URLs for all the tests gathered');
33-
console.log('📊 Test URLs:', target);
32+
core.debug('📊 URLs for all the tests gathered');
33+
core.debug(`📊 Test URLs: ${target}`);
3434

3535
if (isCloud) {
3636
// Generate PR comment with test run URLs

src/k6OutputParser.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@ import { TestResultUrlsMap } from './types';
22

33
const REGEX_EXPRESSIONS = {
44
scriptPath: /^\s*script:\s*(.+)$/m,
5+
// output: https://k6cloud.grafana.net/a/k6-app/runs/123
6+
// output: cloud (https://k6cloud.grafana.net/a/k6-app/runs/2662254)
57
output: /^\s*output:\s*(.+)$/m,
8+
outputCloudUrl: /cloud\s*\((.+)\)/,
69
runningIteration: /running \(.*\), \d+\/\d+ VUs, \d+ complete and \d+ interrupted iterations/g,
710
// default [ 20% ] 10 VUs 1.0s/5s
811
// createBrowser [ 61% ] 035/500 VUs 0m36.5s/1m0s 5.00 iters/s
9-
runProgress: /\[\s*(\d+)%\s*\]\s*\d+(\/\d+)? VUs/g
10-
};
12+
executionProgress: /\[\s*(\d+)%\s*\]\s*\d+(\/\d+)? VUs/g,
13+
// Init [ 0% ] Loading test script...
14+
// Init [ 0% ] Validating script options
15+
// Run [ 17% ] 14.0s/35s
16+
// Run [ 0% ] Initializing
17+
cloudRunExecution: /Init|Run\s+\[\s+\d+%\s+\]/g
18+
},
19+
TEST_RUN_PROGRESS_MSG_REGEXES = [
20+
REGEX_EXPRESSIONS.runningIteration,
21+
REGEX_EXPRESSIONS.executionProgress,
22+
REGEX_EXPRESSIONS.cloudRunExecution
23+
];
1124

1225

1326
function extractTestRunUrl(data: string, testResultUrlsMap: TestResultUrlsMap): boolean {
@@ -30,9 +43,11 @@ function extractTestRunUrl(data: string, testResultUrlsMap: TestResultUrlsMap):
3043
// Extracting the output URL
3144
const outputMatch = data.match(REGEX_EXPRESSIONS.output);
3245
const output = outputMatch ? outputMatch[1] : null;
46+
const outputCloudUrlMatch = output ? output.match(REGEX_EXPRESSIONS.outputCloudUrl) : null;
47+
const outputCloudUrl = outputCloudUrlMatch ? outputCloudUrlMatch[1] : output;
3348

3449
if (scriptPath && output) {
35-
testResultUrlsMap[scriptPath] = output;
50+
testResultUrlsMap[scriptPath] = outputCloudUrl || '';
3651
return true;
3752
} else {
3853
return false;
@@ -70,6 +85,11 @@ function checkIfK6ASCIIArt(data: string): boolean {
7085
return false;
7186
}
7287

88+
// During cloud execution, the ASCII art is printed with %0A instead of \n
89+
data = data.replace(/%0A/g, "\n");
90+
91+
data = data.slice(0, data.indexOf(".io") + 3);
92+
7393
let K6_ASCII_ART_CHARS = [
7494
'|', ' ', '\n', '/',
7595
'‾', '(', ')', '_',
@@ -123,7 +143,8 @@ export function parseK6Output(data: Buffer, testResultUrlsMap: TestResultUrlsMap
123143
}
124144

125145
const filteredLines = lines.filter((line) => {
126-
const isRegexMatch = REGEX_EXPRESSIONS.runningIteration.test(line) || REGEX_EXPRESSIONS.runProgress.test(line);
146+
const isRegexMatch = TEST_RUN_PROGRESS_MSG_REGEXES.some((regex) => regex.test(line));
147+
127148
return !isRegexMatch;
128149
});
129150

0 commit comments

Comments
 (0)