|
| 1 | +name: Deploy Preview to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pages: write |
| 10 | + id-token: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: "pages-preview-${{ github.event.pull_request.number }}" |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Setup Node.js |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: "20" |
| 27 | + |
| 28 | + - name: Setup pnpm |
| 29 | + uses: pnpm/action-setup@v4 |
| 30 | + with: |
| 31 | + version: latest |
| 32 | + |
| 33 | + - name: Get pnpm store directory |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 37 | +
|
| 38 | + - name: Setup pnpm cache |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: ${{ env.STORE_PATH }} |
| 42 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-pnpm-store- |
| 45 | +
|
| 46 | + - name: Install dependencies |
| 47 | + run: pnpm install --frozen-lockfile |
| 48 | + |
| 49 | + - name: Build |
| 50 | + run: pnpm build |
| 51 | + |
| 52 | + - name: Setup Pages |
| 53 | + uses: actions/configure-pages@v4 |
| 54 | + with: |
| 55 | + static_site_generator: svelte |
| 56 | + |
| 57 | + - name: Upload artifact |
| 58 | + uses: actions/upload-pages-artifact@v3 |
| 59 | + with: |
| 60 | + path: ./build |
| 61 | + |
| 62 | + deploy: |
| 63 | + environment: |
| 64 | + name: github-pages-preview |
| 65 | + url: ${{ steps.deployment.outputs.page_url }} |
| 66 | + runs-on: ubuntu-latest |
| 67 | + needs: build |
| 68 | + steps: |
| 69 | + - name: Deploy to GitHub Pages |
| 70 | + id: deployment |
| 71 | + uses: actions/deploy-pages@v4 |
| 72 | + |
| 73 | + comment: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: deploy |
| 76 | + if: github.event_name == 'pull_request' |
| 77 | + steps: |
| 78 | + - name: Comment PR |
| 79 | + uses: actions/github-script@v7 |
| 80 | + with: |
| 81 | + script: | |
| 82 | + github.rest.issues.createComment({ |
| 83 | + issue_number: context.issue.number, |
| 84 | + owner: context.repo.owner, |
| 85 | + repo: context.repo.repo, |
| 86 | + body: `🚀 **Preview deployed!**\n\nYour changes are now live at: ${{ needs.deploy.outputs.page_url }}\n\nThis preview will be automatically updated when you push new commits to this PR.` |
| 87 | + }) |
0 commit comments