Skip to content

Commit

Permalink
Select when to run deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
leavauchier committed Nov 13, 2024
1 parent bf907fe commit b98df14
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions .github/workflows/cicd_deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down Expand Up @@ -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 }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

0 comments on commit b98df14

Please sign in to comment.