|
| 1 | +name: medcat-trainer-v1 release-build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'medcat-trainer/v1.*.*' |
| 7 | + |
| 8 | +defaults: |
| 9 | + run: |
| 10 | + working-directory: ./v1/medcat-trainer |
| 11 | + |
| 12 | +jobs: |
| 13 | + # Test, build and publish client library |
| 14 | + test-and-publish-client: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout main |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + ref: "main" |
| 21 | + |
| 22 | + - name: Release Tag |
| 23 | + # 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 |
| 24 | + run: echo "RELEASE_VERSION=${GITHUB_REF##refs/*/}" >> $GITHUB_ENV |
| 25 | + |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v4 |
| 28 | + with: |
| 29 | + python-version: '3.10' |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: | |
| 33 | + python -m pip install --upgrade pip |
| 34 | + pip install requests pytest build twine |
| 35 | +
|
| 36 | + - name: Install client package in development mode |
| 37 | + run: | |
| 38 | + cd client |
| 39 | + pip install -e . |
| 40 | +
|
| 41 | + - name: Run client tests |
| 42 | + run: | |
| 43 | + cd client |
| 44 | + python -m pytest tests/ -v |
| 45 | +
|
| 46 | + - name: Build client package |
| 47 | + run: | |
| 48 | + cd client |
| 49 | + python -m build |
| 50 | +
|
| 51 | + - name: Publish production distribution to PyPI |
| 52 | + if: startsWith(github.ref, 'refs/tags') && ! github.event.release.prerelease |
| 53 | + |
| 54 | + with: |
| 55 | + # TODO CU-869a25n7e Use Trusted Platform Publisher based PyPI release |
| 56 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 57 | + packages_dir: v1/medcat-trainer/client/dist |
| 58 | + |
| 59 | + # Build and test webapp container |
| 60 | + build-and-push: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: test-and-publish-client |
| 63 | + steps: |
| 64 | + - name: Checkout main |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + ref: "main" |
| 68 | + |
| 69 | + - name: Release Tag |
| 70 | + # 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 |
| 71 | + run: echo "RELEASE_VERSION=${GITHUB_REF##refs/*/}" >> $GITHUB_ENV |
| 72 | + - name: Build |
| 73 | + env: |
| 74 | + IMAGE_TAG: ${{ env.RELEASE_VERSION }} |
| 75 | + run: | |
| 76 | + docker build -t cogstacksystems/medcat-trainer:$IMAGE_TAG webapp/. |
| 77 | + - name: Run Django Tests |
| 78 | + env: |
| 79 | + IMAGE_TAG: ${{ env.RELEASE_VERSION }} |
| 80 | + run: | |
| 81 | + # run tests |
| 82 | + docker run --rm cogstacksystems/medcat-trainer:$IMAGE_TAG python manage.py test |
| 83 | +
|
| 84 | + - name: Login to DockerHub |
| 85 | + uses: docker/login-action@v3 |
| 86 | + with: |
| 87 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 88 | + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} |
| 89 | + |
| 90 | + - name: Push to DockerHub |
| 91 | + env: |
| 92 | + IMAGE_TAG: ${{ env.RELEASE_VERSION }} |
| 93 | + run: | |
| 94 | + docker push cogstacksystems/medcat-trainer:$IMAGE_TAG |
| 95 | +
|
0 commit comments