Skip to content

Build IMAS in action to run tests #425

Build IMAS in action to run tests

Build IMAS in action to run tests #425

Workflow file for this run

name: Build IMAS and run tests
on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- ready_for_review
push:
branches:
- main
workflow_dispatch:
jobs:
test:
if: github.event.pull_request.draft == false
name: ${{ matrix.os }}, ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest']
python-version: ['3.9']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.cfg') }}
- uses: actions/checkout@v3
- name: Install libraries
run: |
sudo apt-get install -y xsltproc libhdf5-dev libblitz0-dev default-jre libboost-filesystem-dev
- name: Download data-dictionary
run: |
username="smeetss"
password="${{ secrets.GIT_ITER_ORG_HTTPS_KEY }}"
git clone https://$username:$password@git.iter.org/scm/imas/data-dictionary.git imas/data-dictionary
- name: Download access-layer
run: |
username="smeetss"
password="${{ secrets.GIT_ITER_ORG_HTTPS_KEY }}"
git clone --depth=1 https://$username:$password@git.iter.org/scm/imas/access-layer.git imas/access-layer
- name: Download saxon9he.jar
run: |
mkdir saxon9he
cd saxon9he
curl -L https://sourceforge.net/projects/saxon/files/Saxon-HE/9.9/SaxonHE9-9-1-7J.zip/download -o saxon9he.zip
unzip saxon9he.zip
- name: Install mdsplus
run: |
curl -fsSL http://www.mdsplus.org/dist/mdsplus.gpg.key | sudo apt-key add -
sudo sh -c "echo 'deb [arch=amd64] http://www.mdsplus.org/dist/Ubuntu22/repo MDSplus stable' > /etc/apt/sources.list.d/mdsplus.list"
sudo apt-get update
sudo apt-get install -y mdsplus mdsplus-devel
- name: Build imas
run: |
cd imas
ln -s ../testing/build_imas_script.sh .
./build_imas_script.sh
cd ..
- name: Test imas import
run: |
cat ./imas/source_me.sh
. ./imas/source_me.sh
python -c 'import imas'
- uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_KEY_CONTAINERIZED_RUNS_REPO }}
repository: duqtools/containerized_runs
path: containerized_runs
- name: Put the IMAS db in the right location
run: |
mkdir -p /opt/imas/shared
mkdir -p ${HOME}/public/
ln -s `pwd`/containerized_runs/imasdb /opt/imas/shared/
ln -s `pwd`/containerized_runs/imasdb ${HOME}/public/imasdb
echo `pwd`/containerized_runs/imasdb
echo ${HOME}/public/imasdb
- name: Create venv and setup duqtools
run: |
if ! test -d ".imasenv"; then
python3 -m venv .imasenv
. .imasenv/bin/activate
python -m pip install wheel
python -m pip install -e .[develop]
else
. .imasenv/bin/activate
python -m pip install -e .[develop]
fi
echo "VIRTUAL_ENV=${VIRTUAL_ENV}" >> $GITHUB_ENV
echo "PATH=${PATH}" >> $GITHUB_ENV
- name: Test paths
shell: python
run: |
from duqtools.api import ImasHandle
print(ImasHandle.from_string('root/test/11111/6666').path())
print(ImasHandle.from_string('test/11111/4444').path())
- name: Test with pytest
run: |
. ./imas/source_me.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
- 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 }}
sonar:
name: SonarCloud Upload
runs-on: ubuntu-latest
needs: test
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
with:
# Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}