Skip to content

Commit bab41a0

Browse files
committed
Add preview PR deployments
Signed-off-by: Nelo-T. Wallus <red.brush9525@fastmail.com> Signed-off-by: Nelo-T. Wallus <n.wallus@sap.com>
1 parent 461fdef commit bab41a0

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

.github/workflows/pages.yaml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,38 @@ on:
77
pull_request:
88
branches:
99
- main
10+
types:
11+
- opened
12+
- reopened
13+
- synchronize
14+
- closed
1015
workflow_dispatch:
1116

1217
permissions:
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+
1523
concurrency:
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

1928
jobs:
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:

.vitepress/config.mts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fileURLToPath, URL } from 'node:url'
55
export default withMermaid({
66
title: "Platform Mesh",
77

8+
base: process.env.PAGES_BASE ? process.env.PAGES_BASE : '/',
89

910
description: "Platform Mesh - Building upon the Kubernetes API & Resource Model",
1011

@@ -41,7 +42,6 @@ export default withMermaid({
4142
width: 24,
4243
height: 24
4344
},
44-
4545

4646
outline: [2, 3, 4, 5],
4747

@@ -63,7 +63,7 @@ export default withMermaid({
6363
]
6464
}
6565
],
66-
66+
6767
'/scenarios': {
6868
test: 'Scenarios',
6969
items: [
@@ -72,13 +72,11 @@ export default withMermaid({
7272
],
7373
},
7474

75-
7675
},
77-
7876

7977
socialLinks: [
8078
{ icon: 'github', link: 'https://github.com/platform-mesh' }
8179
]
8280
},
83-
81+
8482
})

0 commit comments

Comments
 (0)