From ea050c1cacc37ed32e568b74fe7810c248e59be0 Mon Sep 17 00:00:00 2001 From: alhendrickson <159636032+alhendrickson@users.noreply.github.com.> Date: Wed, 21 Jan 2026 11:06:42 +0000 Subject: [PATCH 1/3] build(medcat-trainer): Use Docker actions for github CI builds --- .github/workflows/medcat-trainer_ci.yml | 65 +++++++++++++++++++++---- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/.github/workflows/medcat-trainer_ci.yml b/.github/workflows/medcat-trainer_ci.yml index f4037c760..6d301621f 100644 --- a/.github/workflows/medcat-trainer_ci.yml +++ b/.github/workflows/medcat-trainer_ci.yml @@ -115,20 +115,67 @@ jobs: - 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: Build - env: - IMAGE_TAG: ${{ env.RELEASE_VERSION }} - run: | - docker build -t cogstacksystems/medcat-trainer:dev-latest webapp/. + - 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 + 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: Run Django Tests - env: - IMAGE_TAG: ${{ env.RELEASE_VERSION }} run: | - # run tests - docker run --rm cogstacksystems/medcat-trainer:dev-latest python manage.py test + # run tests using the built image + docker run --rm cogstacksystems/medcat-trainer@${{ steps.docker_build.outputs.digest }} python manage.py test + + - name: Push Docker MedCATtrainer image + id: docker_build_push + uses: docker/build-push-action@v6 + with: + context: ./medcat-trainer/webapp/ + load: 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 }} From 600a682f40494ede38628f25abcd42c101a41826 Mon Sep 17 00:00:00 2001 From: alhendrickson <159636032+alhendrickson@users.noreply.github.com.> Date: Wed, 21 Jan 2026 11:22:36 +0000 Subject: [PATCH 2/3] build(medcat-trainer): Consolidate workflows into one file. Updating docker action --- .github/workflows/medcat-trainer_ci.yml | 30 ++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/medcat-trainer_ci.yml b/.github/workflows/medcat-trainer_ci.yml index 6d301621f..ae776a729 100644 --- a/.github/workflows/medcat-trainer_ci.yml +++ b/.github/workflows/medcat-trainer_ci.yml @@ -1,11 +1,18 @@ 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 @@ -45,6 +52,23 @@ jobs: 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' + 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 + with: + packages_dir: medcat-trainer/client/dist + test-frontend: runs-on: ubuntu-latest steps: @@ -156,7 +180,7 @@ jobs: with: context: ./medcat-trainer/webapp/ load: true - tags: ${{ steps.meta.outputs.tags }} + 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 @@ -164,14 +188,14 @@ jobs: - name: Run Django Tests run: | # run tests using the built image - docker run --rm cogstacksystems/medcat-trainer@${{ steps.docker_build.outputs.digest }} python manage.py test + 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/ - load: true + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=cogstacksystems/medcat-trainer:buildcache From afc8faf893fa14e57cdd7d2ce3a710c50a431b12 Mon Sep 17 00:00:00 2001 From: alhendrickson <159636032+alhendrickson@users.noreply.github.com.> Date: Wed, 21 Jan 2026 11:34:15 +0000 Subject: [PATCH 3/3] build(medcat-trainer): Consolidate github workflows into one --- .github/workflows/medcat-trainer_ci.yml | 2 +- .github/workflows/medcat-trainer_qa.yml | 153 ----------------- .github/workflows/medcat-trainer_release.yml | 163 ------------------- 3 files changed, 1 insertion(+), 317 deletions(-) delete mode 100644 .github/workflows/medcat-trainer_qa.yml delete mode 100644 .github/workflows/medcat-trainer_release.yml diff --git a/.github/workflows/medcat-trainer_ci.yml b/.github/workflows/medcat-trainer_ci.yml index ae776a729..ec2679437 100644 --- a/.github/workflows/medcat-trainer_ci.yml +++ b/.github/workflows/medcat-trainer_ci.yml @@ -179,7 +179,7 @@ jobs: uses: docker/build-push-action@v6 with: context: ./medcat-trainer/webapp/ - load: true + 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 diff --git a/.github/workflows/medcat-trainer_qa.yml b/.github/workflows/medcat-trainer_qa.yml deleted file mode 100644 index 55705f211..000000000 --- a/.github/workflows/medcat-trainer_qa.yml +++ /dev/null @@ -1,153 +0,0 @@ -name: medcat-trainer qa-build - -on: - push: - branches: [main] - -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: "main" - - - 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: Bump version for TestPyPI - run: sed -i "s/^version = .*/version = \"1.0.0.dev$(date +%s)\"/" client/pyproject.toml - - - name: Build client package - run: | - cd client - python -m build - - - name: Publish dev distribution to Test PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - repository_url: https://test.pypi.org/legacy/ - 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: "main" - - - 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 - steps: - - name: Checkout main - uses: actions/checkout@v6 - with: - ref: "main" - - - name: Build - run: | - docker build -t cogstacksystems/medcat-trainer:latest webapp/. - - - name: Run Django Tests - env: - IMAGE_TAG: latest - run: | - # run tests - docker run --rm cogstacksystems/medcat-trainer:latest python manage.py test - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Push to DockerHub - run: | - docker push cogstacksystems/medcat-trainer:latest diff --git a/.github/workflows/medcat-trainer_release.yml b/.github/workflows/medcat-trainer_release.yml deleted file mode 100644 index 4812a43ca..000000000 --- a/.github/workflows/medcat-trainer_release.yml +++ /dev/null @@ -1,163 +0,0 @@ -name: medcat-trainer release-build - -on: - push: - tags: - - "medcat-trainer/v*.*.*" - -permissions: - id-token: write - -defaults: - run: - working-directory: ./medcat-trainer - -jobs: - # Test, build and publish client library - test-and-publish-client: - runs-on: ubuntu-latest - steps: - - name: Checkout main - uses: actions/checkout@v6 - with: - ref: "main" - - - name: Release Tag - # If GITHUB_REF=refs/tags/medcat-trainer/v0.1.2, this returns v0.1.2. Note it's including the "v" though it probably shouldnt - run: echo "RELEASE_VERSION=${GITHUB_REF##refs/*/}" >> $GITHUB_ENV - - - 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 twine - - - 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: Publish production distribution to PyPI - if: startsWith(github.ref, 'refs/tags') && ! github.event.release.prerelease - uses: pypa/gh-action-pypi-publish@release/v1 - with: - packages_dir: medcat-trainer/client/dist - - test-frontend: - runs-on: ubuntu-latest - steps: - - name: Checkout main - uses: actions/checkout@v6 - with: - ref: "main" - - - 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: "main" - - - 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-frontend - - test-backend - steps: - - name: Checkout main - uses: actions/checkout@v6 - with: - ref: "main" - - - name: Release Tag - # If GITHUB_REF=refs/tags/medcat-trainer/v0.1.2, this returns v0.1.2. Note it's including the "v" though it probably shouldnt - run: echo "RELEASE_VERSION=${GITHUB_REF##refs/*/}" >> $GITHUB_ENV - - name: Build - env: - IMAGE_TAG: ${{ env.RELEASE_VERSION }} - run: | - docker build -t cogstacksystems/medcat-trainer:$IMAGE_TAG -t cogstacksystems/medcat-trainer:latest webapp/. - - name: Run Django Tests - env: - IMAGE_TAG: ${{ env.RELEASE_VERSION }} - run: | - # run tests - docker run --rm cogstacksystems/medcat-trainer:$IMAGE_TAG python manage.py test - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Push to DockerHub - env: - IMAGE_TAG: ${{ env.RELEASE_VERSION }} - run: | - docker push cogstacksystems/medcat-trainer:$IMAGE_TAG - docker push cogstacksystems/medcat-trainer:latest