├── .github └── workflows │ └── main.yml ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml ├── entrypoint.sh ├── k6.gif └── test.js /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Main Workflow 2 | on: [push] 3 | jobs: 4 | build: 5 | name: Run load test using the action 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v4 10 | - name: Run load test using action code from commit 11 | uses: ./ 12 | with: 13 | cloud: true 14 | token: ${{ secrets.K6_TOKEN }} 15 | flags: --vus 1 --duration 10s 16 | - name: Run load test using actions tarball 17 | uses: grafana/k6-action@HEAD 18 | with: 19 | cloud: true 20 | token: ${{ secrets.K6_TOKEN }} 21 | flags: --vus 1 --duration 10s 22 | 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM grafana/k6:latest 2 | 3 | USER 0 4 | COPY entrypoint.sh /entrypoint.sh 5 | 6 | ENTRYPOINT ["/entrypoint.sh"] 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 k6 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > ⚠️ This action has been archived and is no longer maintained. 2 | > 3 | > Please use the [Setup K6 Action](https://github.com/grafana/setup-k6-action) and [Run K6 Action](https://github.com/grafana/run-k6-action) instead. To learn about using the new GitHub actions, check out the [tutorial on using Grafana k6 and GitHub Actions](https://grafana.com/blog/2024/07/15/performance-testing-with-grafana-k6-and-github-actions/). 4 | 5 | # k6-action 6 | 7 | ### See also 8 | - [Performance testing with Grafana k6 and GitHub Actions](https://grafana.com/blog/2024/07/15/performance-testing-with-grafana-k6-and-github-actions/) 9 | 10 | ### Local test 11 | 12 | ```yaml 13 | name: Main Workflow 14 | on: [push] 15 | jobs: 16 | build: 17 | name: Run k6 test 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v4 22 | - name: Run k6 local test 23 | uses: grafana/k6-action@v0.3.1 24 | with: 25 | filename: my-load-test.js 26 | flags: --vus 50 --duration 10s 27 | ``` 28 | 29 | ### Cloud test 30 | 31 | ```yml 32 | name: Main Workflow 33 | on: [push] 34 | jobs: 35 | build: 36 | name: Run k6 test 37 | runs-on: ubuntu-latest 38 | steps: 39 | - name: Checkout 40 | uses: actions/checkout@v4 41 | - name: Run k6 cloud test 42 | uses: grafana/k6-action@v0.3.1 43 | with: 44 | filename: my-load-test.js 45 | flags: --vus 50 --duration 10s 46 | cloud: true 47 | token: ${{ secrets.K6_CLOUD_API_TOKEN }} 48 | ``` 49 | 50 | ### Inputs 51 | 52 | #### Filename 53 | 54 | ```yaml 55 | steps: 56 | - name: Run k6 local test 57 | uses: grafana/k6-action@v0.3.1 58 | with: 59 | filename: my-script-file.js 60 | ``` 61 | 62 | Sets the filename of the test script to execute. This property is relative to the workspace directory. If omitted, it defaults to `test.js`. 63 | 64 | #### Cloud 65 | 66 | ```yaml 67 | environment: test 68 | 69 | steps: 70 | - name: Run k6 cloud test 71 | uses: grafana/k6-action@v0.3.1 72 | with: 73 | cloud: true 74 | token: ${{ secrets.K6_CLOUD_API_TOKEN }} 75 | ``` 76 | 77 | Enables execution in Grafana Cloud k6. Additional details on the k6 cloud offering are available at [https://grafana.com/docs/grafana-cloud/k6/](https://grafana.com/docs/grafana-cloud/k6/). 78 | 79 | You can use a Grafana Cloud k6 personal API token, or a Grafana Stack API token. For more details, refer to [Authenticate on the CLI](https://grafana.com/docs/grafana-cloud/k6/author-run/tokens-and-cli-authentication/#authenticate-on-the-cli). 80 | 81 | #### Flags 82 | 83 | ```yaml 84 | steps: 85 | - name: Run k6 local test 86 | uses: grafana/k6-action@v0.3.1 87 | with: 88 | flags: --vus 50 --duration 10s 89 | ``` 90 | 91 | Any additional arguments or flags to pass to the k6 CLI. The full list of possible options is available at https://grafana.com/docs/k6/latest/using-k6/k6-options/reference/. 92 | 93 | For additional information, and help getting started, see https://grafana.com/docs/k6/latest/get-started/running-k6/. 94 | 95 | #### Environment Variables 96 | 97 | Environment variables can be added the same way as you do it [locally](https://grafana.com/docs/k6/latest/using-k6/k6-options/reference/#supply-environment-variables), using the [`flags` action option](https://github.com/grafana/k6-action#flags): 98 | 99 | ```yaml 100 | steps: 101 | - name: Run k6 local test 102 | uses: grafana/k6-action@v0.3.1 103 | with: 104 | filename: my-script-file.js 105 | flags: --env MY_VAR=42 106 | ``` 107 | 108 | Or can be scoped to the action step: 109 | 110 | ```yaml 111 | steps: 112 | - name: Run k6 local test 113 | uses: grafana/k6-action@v0.3.1 114 | with: 115 | filename: my-script-file.js 116 | env: 117 | MY_VAR: 42 118 | ``` 119 | 120 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'k6 Load Test' 2 | description: 'Run a load test with k6, a modern load testing tool built for developer happiness.' 3 | inputs: 4 | cloud: 5 | description: | 6 | To run in the k6 cloud, provide your k6 cloud token as a secret to the input `token`. 7 | Dont have a k6 account yet? Go to https://k6.io/cloud and activate your free trial. 8 | required: false 9 | default: false 10 | token: 11 | description: | 12 | k6 Cloud Token. Only required for using the cloud service. 13 | required: false 14 | default: '' 15 | filename: 16 | description: | 17 | Path to the test script to execute, relative to the workspace. 18 | required: true 19 | default: 'test.js' 20 | flags: 21 | description: | 22 | Additional argument and flags to provide to the k6 CLI. See https://k6.io/docs/using-k6/k6-options/reference/ for details. 23 | required: false 24 | default: '' 25 | runs: 26 | using: 'docker' 27 | image: 'Dockerfile' 28 | env: 29 | K6_CLOUD_TOKEN: ${{ inputs.token }} 30 | args: 31 | - ${{ inputs.cloud }} 32 | - ${{ inputs.filename || 'test.js' }} 33 | - ${{ inputs.flags }} 34 | branding: 35 | icon: 'bar-chart' 36 | color: 'white' 37 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # `$*` expands the `args` supplied in an `array` individually 4 | # or splits `args` in a string separated by whitespace. 5 | export K6_CLOUD_TOKEN=$INPUT_TOKEN 6 | export K6_COMMAND=$([[ $INPUT_CLOUD == "true" ]] && echo 'cloud' || echo 'run') 7 | sh -c "k6 $K6_COMMAND $INPUT_FILENAME $INPUT_FLAGS" -------------------------------------------------------------------------------- /k6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grafana/k6-action/1e9c55046702f865e9a66c44c1004f47f4d01922/k6.gif -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import http from 'k6/http'; 2 | 3 | import { Rate } from 'k6/metrics'; 4 | import { check } from 'k6'; 5 | 6 | const failRate = new Rate('failed_requests'); 7 | 8 | export const options = { 9 | thresholds: { 10 | failed_requests: ['rate<=0'], 11 | http_req_duration: ['p(95)<500'], 12 | }, 13 | ext: { 14 | loadimpact: { 15 | projectID: 3542013, 16 | }, 17 | }, 18 | }; 19 | 20 | export default function () { 21 | const result = http.get('https://test-api.k6.io'); 22 | check(result, { 23 | 'http response status code is 200': result.status === 200, 24 | }); 25 | failRate.add(result.status !== 200); 26 | } 27 | --------------------------------------------------------------------------------