GitHub Action
Run Grafana k6 tests
v1.1.3
Latest version
This action allows you to easily execute k6 tests as part of your GitHub Actions workflow.
It is a wrapper over k6 run
, with support for globs, parallel execution, fail-fast, and many other features.
This action won't setup/install k6. That functionality is provided by grafana/setup-k6-action
The following inputs can be used as step.with
key:
Name | Type | Required | Default | Description |
---|---|---|---|---|
path |
string | true |
'' |
Glob pattern to select one or multiple test scripts to run. e.g. ./tests/api*.js One can also supply multiple patterns by separating them with new line. path: | |
cloud-run-locally |
boolean | false |
true |
If true , the tests are executed locally and the results are uploaded to Grafana Cloud k6 |
parallel |
boolean | false |
false |
If true and multiple tests are executed, all them run in parallel. |
fail-fast |
boolean | false |
false |
If true , the whole pipeline fails as soon as the first test fails |
flags |
string | false |
'' |
Additional flags to be passed on to the k6 run command.e.g. --vus 10 --duration 20s |
inspect-flags |
string | false |
'' |
Additional flags to be passed on to the k6 inspect command.e.g. --compatibility-mode experimental_enhanced |
cloud-comment-on-pr |
boolean | false |
true |
If true , the workflow comments a link to the cloud test run on the pull request (if present) |
only-verify-scripts |
boolean | false |
false |
If true , only check if the test scripts are valid and skip the test execution' |
debug |
boolean | false |
false |
If true, the output from k6 will be shown in the action logs, else only the summary will be shown. |
Following are some examples of using the workflow.
on:
push:
jobs:
protocol:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: grafana/setup-k6-action@v1
- uses: grafana/run-k6-action@v1
with:
path: |
./tests/api*.js
To send the results to Grafana Cloud k6, you need to set the GCk6 environment variables.
on:
push:
jobs:
protocol:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: grafana/setup-k6-action@v1
- uses: grafana/run-k6-action@v1
env:
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
with:
path: |
./tests/api*.js
By default, the action will run k6 locally and send the results to Grafana Cloud k6. If you want to run the tests in our Cloud instances, you need to change the cloud-run-locally
input to false
:
- uses: grafana/run-k6-action@v1
env:
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
with:
path: |
./tests/api*.js
cloud-run-locally: false
on:
push:
jobs:
protocol:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: grafana/setup-k6-action@v1
browser: true
- uses: grafana/run-k6-action@v1
with:
path: |
./tests/api*.js
./tests/app*.js
flags: --vus 10 --duration 20s # optional: flags to pass to each k6 test (default: none)
parallel: true # optional: run tests in parallel (default: false)
fail-fast: false # optional: fail the step early if any test fails (default: true)
Comment Grafana cloud k6 test URL on PR
- uses: grafana/run-k6-action@v1
env:
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
with:
path: |
./tests/api*.js
cloud-run-locally: false
cloud-comment-on-pr: true
Typescript Compatibility Mode
on:
push:
jobs:
protocol:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: grafana/setup-k6-action@v1
browser: true
- uses: grafana/run-k6-action@v1
with:
path: |
./tests/api*.ts
./tests/app*.ts
flags: --compatibility-mode experimental_enhanced # optional: flags to pass to each k6 test (default: none)
inspect-flags: --compatibility-mode experimental_enhanced # optional: flags to pass to each k6 test validation (default: none)