WIP: Add ci workflow to run unit tests on pr or merge into main branches S… #13
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: CI | |
on: | |
# Run on creating or updating a PR | |
pull_request: | |
types: [opened, synchronize, reopened] | |
# And pushing to the trunk or fix branches | |
push: | |
branches: | |
- trunk | |
- 'fix*' | |
jobs: | |
build: | |
# Run on ubuntu, mac and windows for python 3.8 (in AMS python stack) and 3.11 | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: ["3.8", "3.11"] | |
steps: | |
# Checkout and copy into SCM namespace | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Move Repo To SCM Namespace and Set PYTHONPATH | |
if: runner.os != 'Windows' | |
run: | | |
mkdir -p scm/plams | |
find . -mindepth 1 -maxdepth 1 -not -name 'scm' -not -name '.*' -exec mv {} scm/plams/ \; | |
echo "PYTHONPATH=$(pwd):$PYTHONPATH" >> $GITHUB_ENV | |
- name: Move Repo To SCM Namespace and Set PYTHONPATH (Windows) | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
New-Item -Path scm\plams -ItemType Directory -Force | |
Get-ChildItem -Directory | Where-Object { $_.Name -ne 'scm' } | ForEach-Object { | |
Move-Item -Path $_.FullName -Destination scm\plams | |
} | |
Get-ChildItem -File | ForEach-Object { | |
Move-Item -Path $_.FullName -Destination scm\plams | |
} | |
echo "PYTHONPATH=$(pwd);$env:PYTHONPATH" >> $env:GITHUB_ENV | |
# Set up python env | |
- name: Set Up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Display Python Version | |
run: python -c "import sys; print(sys.version)" | |
- name: Install Dependencies | |
working-directory: scm/plams | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pytest | |
pip install coverage | |
# Run tests and calculate code coverage | |
- name: Run Unit Tests | |
working-directory: scm/plams | |
run: | | |
echo "PYTHONPATH is $PYTHONPATH" | |
pwd | |
coverage run -m pytest unit_tests | |
- name: Evaluate Coverage | |
working-directory: scm/plams | |
run: coverage report --omit="unit_tests/*" -i --fail-under=30 |