From 9fc1f6f9b4b81286f2af2ff97f222b7cbc1b679b Mon Sep 17 00:00:00 2001 From: isUnknown Date: Mon, 4 May 2026 15:01:57 +0200 Subject: [PATCH] =?UTF-8?q?ci=20:=20ajout=20du=20workflow=20Forgejo=20depl?= =?UTF-8?q?oy=20(preprod=20=E2=86=92=20PREPRODUCTION=5FHOST,=20main=20?= =?UTF-8?q?=E2=86=92=20PRODUCTION=5FHOST)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- .forgejo/workflows/deploy.yml | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .forgejo/workflows/deploy.yml diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml new file mode 100644 index 0000000..a9da04a --- /dev/null +++ b/.forgejo/workflows/deploy.yml @@ -0,0 +1,83 @@ +name: Deploy + +on: + push: + branches: + - main + - preprod + +jobs: + deploy: + name: Deploy + runs-on: docker + container: + image: forgejo-ci-php:latest + steps: + - name: Checkout code + run: | + git clone --depth 50 --branch ${{ github.ref_name }} https://oauth2:${{ github.token }}@forge.studio-variable.com/${{ github.repository }}.git . + + - name: Install dependencies + run: | + composer install --no-dev --optimize-autoloader + + - name: Set deploy host + id: host + shell: bash + run: | + if [ "${{ github.ref_name }}" = "preprod" ]; then + echo "ftp_host=${{ secrets.PREPRODUCTION_HOST }}" >> $GITHUB_OUTPUT + else + echo "ftp_host=${{ secrets.PRODUCTION_HOST }}" >> $GITHUB_OUTPUT + fi + + - name: Deploy via FTP + env: + USERNAME: ${{ secrets.USERNAME }} + PASSWORD: ${{ secrets.PASSWORD }} + FTP_HOST: ${{ steps.host.outputs.ftp_host }} + shell: bash + run: | + BEFORE="${{ github.event.before }}" + ZEROS="0000000000000000000000000000000000000000" + + if [ "$BEFORE" != "$ZEROS" ] && git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then + INCREMENTAL=true + echo "=== Mode incrémental — fichiers modifiés depuis $BEFORE ===" + git diff --name-status "$BEFORE" HEAD + echo "============================================================" + else + INCREMENTAL=false + echo "=== Mode full mirror (premier push ou BEFORE hors portée) ===" + fi + + { + echo "set ftp:ssl-allow no" + echo "set cmd:fail-exit no" + echo "open -u $USERNAME,$PASSWORD $FTP_HOST" + + if $INCREMENTAL; then + git diff --name-status "$BEFORE" HEAD | while IFS=$'\t' read -r status file; do + case "$file" in local/*|site/accounts/*|site/cache/*|site/sessions/*) continue ;; esac + if [ "$status" = "D" ]; then + echo "rm -f \"$file\"" + elif [ -f "$file" ]; then + echo "mkdir -p \"$(dirname "$file")\"" + echo "put \"$file\" -o \"$file\"" + fi + done + else + echo "mirror --reverse --verbose --ignore-time --parallel=10 -x local/ assets assets" + echo "mirror --reverse --verbose --ignore-time --parallel=10 -x accounts/ -x cache/ -x sessions/ site site" + fi + + echo "mirror --reverse --verbose --ignore-time --parallel=10 kirby kirby" + echo "mirror --reverse --verbose --ignore-time --parallel=10 vendor vendor" + echo "quit" + } > /tmp/lftp-script.txt + + echo "=== Script lftp généré ===" + cat /tmp/lftp-script.txt + echo "==========================" + + lftp -f /tmp/lftp-script.txt