|
| 1 | + |
| 2 | +name: cicd_deploy |
| 3 | + |
| 4 | +on: |
| 5 | + # Also run when the pull request merges (which generates a push) |
| 6 | + # So that we can tag the docker image appropriately. |
| 7 | + push: |
| 8 | + tags: [ 'v*.*.*' ] |
| 9 | + |
| 10 | +env: |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + REGISTRY: ghcr.io |
| 13 | + TEST_TAG: ${{ github.repository }}:test |
| 14 | + |
| 15 | +jobs: |
| 16 | + deploy_docker: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout branch |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Build the Docker image |
| 28 | + id: build |
| 29 | + uses: docker/build-push-action@v6 |
| 30 | + with: |
| 31 | + load: true |
| 32 | + tags: ${{ env.TEST_TAG }} |
| 33 | + |
| 34 | + # run the test on the docker image |
| 35 | + - name: Run tests in docker image |
| 36 | + run: > |
| 37 | + docker run |
| 38 | + ${{ env.TEST_TAG }} |
| 39 | + python -m pytest -s |
| 40 | + --log-cli-level=DEBUG |
| 41 | + --log-format="%(asctime)s %(levelname)s %(message)s" |
| 42 | + --log-date-format="%Y-%m-%d %H:%M:%S" |
| 43 | + -m "not functional_test" |
| 44 | +
|
| 45 | + # Login against a Docker registry except on PR |
| 46 | + # https://github.com/docker/login-action |
| 47 | + - name: Log into registry ${{ env.REGISTRY }} |
| 48 | + if: github.event_name != 'pull_request' |
| 49 | + uses: docker/login-action@v3.4 |
| 50 | + with: |
| 51 | + registry: ${{ env.REGISTRY }} |
| 52 | + username: ${{ github.actor }} |
| 53 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + # Extract metadata (tags, labels) for Docker |
| 56 | + # https://github.com/docker/metadata-action |
| 57 | + - name: Extract Docker metadata |
| 58 | + if: github.event_name != 'pull_request' |
| 59 | + id: meta |
| 60 | + uses: docker/metadata-action@v5 |
| 61 | + with: |
| 62 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 63 | + |
| 64 | + # Build a Docker image with Buildx (don't on PR) |
| 65 | + # https://github.com/docker/build-push-action |
| 66 | + - name: Build and push Docker image |
| 67 | + if: github.event_name != 'pull_request' |
| 68 | + id: build-and-push |
| 69 | + uses: docker/build-push-action@v6 |
| 70 | + with: |
| 71 | + context: . |
| 72 | + push: true |
| 73 | + tags: ${{ steps.meta.outputs.tags }} |
| 74 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments