chore(CI): add tests action (#1)

We run the test suite on every commit and compute the coverage. The
action succeeds only if the coverage is at 100%.
testing
Christian Merten 2 months ago committed by GitHub
parent 61060d7104
commit 9caa3195ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,60 @@
name: Tests
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('requirements.txt', 'docker/test/Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker image with cache
run: |
cd docker/test
docker buildx build \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
--load \
-t kompass:test \
-f Dockerfile \
../../
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Run tests
run: make test-only
- name: Check coverage
run: |
COVERAGE=$(python3 -c "import json; data=json.load(open('docker/test/htmlcov/coverage.json')); print(data['totals']['percent_covered'])")
echo "Coverage: ${COVERAGE}%"
if (( $(echo "$COVERAGE < 100" | bc -l) )); then
echo "Error: Coverage is ${COVERAGE}%, must be 100%"
exit 1
fi

@ -1,7 +1,7 @@
build-test:
cd docker/test; docker compose build
test: build-test
test-only:
mkdir -p docker/test/htmlcov
chmod 777 docker/test/htmlcov
ifeq ($(keepdb), true)
@ -10,3 +10,5 @@ else
cd docker/test; docker compose up --abort-on-container-exit
endif
echo "Generated coverage report. To read it, point your browser to:\n\nfile://$$(pwd)/docker/test/htmlcov/index.html"
test: build-test test-only

@ -1,6 +1,6 @@
# jdav Kompass
[![Build Status](https://jenkins.merten.dev/buildStatus/icon?job=gitea%2Fkompass%2Fmain)](https://jenkins.merten.dev/job/gitea/job/kompass/job/main/)
![Build Status](https://github.com/chrisflav/kompass/actions/workflows/test.yml/badge.svg?branch=main)
Kompass is an administration platform designed for local sections of the Young German Alpine Club. It provides
tools to contact and (automatically) manage members, groups, material, excursions and statements.

@ -44,3 +44,5 @@ else
coverage run manage.py test startpage finance members contrib logindata mailer material ludwigsburgalpin jdav_web -v 2 --noinput
fi
coverage html
coverage json -o htmlcov/coverage.json
coverage report

Loading…
Cancel
Save