Skip to content

API-tests

API-tests #3656

Workflow file for this run

name: API-tests
on:
push:
branches:
- main
schedule:
- cron: '0 5,7,11,14 * * *'
workflow_dispatch:
inputs:
url:
description: 'Specify URL to run tests against'
required: true
default: 'https://atb-staging.api.mittatb.no'
branch:
description: 'Run against a special branch'
required: true
default: 'main'
waitSeconds:
description: 'Seconds to wait before test run'
required: true
default: '300'
jobs:
api-test:
name: API-tests
runs-on: ubuntu-latest
env:
ENV_URL: ${{ github.event.inputs.url || 'https://atb-staging.api.mittatb.no' }}
ENV_BRANCH: ${{ github.event.inputs.branch || 'main' }}
ENV_WAIT_SECONDS: ${{ github.event.inputs.waitSeconds || '300' }}
steps:
# As default, wait 0 sec for manual triggered and 300 sec for push (wait for new deploy)
- name: Sleep given seconds to wait for deploy
run: sleep ${{ env.ENV_WAIT_SECONDS }}s
shell: bash
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.ENV_BRANCH }}
- name: Install k6
run: |
curl https://github.com/grafana/k6/releases/download/v0.40.0/k6-v0.40.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
cd test && yarn install
- name: Bundle with webpack
run: |
cd test && yarn webpack
- name: Run API tests
run: ./k6 run test/dist/k6.js --env host=${{ env.ENV_URL }} --env runFrom=root --log-output=stdout --log-format=raw | tee test/dist/results/junitLog.txt
- name: Create JUnit from checks
run: python python-tools/apiCheckToJUnit/apiCheckToJUnit.py --file junitLog.txt --folder dist/results
working-directory: test
- name: Create combined JUnit
run: python python-tools/combineJUnit/combineJUnit.py --files junit_bff.xml,junitFromChecks.xml --folder dist/results --addTime true
working-directory: test
- name: Upload test report json
uses: actions/upload-artifact@v4
with:
name: junit-results
path: ./test/dist/results/combinedJUnit.xml
retention-days: 5
- name: Re-run API tests
run: ./k6 run test/dist/k6.js --env host=${{ env.ENV_URL }} --env runFrom=root --env printJUnit=false --quiet