|
| 1 | +# .github/workflows/deploy-pages.yml |
| 2 | +name: Deploy static content to Pages |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pages: write |
| 12 | + id-token: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: pages |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + deploy: |
| 20 | + environment: |
| 21 | + name: github-pages |
| 22 | + url: ${{ steps.deployment.outputs.page_url }} |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + # ---------- 1) Check if Pages is enabled ---------- |
| 30 | + - name: Detect GitHub Pages status |
| 31 | + id: pages_status |
| 32 | + run: | |
| 33 | + set -e |
| 34 | + http_status=$(curl -s -o /dev/null -w "%{http_code}" \ |
| 35 | + -H "Authorization: Bearer ${{ github.token }}" \ |
| 36 | + -H "Accept: application/vnd.github+json" \ |
| 37 | + https://api.github.com/repos/${{ github.repository }}/pages) |
| 38 | +
|
| 39 | + if [ "$http_status" = "200" ]; then |
| 40 | + echo "✅ Pages already enabled." |
| 41 | + echo "deploy=yes" >> "$GITHUB_OUTPUT" |
| 42 | + else |
| 43 | + echo "::notice ::GitHub Pages is not enabled for this repository yet." |
| 44 | + echo "::notice ::Enable it under Settings → Pages (select **GitHub Actions** as the source) and rerun the workflow." |
| 45 | + echo "deploy=no" >> "$GITHUB_OUTPUT" |
| 46 | + fi |
| 47 | +
|
| 48 | + # ---------- 2) Stop early when Pages is disabled ---------- |
| 49 | + - name: Early‑exit (no deploy needed) |
| 50 | + if: steps.pages_status.outputs.deploy == 'no' |
| 51 | + run: echo "Skipping build & deploy because Pages is disabled." |
| 52 | + # Workflow ends successfully here when deploy=no |
| 53 | + continue-on-error: false |
| 54 | + |
| 55 | + # ---------- 3) Normal build & deploy path ---------- |
| 56 | + - name: Set up Node |
| 57 | + if: steps.pages_status.outputs.deploy == 'yes' |
| 58 | + uses: actions/setup-node@v4 |
| 59 | + with: |
| 60 | + node-version: lts/* |
| 61 | + cache: npm |
| 62 | + |
| 63 | + - name: Install dependencies |
| 64 | + if: steps.pages_status.outputs.deploy == 'yes' |
| 65 | + run: npm ci |
| 66 | + |
| 67 | + - name: Build |
| 68 | + if: steps.pages_status.outputs.deploy == 'yes' |
| 69 | + run: npm run build |
| 70 | + |
| 71 | + - name: Setup Pages |
| 72 | + if: steps.pages_status.outputs.deploy == 'yes' |
| 73 | + uses: actions/configure-pages@v5 |
| 74 | + |
| 75 | + - name: Upload artifact |
| 76 | + if: steps.pages_status.outputs.deploy == 'yes' |
| 77 | + uses: actions/upload-pages-artifact@v3 |
| 78 | + with: |
| 79 | + path: ./dist |
| 80 | + |
| 81 | + - name: Deploy to GitHub Pages |
| 82 | + if: steps.pages_status.outputs.deploy == 'yes' |
| 83 | + id: deployment |
| 84 | + uses: actions/deploy-pages@v4 |
0 commit comments