Skip to content

test all mysql versions #12

test all mysql versions

test all mysql versions #12

name: API Container Tests
on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- "api/source/**"
- "test/api/**"
- "Dockerfile"
- ".github/workflows/api-container-tests.yml"
jobs:
test_api:
# needs: fetch-mysql-versions
name: Mocha tests with ${{ matrix.container.name }} and MySQL ${{ matrix.mysql_version }}
runs-on: ubuntu-latest
strategy:
matrix:
container:
- name: "stig-manager-alpine"
build_arg: "node:lts-alpine"
mysql_version: ["8.0.0", "8.0.1", "8.0.2", "8.0.3", "8.0.4", "8.0.5", "8.0.6", "8.0.7", "8.0.11", "8.0.12", "8.0.13", "8.0.14", "8.0.15", "8.0.16", "8.0.17", "8.0.18", "8.0.19", "8.0.20", "8.0.21", "8.0.22", "8.0.23", "8.0.24", "8.0.25", "8.0.26", "8.0.27", "8.0.28", "8.0.29", "8.0.30", "8.0.31", "8.0.32", "8.0.33", "8.0.34", "8.0.35", "8.0.36", "8.0.37", "8.0.38", "8.0.39"]
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Build image for ${{ matrix.container.name }}
id: image-build
run: |
docker build -t ${{ matrix.container.name }} --build-arg BASE_IMAGE=${{ matrix.container.build_arg }} .
- name: Run mock Keycloak
id: id-run
working-directory: ./test/api/mock-keycloak
run: |
python3 -m http.server 8080 &
- name: Run MySQL container version ${{ matrix.mysql_version }}
id: mysql-run
run: |
docker run -d --name stig-manager-db \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=rootpw \
-e MYSQL_DATABASE=stigman \
-e MYSQL_USER=stigman \
-e MYSQL_PASSWORD=stigman \
mysql:${{ matrix.mysql_version }}
- name: Run STIG Manager container ${{ matrix.container.name }}
id: api-run
run: |
docker run -d --name stig-manager-api \
--net=host \
-e STIGMAN_API_PORT=64001 \
-e STIGMAN_DB_HOST=localhost \
-e STIGMAN_DB_PORT=3306 \
-e STIGMAN_DB_PASSWORD=stigman \
-e STIGMAN_API_AUTHORITY=http://127.0.0.1:8080/auth/realms/stigman \
-e STIGMAN_DEV_RESPONSE_VALIDATION=logOnly \
${{ matrix.container.name }}
- name: Install test dependencies
run: npm ci
working-directory: ./test/api/
- name: Wait for bootstrap
run: for i in {1..10}; do [ $i -gt 1 ] && sleep 5; curl --output /dev/null --silent --fail http://localhost:64001/api/op/configuration && s=0 && break || s=$?; printf '.'; done; (exit $s)
- name: Run tests with coverage
working-directory: ./test/api/
run: npm test
- name: Upload mocha test report
id: artifact-upload-mocha
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: mocha-report-${{ matrix.container.name }}-${{ matrix.mysql_version }}
path: ./test/api/mochawesome-report
- name: Extract API container log
id: api-log-extract
if: ${{ always() }}
working-directory: ./test/api
run: |
docker logs stig-manager-api > api-log-${{ matrix.container.name }}-${{ matrix.mysql_version }}-${{ github.run_id }}.json
- name: Upload API log artifact
uses: actions/upload-artifact@v4
id: api-log-upload
if: ${{ always() }}
with:
name: api-log-${{ matrix.container.name }}-${{ matrix.mysql_version }}-${{ github.run_id }}
path: ./test/api/api-log-${{ matrix.container.name }}-${{ matrix.mysql_version }}-${{ github.run_id }}.json
- name: Collect all container logs on failure
if: ${{ cancelled() || failure() }}
uses: jwalton/gh-docker-logs@54a2a89cd6a2c929525f26ca67a7a4857a5dc1d9 # pin@v1
with:
dest: "./logs-${{ matrix.container.name }}-${{ matrix.mysql_version }}"
- name: Tar container logs
if: ${{ cancelled() || failure() }}
run: tar cvzf ./logs-${{ matrix.container.name }}-${{ matrix.mysql_version }}.tgz ./logs-${{ matrix.container.name }}-${{ matrix.mysql_version }}
- name: Upload container logs artifact
if: ${{ cancelled() || failure() }}
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.container.name }}-${{ matrix.mysql_version }}.tgz
path: ./logs-${{ matrix.container.name }}-${{ matrix.mysql_version }}.tgz