Skip to content

Commit a0fd1ae

Browse files
committed
Fix cloud-run-locally input behaviour and action failing without flags
- Fixes the behaviour of `cloud-run-locally` action input where it was behaving opposite to what was expected - Fixes a bug where if no flags are sent as input the action crashes with error code 255 Fixes #15 Fixed #14
1 parent 5fae340 commit a0fd1ae

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

.github/workflows/test.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ jobs:
2222
flags: --vus 10 --duration 30s
2323
parallel: true
2424
cloud-run-locally: false
25+
protocol-without-flags:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Setup Grafana k6
30+
uses: grafana/setup-k6-action@main
31+
with:
32+
k6-version: '0.49.0'
33+
- uses: ./
34+
continue-on-error: true
35+
with:
36+
path: |
37+
./dev/protocol*.js
2538
verify-scripts:
2639
runs-on: ubuntu-latest
2740
env:

action.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ inputs:
2424
required: false
2525
cloud-run-locally:
2626
description: 'If true, run tests locally instead and upload results to Grafana Cloud k6'
27+
default: "true"
2728
required: false
2829
cloud-comment-on-pr:
2930
description: 'If true, comment the cloud test run URL on the pull request'
3031
default: "true"
3132
required: false
32-
only-verify-scripts:
33+
only-verify-scripts:
3334
description: 'If true, only check if the test scripts are valid and skip test execution'
3435
default: "false"
3536
required: false

dist/index.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -34466,16 +34466,33 @@ async function run() {
3446634466
process.exit(1);
3446734467
}
3446834468
function generateCommand(path) {
34469+
let command;
3446934470
const args = [
3447034471
// `--address=""`, // Disable the REST API. THIS DOESN'T WORK???? TODO: Investigate
3447134472
...(flags ? flags.split(' ') : []),
3447234473
];
34473-
if (isCloud && cloudRunLocally) {
34474-
return `k6 cloud ${args.join(' ')} ${path}`;
34474+
if (isCloud) {
34475+
// Cloud execution is possible for the test
34476+
if (cloudRunLocally) {
34477+
// Execute tests locally and upload results to cloud
34478+
command = "k6 run";
34479+
args.push(`--out=cloud`);
34480+
}
34481+
else {
34482+
// Execute tests in cloud
34483+
command = "k6 cloud";
34484+
}
3447534485
}
3447634486
else {
34477-
return `k6 run ${args.join(' ')}${(isCloud) ? [' --out=cloud'] : []} ${path}`;
34487+
// Local execution
34488+
command = "k6 run";
3447834489
}
34490+
// Add path the arguments list
34491+
args.push(path);
34492+
// Append arguments to the command
34493+
command = `${command} ${args.join(' ')}`;
34494+
core.debug("🤖 Generated command: " + command);
34495+
return command;
3447934496
}
3448034497
function runCommand(command) {
3448134498
const parts = command.split(' ');
@@ -34487,7 +34504,7 @@ async function run() {
3448734504
detached: true,
3448834505
env: process.env,
3448934506
});
34490-
// Parse k6 command output and extract test run URLs if running in cloud mode.
34507+
// Parse k6 command output and extract test run URLs if running in cloud mode.
3449134508
// Also, print the output to the console, excluding the progress lines.
3449234509
child.stdout?.on('data', (data) => (0, k6OutputParser_1.parseK6Output)(data, TEST_RESULT_URLS_MAP, TOTAL_TEST_RUNS));
3449334510
return child;

src/index.ts

+24-4
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,35 @@ export async function run(): Promise<void> {
138138
}
139139

140140
function generateCommand(path: string): string {
141+
let command;
141142
const args = [
142143
// `--address=""`, // Disable the REST API. THIS DOESN'T WORK???? TODO: Investigate
143144
...(flags ? flags.split(' ') : []),
144145
]
145-
if (isCloud && cloudRunLocally) {
146-
return `k6 cloud ${args.join(' ')} ${path}`
146+
147+
if (isCloud) {
148+
// Cloud execution is possible for the test
149+
if (cloudRunLocally) {
150+
// Execute tests locally and upload results to cloud
151+
command = "k6 run"
152+
args.push(`--out=cloud`)
153+
} else {
154+
// Execute tests in cloud
155+
command = "k6 cloud"
156+
}
147157
} else {
148-
return `k6 run ${args.join(' ')}${(isCloud) ? [' --out=cloud'] : []} ${path}`
158+
// Local execution
159+
command = "k6 run"
149160
}
161+
162+
// Add path the arguments list
163+
args.push(path)
164+
165+
// Append arguments to the command
166+
command = `${command} ${args.join(' ')}`
167+
168+
core.debug("🤖 Generated command: " + command);
169+
return command;
150170
}
151171

152172
function runCommand(command: string): any {
@@ -160,7 +180,7 @@ export async function run(): Promise<void> {
160180
detached: true,
161181
env: process.env,
162182
});
163-
// Parse k6 command output and extract test run URLs if running in cloud mode.
183+
// Parse k6 command output and extract test run URLs if running in cloud mode.
164184
// Also, print the output to the console, excluding the progress lines.
165185
child.stdout?.on('data', (data) => parseK6Output(data, TEST_RESULT_URLS_MAP, TOTAL_TEST_RUNS));
166186

0 commit comments

Comments
 (0)