Skip to content

Commit 4a407c0

Browse files
build(medcat-trainer): Consolidate github flows into one. Use standardised github actions for docker (#302)
* build(medcat-trainer): Use Docker actions for github CI builds * build(medcat-trainer): Create a docker image for every PR * build(medcat-trainer): Consolidate workflows into one file. Updating docker action
1 parent 9f89a22 commit 4a407c0

3 files changed

Lines changed: 80 additions & 325 deletions

File tree

.github/workflows/medcat-trainer_ci.yml

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
name: medcat-trainer ci-build
22

33
on:
4+
push:
5+
branches: [main]
6+
tags:
7+
- "medcat-trainer/v*.*.*"
48
pull_request:
59
paths:
610
- "medcat-trainer/**"
711
- ".github/workflows/medcat-trainer**"
812

13+
permissions:
14+
id-token: write
15+
916
defaults:
1017
run:
1118
working-directory: ./medcat-trainer
@@ -45,6 +52,23 @@ jobs:
4552
cd client
4653
python -m build
4754
55+
- name: Bump version for TestPyPI
56+
if: github.ref == 'refs/heads/main'
57+
run: sed -i "s/^version = .*/version = \"1.0.0.dev$(date +%s)\"/" client/pyproject.toml
58+
59+
- name: Publish dev distribution to Test PyPI
60+
uses: pypa/gh-action-pypi-publish@release/v1
61+
if: github.ref == 'refs/heads/main'
62+
with:
63+
repository_url: https://test.pypi.org/legacy/
64+
packages_dir: medcat-trainer/client/dist
65+
66+
- name: Publish production distribution to PyPI
67+
if: startsWith(github.ref, 'refs/tags') && ! github.event.release.prerelease
68+
uses: pypa/gh-action-pypi-publish@release/v1
69+
with:
70+
packages_dir: medcat-trainer/client/dist
71+
4872
test-frontend:
4973
runs-on: ubuntu-latest
5074
steps:
@@ -115,20 +139,67 @@ jobs:
115139
- test-client
116140
- test-frontend
117141
- test-backend
142+
outputs:
143+
image_version: ${{ steps.meta.outputs.version }}
118144
steps:
119145
- name: Checkout main
120146
uses: actions/checkout@v6
121147
with:
122148
ref: ${{ github.ref }}
123149

124-
- name: Build
125-
env:
126-
IMAGE_TAG: ${{ env.RELEASE_VERSION }}
127-
run: |
128-
docker build -t cogstacksystems/medcat-trainer:dev-latest webapp/.
150+
- name: Log in to Docker Hub
151+
uses: docker/login-action@v3
152+
with:
153+
username: ${{ secrets.DOCKERHUB_USERNAME }}
154+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
155+
156+
- name: Set up Docker Buildx
157+
uses: docker/setup-buildx-action@v3
158+
159+
- name: Extract metadata (tags, labels) for Docker MedCATtrainer
160+
id: meta
161+
uses: docker/metadata-action@v5
162+
with:
163+
images: cogstacksystems/medcat-trainer
164+
tags: |
165+
# set latest tag for default branch
166+
type=raw,value=latest,enable={{is_default_branch}}
167+
# Include all default tags
168+
type=schedule
169+
type=ref,event=branch
170+
type=ref,event=tag
171+
type=ref,event=pr
172+
type=sha
173+
# Create version tag based on tag prefix
174+
type=match,pattern=medcat-trainer/v(\d+\.\d+\.\d+),group=1
175+
flavor: latest=false
176+
177+
- name: Build Docker MedCATtrainer image for testing
178+
id: docker_build
179+
uses: docker/build-push-action@v6
180+
with:
181+
context: ./medcat-trainer/webapp/
182+
load: true # https://docs.docker.com/build/ci/github-actions/test-before-push/
183+
tags: cogstacksystems/medcat-trainer:test
184+
labels: ${{ steps.meta.outputs.labels }}
185+
cache-from: type=registry,ref=cogstacksystems/medcat-trainer:buildcache
186+
cache-to: type=registry,ref=cogstacksystems/medcat-trainer:buildcache,mode=max
187+
129188
- name: Run Django Tests
130-
env:
131-
IMAGE_TAG: ${{ env.RELEASE_VERSION }}
132189
run: |
133-
# run tests
134-
docker run --rm cogstacksystems/medcat-trainer:dev-latest python manage.py test
190+
# run tests using the built image
191+
docker run --rm cogstacksystems/medcat-trainer:test python manage.py test
192+
193+
- name: Push Docker MedCATtrainer image
194+
id: docker_build_push
195+
uses: docker/build-push-action@v6
196+
with:
197+
context: ./medcat-trainer/webapp/
198+
push: true
199+
tags: ${{ steps.meta.outputs.tags }}
200+
labels: ${{ steps.meta.outputs.labels }}
201+
cache-from: type=registry,ref=cogstacksystems/medcat-trainer:buildcache
202+
cache-to: type=registry,ref=cogstacksystems/medcat-trainer:buildcache,mode=max
203+
204+
- name: Image digest
205+
run: echo ${{ steps.docker_build.outputs.digest }}

.github/workflows/medcat-trainer_qa.yml

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)