Repository navigation
90 lines (78 loc) · 2.86 KB
/
Copy pathpr-preview.yml
File metadata and controls
90 lines (78 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: PR Preview
on:
pull_request:
types: [opened, synchronize, reopened, closed]
permissions:
contents: read
concurrency:
group: pr-preview-${{ github.ref }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
environment: preview
steps:
- name: Checkout
if: github.event.action != 'closed'
uses: actions/checkout@v4
- name: Setup Node
if: github.event.action != 'closed'
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
- name: Install dependencies
if: github.event.action != 'closed'
run: npm ci
- name: Build with Astro
if: github.event.action != 'closed'
run: npm run build
env:
PREVIEW_BASE: "/pr-preview/pr-${{ github.event.number }}/"
PREVIEW_SITE: "https://ledger-donjon.github.io"
- name: Deploy PR Preview
if: github.event.action != 'closed'
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ secrets.PREVIEW_DEPLOY_TOKEN }}
repository-name: Ledger-Donjon/ledger-donjon-preview.github.io
branch: gh-pages
folder: ./dist
target-folder: pr-preview/pr-${{ github.event.number }}
clean: false
commit-message: "Deploy preview for PR #${{ github.event.number }}"
- name: Ensure .nojekyll at preview root
if: github.event.action != 'closed'
run: |
mkdir -p preview-root
touch preview-root/.nojekyll
- name: Deploy .nojekyll to preview root
if: github.event.action != 'closed'
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ secrets.PREVIEW_DEPLOY_TOKEN }}
repository-name: Ledger-Donjon/ledger-donjon-preview.github.io
branch: gh-pages
folder: ./preview-root
target-folder: .
clean: false
commit-message: "Ensure .nojekyll at preview root"
- name: Checkout preview repo for cleanup
if: github.event.action == 'closed'
uses: actions/checkout@v4
with:
repository: Ledger-Donjon/ledger-donjon-preview.github.io
ref: gh-pages
token: ${{ secrets.PREVIEW_DEPLOY_TOKEN }}
path: preview-repo
- name: Remove PR preview
if: github.event.action == 'closed'
run: |
rm -rf "preview-repo/pr-preview/pr-${{ github.event.number }}"
if [ -n "$(git -C preview-repo status --porcelain)" ]; then
git -C preview-repo config user.name "github-actions[bot]"
git -C preview-repo config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C preview-repo add -A
git -C preview-repo commit -m "Remove preview for PR #${{ github.event.number }}"
git -C preview-repo push
fi