Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 7d299e3

Browse files
committed
setup k6 cloud to upload results
Signed-off-by: Sahil Yeole <[email protected]>
1 parent 3aaf778 commit 7d299e3

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

.github/workflows/bench.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
if: github.event.head_commit.message != 'Update performance results in README.md'
1919
env:
2020
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
K6_CLOUD_API_TOKEN: ${{ secrets.K6_CLOUD_API_TOKEN }}
2122
steps:
2223
- name: Checkout (GitHub)
2324
uses: actions/checkout@v4
@@ -34,6 +35,16 @@ jobs:
3435
- name: Setup k6
3536
uses: grafana/setup-k6-action@v1
3637

38+
- name: Setup k6 cloud environment
39+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
40+
run: |
41+
if [ -z "$K6_CLOUD_API_TOKEN" ]; then
42+
echo "K6_CLOUD_API_TOKEN is not set, results will not be uploaded to k6 cloud"
43+
else
44+
k6 login cloud --token $K6_CLOUD_API_TOKEN
45+
echo "IS_K6_CLOUD_ENABLED=true" >> $GITHUB_ENV
46+
fi
47+
3748
- name: Run benchmarks
3849
run: |
3950
bash ./setup.sh

k6/bench.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import http from 'k6/http';
22
import { check } from 'k6';
33

44
const whichBenchmark = Number(__ENV.BENCHMARK);
5+
const benchmarkName = whichBenchmark === 1 ? 'posts' : 'posts+users';
56

67
export const options = {
78
scenarios: {
89
posts: {
910
executor: 'constant-vus',
10-
duration: whichBenchmark === 2 ? '30s' : '10s',
11+
duration: whichBenchmark === 1 ? '10s' : '30s',
1112
gracefulStop: '0s',
1213
vus: 100,
1314
}
1415
},
1516
cloud: {
16-
name: __ENV.TEST_NAME + '-' + whichBenchmark,
17+
name: __ENV.TEST_NAME + '-' + benchmarkName,
1718
},
1819
};
1920

@@ -30,7 +31,7 @@ export default function() {
3031
const payload = JSON.stringify({
3132
operationName: null,
3233
variables: {},
33-
query: whichBenchmark === 2 ? '{posts{id,userId,title,user{id,name,email}}}' : '{posts{title}}',
34+
query: whichBenchmark === 1 ? '{posts{title}}' : '{posts{id,userId,title,user{id,name,email}}}',
3435
});
3536

3637
const res = http.post(url, payload, params);

k6/bench.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
test_name=$1
22
benchmark=$2
33

4-
# k6 run k6/bench.js --quiet --out cloud --env TEST_NAME=$test_name --env BENCHMARK=$benchmark
5-
k6 run k6/bench.js --quiet --env TEST_NAME=$test_name --env BENCHMARK=$benchmark
4+
if [ "$IS_K6_CLOUD_ENABLED" == "true" ]; then
5+
k6 run k6/bench.js --quiet --out cloud --env TEST_NAME=$test_name --env BENCHMARK=$benchmark
6+
else
7+
k6 run k6/bench.js --quiet --env TEST_NAME=$test_name --env BENCHMARK=$benchmark
8+
fi

0 commit comments

Comments
 (0)