It's as easy as:
name: Main Workflow
on: [push]
jobs:
build:
name: Run k6 test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run k6 local test
uses: k6io/action@v0.2.0
with:
filename: my-load-test.js
flags: --vus 50 --duration 10s
name: Main Workflow
on: [push]
jobs:
build:
name: Run k6 test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run k6 cloud test
uses: k6io/action@v0.2.0
with:
filename: my-load-test.js
flags: --vus 50 --duration 10s
cloud: true
token: ${{ secrets.K6_CLOUD_API_TOKEN }}
steps:
- name: Run k6 local test
uses: k6io/action@v0.2.0
with:
filename: my-script-file.js
Sets the filename of the test script to execute. This property is relative to the workspace directory. If omitted, it defaults to test.js
.
steps:
- name: Run k6 cloud test
uses: k6io/action@v0.2.0
with:
cloud: true
token: ${{ secrets.K6_CLOUD_API_TOKEN }}
Enables execution in the k6 cloud. Additional details on the k6 cloud offering are available at https://k6.io/docs/cloud/.
steps:
- name: Run k6 local test
uses: k6io/action@v0.2.0
with:
flags: --vus 50 --duration 10s
Any additional arguments or flags to pass to the k6 cli. The full list of possible options is available at https://k6.io/docs/using-k6/options.
For additional information, and help getting started, see https://k6.io
Environment variables can be added the same way as you do it locally, using the flags
action option:
steps:
- name: Run k6 local test
uses: k6io/action@v0.2.0
with:
filename: my-script-file.js
flags: --env MY_VAR=42
Or can be scoped to the action step:
steps:
- name: Run k6 local test
uses: k6io/action@v0.2.0
with:
filename: my-script-file.js
env:
MY_VAR: 42
Unfortunately, running the local system under test and k6 at the same time is currently not supported by the marketplace action. However, this is easily accomplished by downloading the k6 binary and running it from the same step as the server start:
name: Main Workflow
on: [push]
jobs:
build:
name: Run k6 test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install k6
run: |
curl https://github.com/loadimpact/k6/releases/download/v0.26.2/k6-v0.26.2-linux64.tar.gz -L | tar xvz --strip-components 1
- name: Install packages
run: |
npm install
- name: Start server and run tests
run: |
npm start & npx wait-on http://localhost:3000
./k6 run test.js
Thanks to Amy Hoad for contributing on the solution for this.