77 pull_request :
88 branches :
99 - main
10+ types :
11+ - opened
12+ - reopened
13+ - synchronize
14+ - closed
1015 workflow_dispatch :
1116
1217permissions :
1318 contents : write # to write the built page to the branch
19+ pull-requests : write # to leave a comment with the preview URL
20+
21+ env :
22+ PAGES_BASE : ${{ github.event_name == 'pull_request' && format('pr-preview/pr-{0}', github.event.pull_request.number) || '/' }}
1423
1524concurrency :
16- group : pages
25+ # set separate concurrency groups for main and PR branches
26+ group : ${{ github.event_name == 'pull_request' && format('pages-preview-{0}', github.event.pull_request.number) || 'pages-main' }}
1727 cancel-in-progress : false
1828
1929jobs :
2030
31+ delete-preview :
32+ if : github.event_name == 'pull_request' && github.event.action == 'closed'
33+ runs-on : ubuntu-latest
34+ steps :
35+ - uses : rossjrw/pr-preview-action@v1
36+ with :
37+ action : remove
38+
2139 build :
2240 runs-on : ubuntu-latest
41+ # only build on main or if the PR is open
42+ if : github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.action != 'closed')
2343 steps :
2444 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2545 with :
@@ -29,16 +49,24 @@ jobs:
2949 node-version : 22
3050 cache : npm
3151
32- - uses : actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
52+ - id : configure
53+ uses : actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
3354
3455 - run : npm ci
3556 - run : npm run build
3657
58+ # deploy the PR to a preview URL
3759 - uses : rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1
3860 if : ${{ github.event_name == 'pull_request' }}
3961 with :
4062 source-dir : .vitepress/dist
63+ - uses : thollander/actions-comment-pull-request@v3
64+ if : github.event_name == 'pull_request'
65+ with :
66+ message : |
67+ A preview has been deployed to ${{ format('{0}/{1}', steps.configure.outputs.base_url, env.PAGES_BASE) }}
4168
69+ # deploy the build to GitHub Pages
4270 - uses : JamesIves/github-pages-deploy-action@6c2d9db40f9296374acc17b90404b6e8864128c8 # v4
4371 if : ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' }}
4472 with :
0 commit comments