Repository navigation
89 lines (86 loc) · 3.36 KB
/
Copy pathdeploy.yml
File metadata and controls
89 lines (86 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Deploy React to Hostinger
on:
repository_dispatch: # C'est le signal de WordPress !
types: [cms_update]
workflow_dispatch: # Permet de redeployer a la main depuis l'onglet Actions
inputs:
branch:
description: "Branche a deployer EN PRODUCTION (il n'y a pas de staging)"
type: choice
default: main
options:
- main
- develop
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # Annule le build précédent si un nouveau est lancé
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# La prod est deployee depuis main, alors que ce workflow est lu depuis la
# branche par defaut (develop) lors d'un repository_dispatch. Sur ce
# declencheur inputs est vide, d'ou le repli sur main.
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch || 'main' }}
- name: Show deployed branch
run: echo "Deploiement de ${{ inputs.branch || 'main' }} vers la production"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Build Gatsby site
run: |
# Delais en secondes entre tentatives (backoff croissant) : le blocage
# reseau intermittent cote hebergeur (protection anti-bot Hostinger)
# peut durer plusieurs minutes, d'ou des delais plus longs qu'un simple
# retry rapide.
delays=(120 300 600)
attempt=1
total=$((${#delays[@]} + 1))
while true; do
if npm run build; then
exit 0
fi
if [ "$attempt" -eq "$total" ]; then
echo "Build failed after ${attempt} attempts."
exit 1
fi
delay=${delays[$((attempt - 1))]}
echo "Build attempt ${attempt} failed. Waiting ${delay} seconds before retrying..."
sleep "$delay"
attempt=$((attempt + 1))
done
env:
WPGRAPHQL_URL: ${{ secrets.WPGRAPHQL_URL }}
SITE_URL: ${{ secrets.SITE_URL }}
NODE_ENV: production
GOOGLE_PLACES_API_KEY: ${{ secrets.GOOGLE_PLACES_API_KEY }}
GOOGLE_PLACE_ID: ${{ secrets.GOOGLE_PLACE_ID }}
- name: List Output
run: ls -al public
- name: Deploy via SSH (Hostinger)
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOSTINGER_IP }}
username: ${{ secrets.HOSTINGER_USER }}
key: ${{ secrets.HOSTINGER_SSH_KEY }}
port: 65002 # Port standard SSH chez Hostinger (vérifiez le vôtre dans le hPanel)
source: "public/*"
target: "/home/u566000124/domains/thatmuch.fr/public_html"
strip_components: 1 # Pour éviter de créer un dossier "dist" sur le serveur
- name: Purge Hostinger Cache
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOSTINGER_IP }}
username: ${{ secrets.HOSTINGER_USER }}
key: ${{ secrets.HOSTINGER_SSH_KEY }}
port: 65002
script: |
# Commande pour vider le cache si vous utilisez un plugin de cache ou OpenLiteSpeed
rm -rf /home/u566000124/domains/back.thatmuch.fr/public_html/wp-content/cache/*
echo "Cache purged successfully!"