|
1 | 1 | name: medcat-trainer ci-build |
2 | 2 |
|
3 | 3 | on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: |
| 7 | + - "medcat-trainer/v*.*.*" |
4 | 8 | pull_request: |
5 | 9 | paths: |
6 | 10 | - "medcat-trainer/**" |
7 | 11 | - ".github/workflows/medcat-trainer**" |
8 | 12 |
|
| 13 | +permissions: |
| 14 | + id-token: write |
| 15 | + |
9 | 16 | defaults: |
10 | 17 | run: |
11 | 18 | working-directory: ./medcat-trainer |
|
45 | 52 | cd client |
46 | 53 | python -m build |
47 | 54 |
|
| 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 | + |
48 | 72 | test-frontend: |
49 | 73 | runs-on: ubuntu-latest |
50 | 74 | steps: |
@@ -115,20 +139,67 @@ jobs: |
115 | 139 | - test-client |
116 | 140 | - test-frontend |
117 | 141 | - test-backend |
| 142 | + outputs: |
| 143 | + image_version: ${{ steps.meta.outputs.version }} |
118 | 144 | steps: |
119 | 145 | - name: Checkout main |
120 | 146 | uses: actions/checkout@v6 |
121 | 147 | with: |
122 | 148 | ref: ${{ github.ref }} |
123 | 149 |
|
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 | + |
129 | 188 | - name: Run Django Tests |
130 | | - env: |
131 | | - IMAGE_TAG: ${{ env.RELEASE_VERSION }} |
132 | 189 | 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 }} |
0 commit comments