|
| 1 | +name: Update content and deploy Next.js to Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + schedule: |
| 7 | + # Brasília is UTC-3: Monday 09:00 = Monday 12:00 UTC. |
| 8 | + - cron: '0 12 * * 1' |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + refresh_content: |
| 12 | + description: 'Update stored content before deploying (Apify runs at most once per source per week)' |
| 13 | + type: boolean |
| 14 | + default: true |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + pages: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: pages |
| 23 | + cancel-in-progress: false |
| 24 | + |
| 25 | +jobs: |
| 26 | + build: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 40 |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + ref: main |
| 33 | + fetch-depth: 0 |
| 34 | + - uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: '22' |
| 37 | + cache: npm |
| 38 | + cache-dependency-path: web/package-lock.json |
| 39 | + - uses: actions/setup-python@v5 |
| 40 | + with: |
| 41 | + python-version: '3.12' |
| 42 | + - name: Install dependencies |
| 43 | + working-directory: web |
| 44 | + run: npm ci |
| 45 | + - name: Update stored content |
| 46 | + if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.refresh_content) |
| 47 | + working-directory: web |
| 48 | + continue-on-error: true |
| 49 | + env: |
| 50 | + APIFY_TOKEN: ${{ secrets.APIFY_TOKEN }} |
| 51 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + run: npm run sync:weekly |
| 53 | + - name: Commit only changed content |
| 54 | + if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.refresh_content) |
| 55 | + run: | |
| 56 | + git add web/data/publications.json web/data/projects.json web/data/people.json web/data/media |
| 57 | + if ! git diff --cached --quiet; then |
| 58 | + git config user.name 'github-actions[bot]' |
| 59 | + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 60 | + git commit -m 'Update stored research group content [skip ci]' |
| 61 | + # Never force-push: incorporate concurrent changes or fail on a conflict. |
| 62 | + git fetch origin main |
| 63 | + git rebase origin/main |
| 64 | + git push origin HEAD:main |
| 65 | + fi |
| 66 | + # GITHUB_TOKEN commits do not trigger another push workflow. |
| 67 | + - name: Configure Pages |
| 68 | + id: pages |
| 69 | + uses: actions/configure-pages@v5 |
| 70 | + - name: Export static site |
| 71 | + working-directory: web |
| 72 | + env: |
| 73 | + NEXT_PUBLIC_BASE_PATH: ${{ steps.pages.outputs.base_path }} |
| 74 | + run: npm run build |
| 75 | + - name: Check exported routes and local assets |
| 76 | + working-directory: web |
| 77 | + env: |
| 78 | + NEXT_PUBLIC_BASE_PATH: ${{ steps.pages.outputs.base_path }} |
| 79 | + run: node scripts/check-static.mjs |
| 80 | + - name: Upload static site |
| 81 | + uses: actions/upload-pages-artifact@v3 |
| 82 | + with: |
| 83 | + path: web/out |
| 84 | + deploy: |
| 85 | + needs: build |
| 86 | + runs-on: ubuntu-latest |
| 87 | + environment: |
| 88 | + name: github-pages |
| 89 | + url: ${{ steps.deployment.outputs.page_url }} |
| 90 | + steps: |
| 91 | + - name: Deploy to GitHub Pages |
| 92 | + id: deployment |
| 93 | + uses: actions/deploy-pages@v4 |
0 commit comments