Tests in Imas Container #532
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: Tests in Imas Container | |
on: | |
schedule: | |
# At 05:34 on Sunday | |
- cron: "34 5 * * 0" | |
workflow_dispatch: | |
jobs: | |
test: | |
if: github.event.pull_request.draft == false | |
name: Tests in IMAS container | |
runs-on: ubuntu-latest | |
container: | |
image: gitlab.eufus.psnc.pl:5050/containerization/imas/imas-installer/rockylinux8.6/ual | |
credentials: | |
password: ${{ secrets.GITLAB_PSNC_TOKEN }} | |
username: ${{ secrets.GITLAB_PSNC_USERNAME }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/checkout@v3 | |
with: | |
ssh-key: ${{ secrets.SSH_KEY_CONTAINERIZED_RUNS_REPO }} | |
repository: duqtools/containerized_runs | |
path: containerized_runs | |
- name: Set up containerized runs directory | |
run: | | |
echo "CONTAINERIZED_RUNS_DIR=`pwd`/containerized_runs" >> $GITHUB_ENV | |
- name: Python and Environment info | |
run: | | |
whoami | |
which python | |
python --version | |
pwd | |
ls -alh | |
- uses: actions/cache@v3 | |
with: | |
path: .imasenv | |
key: ${{ hashFiles('pyproject.toml') }} | |
- name: Create venv and setup duqtools | |
run: | | |
if ! test -d ".imasenv"; then | |
python3 -m venv .imasenv | |
. .imasenv/bin/activate | |
python -m pip install -U pip wheel | |
python -m pip install -e .[develop] | |
else | |
. .imasenv/bin/activate | |
fi | |
echo "VIRTUAL_ENV=${VIRTUAL_ENV}" >> $GITHUB_ENV | |
echo "PATH=${PATH}" >> $GITHUB_ENV | |
- name: Test if IMAS is really available | |
run: | | |
. /docker-entrypoint.sh | |
python -m imas | |
- name: Test with pytest | |
run: | | |
. /docker-entrypoint.sh | |
coverage run -p -m pytest | |
- name: Upload coverage data | |
uses: actions/upload-artifact@v3 | |
with: | |
name: covdata | |
path: .coverage.* | |
coverage: | |
name: Coverage | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install coverage[toml] | |
- name: Download coverage data | |
uses: actions/download-artifact@v3 | |
with: | |
name: covdata | |
- name: Combine | |
run: | | |
coverage combine | |
- name: Fix paths | |
shell: python | |
run: | | |
import sqlite3 | |
from pathlib import Path | |
cwd = str(Path.cwd()) | |
with sqlite3.connect('.coverage') as conn: | |
for (idx, path) in conn.execute('select * from file'): | |
new_path = path.replace('/__w/duqtools/duqtools', cwd) | |
q = 'update file set path = :new_path where id = :idx;' | |
conn.execute(q, {'idx': idx, 'new_path': new_path}) | |
conn.commit() | |
- name: Report coverage | |
run: | | |
coverage json | |
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])") | |
echo "total=$TOTAL" >> $GITHUB_ENV | |
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY | |
echo $'\n```' >> $GITHUB_STEP_SUMMARY | |
coverage report >> $GITHUB_STEP_SUMMARY | |
echo $'\n```' >> $GITHUB_STEP_SUMMARY | |
- name: Make badge | |
if: ${{ github.ref == 'refs/heads/main' }} | |
uses: schneegans/dynamic-badges-action@v1.6.0 | |
with: | |
auth: ${{ secrets.GIST_TOKEN }} | |
gistID: ea916a5b3c3d9bc59065a7304e4ca707 | |
filename: covbadge.json | |
label: Coverage | |
message: ${{ env.total }}% | |
minColorRange: 50 | |
maxColorRange: 90 | |
valColorRange: ${{ env.total }} |