76 lines
2.5 KiB
YAML
76 lines
2.5 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
name: Deploy to Production
|
|
runs-on: docker
|
|
container:
|
|
image: forgejo-ci-php:latest
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
git clone --depth 50 --branch main https://oauth2:${{ github.token }}@forge.studio-variable.com/${{ github.repository }}.git .
|
|
|
|
- name: Deploy via FTP
|
|
env:
|
|
USERNAME: ${{ secrets.USERNAME }}
|
|
PASSWORD: ${{ secrets.PASSWORD }}
|
|
PREPRODUCTION_HOST: ${{ secrets.PREPRODUCTION_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 $PREPRODUCTION_HOST"
|
|
|
|
if $INCREMENTAL; then
|
|
git diff --name-status "$BEFORE" HEAD | while IFS=$'\t' read -r status file; do
|
|
# Ignorer les fichiers CI et les sources sass
|
|
case "$file" in
|
|
.forgejo/*) continue ;;
|
|
*.scss) continue ;;
|
|
esac
|
|
# N'envoyer que index.html et le dossier assets/
|
|
case "$file" in
|
|
index.html|assets/*) ;;
|
|
*) 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
|
|
# Premier déploiement : full mirror
|
|
echo "put index.html -o index.html"
|
|
echo "mirror --reverse --verbose --ignore-time --parallel=10 --exclude-glob=*.scss assets assets"
|
|
fi
|
|
|
|
echo "quit"
|
|
} > /tmp/lftp-script.txt
|
|
|
|
echo "=== Script lftp généré ==="
|
|
cat /tmp/lftp-script.txt
|
|
echo "=========================="
|
|
|
|
lftp -f /tmp/lftp-script.txt
|