API-tests #3203
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
waitSeconds: | |
description: 'Seconds to wait before test run' | |
required: true | |
default: '0' | |
jobs: | |
api-test: | |
name: API-tests | |
runs-on: ubuntu-latest | |
# As default, wait 0 sec for manual triggered and 300 sec for push (wait for new deploy) | |
steps: | |
- name: Set variables | |
env: | |
DEFAULT_URL: 'https://atb-staging.api.mittatb.no' | |
DEFAULT_WAIT_SECONDS: '300' | |
run: | | |
echo "INPUT_URL=${{ github.event.inputs.url || env.DEFAULT_URL }}" >> $GITHUB_ENV | |
echo "INPUT_WAIT_SECONDS=${{ github.event.inputs.waitSeconds || env.DEFAULT_WAIT_SECONDS }}" >> $GITHUB_ENV | |
- name: Sleep given seconds to wait for deploy | |
run: sleep ${{ env.INPUT_WAIT_SECONDS }}s | |
shell: bash | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
- 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.INPUT_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.INPUT_URL }} --env runFrom=root --env printJUnit=false --quiet | |