Skip to content

Commit

Permalink
Run tests in GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Jul 27, 2024
1 parent 977a07e commit e12f38b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
import os
import itertools
registries = ['docker.io', 'ghcr.io']
repos = ['${{ github.repository }}'.lower()]
if '${{ github.ref_type }}' == 'branch':
Expand All @@ -40,11 +40,11 @@ jobs:
def join_tag(t):
registry, repo, tag = t
return f'{registry}/{repo}:{tag}'

product = itertools.product(registries, repos, tags)
tags_csv = ','.join(map(join_tag, product))
push = 'true' if tags_csv else 'false'
push = 'true' if len(tags) >= 2 else 'false'

with open(os.environ['GITHUB_OUTPUT'], 'a') as out:
out.write(f'tags={tags_csv}\n')
out.write(f'push={push}\n')
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Test

on:
push:
branches: [ master ]
paths:
- '.github/workflows/test.yml'
- '**.py'
pull_request:

jobs:
test:
name: Tests
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Spin up ChRIS
uses: FNNDSC/miniChRIS-docker@master
with:
# for testing, we need to create plugin instances, but we don't need the plugins to actually run.
services: chris
- name: Build
run: docker compose build
- name: Test
id: test
continue-on-error: true # we want to upload coverage, even on failure
run: docker compose run -T test pytest --color=yes --cov=chrisomatic --cov-report=xml
- name: Copy coverage.xml from container
run: docker cp "$(docker compose ps -a test -q | tail -n 1):/app/coverage.xml" coverage.xml
- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: unittests
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Run example
run: |
set +e
docker compose run -T test sh -c '
export PYTHONPATH=$PWD
/app/scripts/create_example.py | coverage run -m chrisomatic.cli -
'
if [ "$?" = '0' ]; then
echo '::error::Expected run to fail, but it did not.'
exit 1
fi
docker compose run -T test coverage xml -o - > simulation_coverage.xml
- name: Upload simulation coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./simulation_coverage.xml
flags: simulation
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Version](https://img.shields.io/docker/v/fnndsc/chrisomatic?sort=semver)](https://hub.docker.com/r/fnndsc/chrisomatic)
[![MIT License](https://img.shields.io/github/license/fnndsc/chrisomatic)](https://github.com/FNNDSC/chrisomatic/blob/master/LICENSE)
[![Build](https://github.com/FNNDSC/chrisomatic/actions/workflows/build.yml/badge.svg)](https://github.com/FNNDSC/chrisomatic/actions)
[![codecov](https://codecov.io/gh/FNNDSC/chrisomatic/graph/badge.svg?token=U2UPF27JEV)](https://codecov.io/gh/FNNDSC/chrisomatic)

`chrisomatic` is a tool for automatic administration of _ChRIS_ backends.
It is particularly useful for the recreation of setups for testing or development,
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
dev:
test:
build:
context: .
dockerfile: dev.Dockerfile
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ requires-python = "== 3.12.3"
chrisomatic = "chrisomatic.cli.typer:app"

[tool.rye.scripts]
test = "docker compose run --rm --build dev"
simulate = "docker compose run --rm --build dev /app/scripts/simulation.sh"
test = "docker compose run --rm --build test"
simulate = "docker compose run --rm --build test /app/scripts/simulation.sh"

[build-system]
requires = ["hatchling"]
Expand All @@ -33,6 +33,7 @@ managed = true
dev-dependencies = [
"pytest>=8.3.2",
"pytest-asyncio>=0.23.8",
"pytest-cov>=5.0.0",
]

[tool.hatch.metadata]
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ casefy==0.1.7
# via pyserde
click==8.1.7
# via typer
coverage==7.6.0
# via pytest-cov
frozenlist==1.4.1
# via aiohttp
# via aiosignal
Expand Down Expand Up @@ -64,7 +66,9 @@ pyserde==0.19.3
# via chrisomatic
pytest==8.3.2
# via pytest-asyncio
# via pytest-cov
pytest-asyncio==0.23.8
pytest-cov==5.0.0
python-dateutil==2.9.0.post0
# via strictyaml
rich==13.7.1
Expand Down
2 changes: 1 addition & 1 deletion src/chrisomatic/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from __version__ import __version__
from chrisomatic.__version__ import __version__

0 comments on commit e12f38b

Please sign in to comment.