Skip to content

feat(medcat-trainer): configurable remote model service timeout & pre… #127

feat(medcat-trainer): configurable remote model service timeout & pre…

feat(medcat-trainer): configurable remote model service timeout & pre… #127

name: medcat-trainer ci-build
on:
push:
branches: [main]
tags:
- "medcat-trainer/v*.*.*"
pull_request:
paths:
- "medcat-trainer/**"
- ".github/workflows/medcat-trainer**"
permissions:
id-token: write
defaults:
run:
working-directory: ./medcat-trainer
jobs:
# Test and build client library
test-client:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pytest build
- name: Install client package in development mode
run: |
cd client
pip install -e .
- name: Run client tests
run: |
cd client
python -m pytest tests/ -v
- name: Build client package
run: |
cd client
python -m build
- name: Bump version for TestPyPI
if: github.ref == 'refs/heads/main'
run: sed -i "s/^version = .*/version = \"1.0.0.dev$(date +%s)\"/" client/pyproject.toml
- name: Publish dev distribution to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: github.ref == 'refs/heads/main'
continue-on-error: true
with:
repository_url: https://test.pypi.org/legacy/
packages_dir: medcat-trainer/client/dist
- name: Publish production distribution to PyPI
if: startsWith(github.ref, 'refs/tags') && ! github.event.release.prerelease
uses: pypa/gh-action-pypi-publish@release/v1
continue-on-error: true
with:
packages_dir: medcat-trainer/client/dist
test-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
- name: Install dependencies
run: |
cd webapp/frontend
npm ci
- name: Run frontend tests
run: |
cd webapp/frontend
npm run test:unit
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
cd webapp
pip install -r requirements.txt
- name: Download spaCy model
run: |
python -m spacy download en_core_web_md
- name: Run Django tests
env:
DB_ENGINE: sqlite3
SECRET_KEY: test-secret-key
DEBUG: 1
run: |
cd webapp/api
python manage.py test
# Build and test webapp container
build-and-push:
runs-on: ubuntu-latest
needs:
- test-client
- test-frontend
- test-backend
outputs:
image_version: ${{ steps.meta.outputs.version }}
steps:
- name: Checkout main
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker MedCATtrainer
id: meta
uses: docker/metadata-action@v5
with:
images: cogstacksystems/medcat-trainer
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# Include all default tags
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
# Create version tag based on tag prefix
type=match,pattern=medcat-trainer/v(\d+\.\d+\.\d+),group=1
flavor: latest=false
- name: Build Docker MedCATtrainer image for testing
id: docker_build
uses: docker/build-push-action@v6
with:
context: ./medcat-trainer/webapp/
load: true # https://docs.docker.com/build/ci/github-actions/test-before-push/
tags: cogstacksystems/medcat-trainer:test
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=cogstacksystems/medcat-trainer:buildcache
cache-to: type=registry,ref=cogstacksystems/medcat-trainer:buildcache,mode=max
- name: Run Django Tests
run: |
# run tests using the built image
docker run --rm cogstacksystems/medcat-trainer:test python manage.py test
- name: Push Docker MedCATtrainer image
id: docker_build_push
uses: docker/build-push-action@v6
with:
context: ./medcat-trainer/webapp/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=cogstacksystems/medcat-trainer:buildcache
cache-to: type=registry,ref=cogstacksystems/medcat-trainer:buildcache,mode=max
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}