From b98df14ebfdfa3619cb7b72a0bdb36fe25c31882 Mon Sep 17 00:00:00 2001 From: Lea Vauchier Date: Wed, 13 Nov 2024 15:19:00 +0100 Subject: [PATCH] Select when to run deployment --- .github/workflows/cicd_deploy.yml | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/cicd_deploy.yml b/.github/workflows/cicd_deploy.yml index c648cc2..548c3da 100644 --- a/.github/workflows/cicd_deploy.yml +++ b/.github/workflows/cicd_deploy.yml @@ -1,10 +1,12 @@ name: cicd_deploy on: - pull_request: - branches: - - main - - dev + push: + # Run deployment tests on every new version tag and every push to main and dev: + # Run actual deploymment only on push to main and tags + branches: [ "main", "dev" ] + tags: + - v*.*.* env: IMAGE_NAME: ${{ github.repository }} @@ -42,45 +44,46 @@ jobs: - name: Set version number run: | - echo "VERSION=v$(python -m lidro.version)" >> $GITHUB_ENV + echo "VERSION=v$(python -m lidro._version)" >> $GITHUB_ENV - name: Check tag and version number consistency - if: ${{ github.event_name == 'tag' }} + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') run: | if [[ ${{ github.ref_name }} == ${{ env.VERSION }} ]] then - echo "OK: Tag name and VERSION.md (${{ env.VERSION }}) version number (${{ github.ref_name }}) match" + echo "OK: Tag name and _version.py (${{ env.VERSION }}) version number (${{ github.ref_name }}) match" else - echo "NOK: Tag name and VERSION.md (${{ env.VERSION }}) version number (${{ github.ref_name }}) don't match" + echo "NOK: Tag name and _version.py (${{ env.VERSION }}) version number (${{ github.ref_name }}) don't match" exit 1 fi - # Login against a Docker registry except on PR + # Login against a Docker registry except on dev branch # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' uses: docker/login-action@v2 + if: ${{ github.ref_name != 'dev' }} with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} + password: ${{ secrets.GITHUB_TOKEN }} - # Extract metadata (tags, labels) for Docker + # Extract metadata (tags, labels) for Docker except on dev branch # https://github.com/docker/metadata-action - name: Extract Docker metadata - id: meta + id: metadata + if: ${{ github.ref_name != 'dev' }} uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # Build and push Docker image with Buildx (don't on PR) + # Build and push Docker image with Buildx except on dev branch # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push - if: ${{ github.event_name != 'pull_request' }} + if: ${{ github.ref_name != 'dev' }} uses: docker/build-push-action@v5 with: context: . push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} \ No newline at end of file