From 022f3c1a068c8a3ce04417f3dd48a703b4617d75 Mon Sep 17 00:00:00 2001 From: Pepe Cano <825430+ppcano@users.noreply.github.com> Date: Tue, 12 Dec 2023 18:53:12 +0100 Subject: [PATCH] Add GH action for k6 tests --- .github/workflows/k6-tests.yaml | 46 +++++++++++++++++++++++++++++++++ run-ci-tests.sh | 24 +++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/k6-tests.yaml create mode 100755 run-ci-tests.sh diff --git a/.github/workflows/k6-tests.yaml b/.github/workflows/k6-tests.yaml new file mode 100644 index 00000000..c48438f5 --- /dev/null +++ b/.github/workflows/k6-tests.yaml @@ -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 \ No newline at end of file diff --git a/run-ci-tests.sh b/run-ci-tests.sh new file mode 100755 index 00000000..9f19c219 --- /dev/null +++ b/run-ci-tests.sh @@ -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 \ No newline at end of file