Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,10 @@ jobs:
cloudflare-api-token: ${{ secrets.CF_API_TOKEN }}
cloudflare-zone-id: ${{ secrets.CF_ZONE_ID }}
keycloak-admin-password: ${{ secrets.KEYCLOAK_ADMIN_PASSWORD }}

check:
name: Check
needs: [ deploy ]
uses: ./.github/workflows/check.yml
with:
url: ${{needs.deploy.outputs.url}}
28 changes: 28 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy

on:
workflow_call:
inputs:
url:
type: string
description: URL

jobs:
check:
name: Check
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
-
name: Checkout
uses: actions/checkout@v4

- name: Run local k6 test
uses: grafana/k6-action@v0.2.0
with:
filename: k6/script.js
flags: --out json=results.json
env:
TARGET: ${{ inputs.url }}
7 changes: 7 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ on:
keycloak-admin-password:
description: Keycloak Admin Password
required: true
outputs:
url:
value: ${{ jobs.deploy.outputs.url }}

jobs:
deploy:
Expand All @@ -43,6 +46,8 @@ jobs:
permissions:
contents: 'read'
id-token: 'write'
outputs:
url: ${{ steps.deploy.outputs.url }}
steps:
-
name: Checkout
Expand Down Expand Up @@ -81,6 +86,7 @@ jobs:
# Release name MUST start with a letter
-
name: Deploy
id: deploy
run: |
if [ "${{ github.event_name }}" == "push" ]; then
release=prod
Expand All @@ -91,6 +97,7 @@ jobs:
namespace=$release
url=$release-demo.api-platform.com
fi
echo "url=$url" >> "$GITHUB_OUTPUT"
cors="https://$url|http://localhost|https://localhost|http://localhost:3000"
set -o pipefail
helm upgrade $release ./helm/api-platform -f ./helm/api-platform/values.yaml \
Expand Down
43 changes: 43 additions & 0 deletions k6/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { check, sleep } from "k6";
import http from "k6/http";

export let options = {
maxRedirects: 0,
scenarios: {
default: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 1,
}
},
thresholds: {
http_req_duration: [{threshold: 'p(95)<5000', abortOnFail: true}], //units in miliseconds 60000ms = 1m
http_req_failed: [{threshold: 'rate<0.01', abortOnFail: true}], // http errors should be less than 1%
checks: [{threshold: 'rate>0.95', abortOnFail: true}], // checks must success more than 99%
},
};

const target=__ENV.TARGET;
console.log(`Running test on ${target}`);

export default function() {
check_https_redirect();
check_api_link_header();
sleep(1);
}

function check_https_redirect() {
var r = http.get(`http://${target}/`);
check(r, {
"http request: status is 301": (r) => r.status === 301,
"http request: redirection location ok": (r) => r.headers["Location"] === `https://${target}/`,
});
}

function check_api_link_header() {
var r = http.get(`https://${target}/books?page=1`);
check(r, {
"books API: status is 200": (r) => r.status === 200,
"books API: Link in https": (r) => r.headers["Link"].match(`https://${target}/docs.jsonld`),
});
}
18 changes: 18 additions & 0 deletions k6/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
cd $(dirname $0)
if [ -z "$TARGET" ]; then
echo "Missing TARGET=pr-xxx-demo.api-platform.com" 1>&2
exit 1
fi
docker run \
--name k6 \
--rm -i \
-v $(pwd):/test \
-w /test \
-p 5665:5665 \
-e TARGET=$TARGET \
ghcr.io/szkiba/xk6-dashboard:latest \
run \
--http-debug \
--out=dashboard \
./script.js