Deploy to GitHub Pages #2384
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |