Deploy Website to GitHub Pages #1210
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 Website to GitHub Pages | |
| # Коли запускається цей workflow: | |
| on: | |
| # 1. АВТОМАТИЧНО після завершення бота | |
| workflow_run: | |
| workflows: ["Danish News Bot - Scheduled"] | |
| types: | |
| - completed | |
| # 2. При push змін в main | |
| push: | |
| branches: [main] | |
| # 3. Ручний запуск | |
| workflow_dispatch: | |
| # Права для деплою на GitHub Pages | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # Не запускати паралельно (щоб не було конфліктів) | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| # ============================================ | |
| # JOB 1: Build Hugo site | |
| # ============================================ | |
| build: | |
| runs-on: ubuntu-latest | |
| # Запускаємо якщо: бот успішний АБО це push/manual | |
| if: | | |
| github.event_name == 'push' || | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') | |
| env: | |
| SUPABASE_URL: ${{ secrets.SUPABASE_URL }} | |
| SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }} | |
| steps: | |
| # 1. Checkout репозиторію (latest code, no cached markdown) | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: main # Always use latest main branch | |
| # 2. Clean any existing generated posts (ensure fresh build) | |
| - name: Clean generated posts | |
| run: | | |
| echo "🧹 Cleaning existing markdown files..." | |
| rm -f website/content/posts/*.md 2>/dev/null || true | |
| echo "✅ Ready for fresh content generation" | |
| # 3. Встановлення Hugo | |
| - name: Setup Hugo | |
| uses: peaceiris/actions-hugo@v3 | |
| with: | |
| hugo-version: 'latest' | |
| extended: true | |
| # 4. Налаштування GitHub Pages | |
| - name: Setup Pages | |
| id: pages | |
| uses: actions/configure-pages@v4 | |
| # 5. Generate markdown files from Supabase (fresh data every build) | |
| - name: Generate pages from Supabase | |
| run: | | |
| echo "📥 Fetching latest news from Supabase and generating markdown..." | |
| chmod +x scripts/generate-pages.sh | |
| ./scripts/generate-pages.sh | |
| echo "✅ Generated posts:" | |
| ls -lh website/content/posts/ || echo "No posts directory yet" | |
| continue-on-error: false # Fail if Supabase fetch fails | |
| # 6. Build сайту | |
| - name: Build with Hugo | |
| working-directory: website | |
| env: | |
| HUGO_ENVIRONMENT: production | |
| HUGO_ENV: production | |
| run: | | |
| hugo --gc --minify | |
| echo "✅ Hugo build completed" | |
| echo "📁 Files in public/:" | |
| ls -la public/ | |
| # 7. Upload artifact для деплою | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./website/public | |
| # ============================================ | |
| # JOB 2: Deploy to GitHub Pages | |
| # ============================================ | |
| 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 |