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
1419
20+ env :
21+ PAGES_BASE : ${{ github.event_name == 'pull_request' && format('pr-preview/pr-{0}', github.event.pull_request.number) || '/' }}
22+
1523concurrency :
16- group : pages
24+ # set separate concurrency groups for main and PR branches
25+ group : ${{ github.event_name == 'pull_request' && format('pages-preview-{0}', github.event.pull_request.number) || 'pages-main' }}
1726 cancel-in-progress : false
1827
1928jobs :
2029
30+ delete-preview :
31+ if : github.event_name == 'pull_request' && github.event.action == 'closed'
32+ runs-on : ubuntu-latest
33+ steps :
34+ - uses : rossjrw/pr-preview-action@v1
35+ with :
36+ action : remove
37+
2138 build :
2239 runs-on : ubuntu-latest
40+ # only build on main or if the PR is open
41+ if : github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.action != 'closed')
2342 steps :
2443 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2544 with :
@@ -29,16 +48,24 @@ jobs:
2948 node-version : 22
3049 cache : npm
3150
32- - uses : actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
51+ - id : configure
52+ uses : actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
3353
3454 - run : npm ci
3555 - run : npm run build
3656
57+ # deploy the PR to a preview URL
3758 - uses : rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1
3859 if : ${{ github.event_name == 'pull_request' }}
3960 with :
4061 source-dir : .vitepress/dist
62+ - uses : thollander/actions-comment-pull-request@v3
63+ if : github.event_name == 'pull_request'
64+ with :
65+ message : |
66+ A preview has been deployed to ${{ format('{0}/{1}', steps.configure.outputs.base_url, env.PAGES_BASE) }}
4167
68+ # deploy the build to GitHub Pages
4269 - uses : JamesIves/github-pages-deploy-action@6c2d9db40f9296374acc17b90404b6e8864128c8 # v4
4370 if : ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' }}
4471 with :
0 commit comments