Use GitHub Pages on separate repo for PR previews #2
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 Preview | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| push: | |
| branches-ignore: | |
| - main | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| preview: | |
| runs-on: ubuntu-latest | |
| env: | |
| HUGO_VERSION: 0.154.3 | |
| steps: | |
| - name: Install Hugo | |
| run: | | |
| wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb | |
| sudo dpkg -i ${{ runner.temp }}/hugo.deb | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Build with Hugo | |
| env: | |
| HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache | |
| run: | | |
| hugo --minify --baseURL "https://agentevals-dev.github.io/website-preview/" | |
| - name: Deploy to preview repo | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| personal_token: ${{ secrets.PREVIEW_DEPLOY_TOKEN }} | |
| external_repository: agentevals-dev/website-preview | |
| publish_branch: gh-pages | |
| publish_dir: ./public | |
| - name: Comment preview URL on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const previewUrl = 'https://agentevals-dev.github.io/website-preview/'; | |
| const body = `🔗 **Preview deployed:** ${previewUrl}\n\nUpdated from commit ${context.sha.substring(0, 7)}`; | |
| // Find existing bot comment | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.data.find(c => | |
| c.user.type === 'Bot' && c.body.includes('Preview deployed') | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: body, | |
| }); | |
| } |