-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (136 loc) · 5.13 KB
/
Copy pathdeploy.yml
File metadata and controls
162 lines (136 loc) · 5.13 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Deploy to GitHub Pages
on:
# Trigger su push al branch main, ma escludi file di documentazione
push:
branches: [ main ]
paths-ignore:
- 'prd.md'
- 'LOG.md'
- 'README.md'
- 'docs/**'
# Deploy automatico 6 volte al giorno: 4:00, 8:00, 12:00, 16:00, 19:30, 20:00 UTC
# 21:30 UTC = 23:30 ora italiana (considerando ora legale)
schedule:
- cron: '0 4,8,12,16,20 * * *'
- cron: '30 21 * * *'
# Permetti di lanciare manualmente dalla UI GitHub
workflow_dispatch:
inputs:
reason:
description: 'Motivo del deploy manuale'
required: false
default: 'Deploy manuale'
# Permessi necessari per il deploy
permissions:
contents: write # Necessario per commit e push
pages: write
id-token: write
# Consenti solo un deployment alla volta
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Show manual deploy reason
if: github.event_name == 'workflow_dispatch'
run: echo "Deploy manuale lanciato - Motivo:" "${{ github.event.inputs.reason }}"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm install --legacy-peer-deps
- name: Install dependencies for data processing
run: |
sudo apt-get update
sudo apt-get install -y jq miller
- name: Download and save API data
run: |
# Rendi eseguibile lo script di download
chmod +x scripts/download_data.sh
# Esegui lo script di download
./scripts/download_data.sh
# Crea il file check_date.txt con la data di scarico
date '+%Y-%m-%d' > data/check_date.txt
echo "📅 Created check_date.txt with download date: $(cat data/check_date.txt)"
- name: Commit and push updated data
run: |
# Configura git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Sincronizza con il branch remoto (stash automaticamente i cambiamenti locali)
git pull --rebase --autostash
# Aggiungi i file se sono cambiati
git add data/source.json data/source.jsonl data/time_line.jsonl data/media_sostenitori_giornaliera.jsonl data/check_date.txt
# Verifica se ci sono cambiamenti da committare
if git diff --staged --quiet; then
echo "📝 No changes in data files"
else
echo "📝 Committing updated data files"
git commit -m "chore: update data files with latest API data [skip ci]"
git push
fi
- name: Generate Open Graph Images
run: npm run generate-og-images
- name: Build with Astro
run: npm run build
env:
NODE_ENV: production
- name: Setup Pages
uses: actions/configure-pages@v4
with:
# Abilita automaticamente Pages se non è già abilitato
enablement: true
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './dist'
- name: Ensure data directory exists (solo cron 21:30 UTC)
if: github.event_name == 'schedule' && github.event.schedule == '30 21 * * *'
run: mkdir -p data
- name: Log deploy status (solo cron 21:30 UTC)
if: github.event_name == 'schedule' && github.event.schedule == '30 21 * * *'
run: |
echo "DEBUG: Entering 'Log deploy status' step for cron 21:30 UTC"
STATUS="success"
LOG_FILE="data/deploy_log.jsonl"
DATE=$(date '+%Y-%m-%d')
echo "{\"date\": \"$DATE\", \"status\": \"$STATUS\"}" >> "$LOG_FILE"
echo "📝 Aggiornato $LOG_FILE con stato deploy: $STATUS"
- name: Commit and push deploy log (solo cron 21:30 UTC)
if: github.event_name == 'schedule' && github.event.schedule == '30 21 * * *'
run: |
echo "DEBUG: Entering 'Commit and push deploy log' step for cron 21:30 UTC"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Sincronizza con il branch remoto (stash automaticamente i cambiamenti locali)
git pull --rebase --autostash
git add data/deploy_log.jsonl
if git diff --staged --quiet; then
echo "📝 Nessun cambiamento nel file di log"
else
echo "DEBUG: Changes detected, committing deploy_log.jsonl"
git commit -m "chore: update deploy log for 21:30 UTC cron [skip ci]"
git push
echo "DEBUG: deploy_log.jsonl committed and pushed."
fi
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
with:
timeout: 1200000