Github CD
This commit is contained in:
@@ -1,45 +1,17 @@
|
|||||||
name: Deploy to production
|
name: Deploy to production
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_run:
|
push:
|
||||||
workflows:
|
tags:
|
||||||
- Docker Image CI
|
- '*'
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-and-deploy:
|
deploy:
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: prod
|
environment: prod
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ github.event.workflow_run.head_sha }}
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Check if tag is from prod branch
|
|
||||||
id: check
|
|
||||||
run: |
|
|
||||||
TAG_REF="${{ github.event.workflow_run.head_branch }}"
|
|
||||||
echo "Tag/Branch: $TAG_REF"
|
|
||||||
|
|
||||||
# Récupère les branches contenant ce commit
|
|
||||||
BRANCHES=$(git branch -r --contains ${{ github.event.workflow_run.head_sha }})
|
|
||||||
echo "Branches containing this commit: $BRANCHES"
|
|
||||||
|
|
||||||
if echo "$BRANCHES" | grep -q "origin/prod"; then
|
|
||||||
echo "is_prod=true" >> $GITHUB_OUTPUT
|
|
||||||
echo "✅ Tag is from prod branch - will deploy"
|
|
||||||
else
|
|
||||||
echo "is_prod=false" >> $GITHUB_OUTPUT
|
|
||||||
echo "❌ Tag is not from prod branch - skipping deployment"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Deploy to production server
|
- name: Deploy to production server
|
||||||
if: steps.check.outputs.is_prod == 'true'
|
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.PROD_SSH_HOST }}
|
host: ${{ secrets.PROD_SSH_HOST }}
|
||||||
|
|||||||
@@ -18,25 +18,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 0 # required to verify branch
|
|
||||||
|
|
||||||
- name: Check which branch the tag belongs to
|
|
||||||
id: check_branch
|
|
||||||
run: |
|
|
||||||
# Trouve les branches qui contiennent ce tag
|
|
||||||
BRANCHES=$(git branch -r --contains ${{ github.ref }})
|
|
||||||
|
|
||||||
if echo "$BRANCHES" | grep -q "origin/main"; then
|
|
||||||
echo "branch=main" >> $GITHUB_OUTPUT
|
|
||||||
echo "LATEST_TAG=latest" >> $GITHUB_ENV
|
|
||||||
elif echo "$BRANCHES" | grep -q "origin/prod"; then
|
|
||||||
echo "branch=prod" >> $GITHUB_OUTPUT
|
|
||||||
echo "LATEST_TAG=latest-prod" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "branch=other" >> $GITHUB_OUTPUT
|
|
||||||
echo "LATEST_TAG=" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
@@ -58,4 +39,4 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
ghcr.io/${{ env.lower_actor }}/aperisolve:${{ env.RELEASE_VERSION }}
|
ghcr.io/${{ env.lower_actor }}/aperisolve:${{ env.RELEASE_VERSION }}
|
||||||
${{ env.LATEST_TAG && format('ghcr.io/{0}/aperisolve:{1}', env.lower_actor, env.LATEST_TAG) || '' }}
|
ghcr.io/${{ env.lower_actor }}/aperisolve:latest-prod
|
||||||
Reference in New Issue
Block a user