From 1cceb321f7246ad355f3d9192ab9224102a95768 Mon Sep 17 00:00:00 2001 From: Arthur Date: Sat, 13 Sep 2025 23:21:52 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liorer=20le=20workflow=20de=20d=C3=A9pl?= =?UTF-8?q?oiement=20en=20simplifiant=20la=20gestion=20du=20contenu=20du?= =?UTF-8?q?=20fichier=20.env=20et=20en=20nettoyant=20le=20code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0b20345..80ecd70 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,11 +3,12 @@ name: Deploy to VM Prod on: push: branches: - - main + - main jobs: deploy: runs-on: self-hosted + steps: - name: Checkout repository uses: actions/checkout@v3 @@ -15,28 +16,28 @@ jobs: - name: Deploy to production run: | REPO_NAME=${{ github.event.repository.name }} + ENV_CONTENT="${{ secrets.ENV_FILE || '' }}" - if [ -z "${{ secrets.ENV_FILE }}" ]; then - ENV_CONTENT="" - else - ENV_CONTENT="${{ secrets.ENV_FILE }}" - fi + ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} bash -s << 'EOF' + REPO_NAME='"$REPO_NAME"' + ENV_CONTENT='"$ENV_CONTENT"' - ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} " mkdir -p /srv/$REPO_NAME cd /srv/$REPO_NAME + # Supprime tout si le repo n'existe pas encore if [ ! -d .git ]; then - rm -rf ./* # vide le dossier si nécessaire + rm -rf ./* git clone https://github.com/arthur-pbty-labs/$REPO_NAME . else git reset --hard git pull origin main fi - if [ -n \"$ENV_CONTENT\" ]; then - echo \"$ENV_CONTENT\" > .env + # Crée .env seulement si contenu non vide + if [ -n "$ENV_CONTENT" ]; then + echo "$ENV_CONTENT" > .env fi docker compose up -d --build - " +EOF