|
| 1 | +name: Preview |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [master] |
| 6 | + types: [opened, synchronize, reopened, closed] |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy-preview: |
| 10 | + if: github.event.action != 'closed' |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v6 |
| 14 | + - uses: actions/setup-dotnet@v5 |
| 15 | + with: |
| 16 | + dotnet-version: 10.0.x |
| 17 | + - name: Install dependencies |
| 18 | + run: dotnet restore |
| 19 | + - name: Build |
| 20 | + run: dotnet build --configuration Release --no-restore |
| 21 | + - name: Generate site |
| 22 | + run: dotnet run --configuration Release |
| 23 | + - name: Index with Pagefind |
| 24 | + run: npx pagefind --site output |
| 25 | + - name: Install Surge |
| 26 | + run: npm install -g surge |
| 27 | + - name: Deploy to Surge |
| 28 | + env: |
| 29 | + SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} |
| 30 | + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} |
| 31 | + run: surge ./output petrsvihlik-pr-${{ github.event.pull_request.number }}.surge.sh |
| 32 | + - name: Post preview URL comment |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const url = 'https://petrsvihlik-pr-${{ github.event.pull_request.number }}.surge.sh'; |
| 37 | + const marker = '<!-- surge-preview -->'; |
| 38 | + const body = `${marker}\n🚀 **Preview:** [${url}](${url})`; |
| 39 | +
|
| 40 | + const comments = await github.rest.issues.listComments({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + issue_number: context.issue.number, |
| 44 | + }); |
| 45 | +
|
| 46 | + const existing = comments.data.find(c => c.body.includes(marker)); |
| 47 | + if (existing) { |
| 48 | + await github.rest.issues.updateComment({ |
| 49 | + owner: context.repo.owner, |
| 50 | + repo: context.repo.repo, |
| 51 | + comment_id: existing.id, |
| 52 | + body, |
| 53 | + }); |
| 54 | + } else { |
| 55 | + await github.rest.issues.createComment({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + issue_number: context.issue.number, |
| 59 | + body, |
| 60 | + }); |
| 61 | + } |
| 62 | +
|
| 63 | + teardown-preview: |
| 64 | + if: github.event.action == 'closed' |
| 65 | + runs-on: ubuntu-latest |
| 66 | + steps: |
| 67 | + - name: Install Surge |
| 68 | + run: npm install -g surge |
| 69 | + - name: Teardown Surge preview |
| 70 | + env: |
| 71 | + SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} |
| 72 | + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} |
| 73 | + run: surge teardown petrsvihlik-pr-${{ github.event.pull_request.number }}.surge.sh |
0 commit comments