update #71
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 | |
| push: | |
| branches: [ main ] | |
| # Deploy automatico ogni giorno alle 6:00 UTC (8:00 CET) | |
| schedule: | |
| - cron: '0 6 * * *' | |
| # 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: Download and save API data | |
| run: | | |
| # Crea la cartella data se non esiste | |
| mkdir -p data | |
| # Scarica i dati dall'API e salvali come source.json | |
| # Questo file servirà come backup locale nel repository | |
| curl -s "https://firmereferendum.giustizia.it/referendum/api-portal/iniziativa/public?v=1751271726271" \ | |
| -H "Accept: application/json" \ | |
| -H "User-Agent: Mozilla/5.0 (compatible; referendum-astro-bot/1.0)" \ | |
| -o data/source.json | |
| # Verifica che il file sia stato scaricato correttamente | |
| if [ -f "data/source.json" ] && [ -s "data/source.json" ]; then | |
| echo "✅ API data downloaded successfully to data/source.json" | |
| echo "File size: $(wc -c < data/source.json) bytes" | |
| # 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)" | |
| else | |
| echo "❌ Failed to download API data" | |
| exit 1 | |
| fi | |
| - name: Commit and push updated data | |
| run: | | |
| # Configura git | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| # Aggiungi il file se è cambiato | |
| git add data/source.json data/check_date.txt | |
| # Verifica se ci sono cambiamenti da committare | |
| if git diff --staged --quiet; then | |
| echo "📝 No changes in source.json" | |
| else | |
| echo "📝 Committing updated source.json" | |
| git commit -m "chore: update source.json 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' | |
| 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 |