Skip to content

Commit

Permalink
Add GH action for k6 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ppcano committed Dec 12, 2023
1 parent c18c2f1 commit 022f3c1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/k6-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: k6 - Smoke Testing Suite
on: [push]

jobs:
runner-job:
runs-on: ubuntu-latest

services:
quickpizza:
image: ghcr.io/grafana/quickpizza-local:latest
ports:
- 3333:3333

steps:
- name: Checkout
uses: actions/checkout@v4

# cannot use the k6 docker image because it does not allow executing shell commands
- name: Install k6 in Ubuntu
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
# - name: Install ACT missing dependencies
# run: |
# sudo apt-get update
# . sudo apt-get install -y ca-certificates gnupg2
# sudo apt-get install -y libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev libasound2

- name: Install Chromium
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: chromium-browser

#- name: Run k6 foundations tests
# run: ./run-ci-tests.sh -t ./k6/foundations/01.basic.js -u http://localhost:3333
# uses: grafana/k6-github-action@v1
# with:
# include: ./k6/browser/01.basic.js
# params: --no-thresholds -e BASE_URL=http://localhost:3333
# browser: true
- name: Run k6 browser tests
run: ./run-ci-tests.sh -t ./k6/browser/01.basic.js -u http://localhost:3333
24 changes: 24 additions & 0 deletions run-ci-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

shopt -s globstar

while getopts "u:t:" flag; do
case $flag in
u) BASE_URL="$OPTARG" ;;
t) TESTS="$OPTARG" ;;
esac
done

BASE_URL="${BASE_URL:=http://localhost:3333}"
TESTS="${TESTS:=k6/foundations/*.js}"

for test in $TESTS; do
#echo $test
# Run without thresholds because some examples will fail
K6_BROWSER_HEADLESS=true K6_BROWSER_ARGS='no-sandbox' k6 run --no-thresholds -e BASE_URL=$BASE_URL "$test"

# If k6 run command fails, exit with the same status code
if [ $? -ne 0 ]; then
exit $?
fi
done

0 comments on commit 022f3c1

Please sign in to comment.