-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (131 loc) · 4.6 KB
/
deploy-pages.yml
File metadata and controls
153 lines (131 loc) · 4.6 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Deploy to GitHub Pages
on:
release:
types: [published]
push:
branches: [main]
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
build-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Determine base path and site path
id: paths
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "base=/" >> $GITHUB_OUTPUT
echo "site_path=" >> $GITHUB_OUTPUT
else
echo "base=/preview/${{ github.sha }}/" >> $GITHUB_OUTPUT
echo "site_path=preview/${{ github.sha }}" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm run build
env:
VITE_BASE_PATH: ${{ steps.paths.outputs.base }}
VITE_PUBLIC_POSTHOG_KEY: ${{ secrets.VITE_PUBLIC_POSTHOG_KEY }}
VITE_PUBLIC_POSTHOG_API_HOST: ${{ vars.VITE_PUBLIC_POSTHOG_API_HOST }}
VITE_PUBLIC_POSTHOG_HOST: ${{ vars.VITE_PUBLIC_POSTHOG_HOST }}
VITE_COMMIT_SHA: ${{ github.sha }}
- name: Restore existing site state
run: |
mkdir -p _site
if git ls-remote --exit-code --heads origin pages-state >/dev/null 2>&1; then
git fetch origin pages-state
git worktree add ../site-state origin/pages-state
cp -R ../site-state/. _site/
fi
touch _site/.nojekyll
- name: Merge build into site
env:
SITE_PATH: ${{ steps.paths.outputs.site_path }}
EVENT_TYPE: ${{ github.event_name }}
run: |
if [[ "$EVENT_TYPE" == "release" ]]; then
find _site -mindepth 1 -maxdepth 1 ! -name '.nojekyll' ! -name CNAME -exec rm -rf {} + 2>/dev/null || true
cp -R dist/. _site/
else
rm -rf "_site/${SITE_PATH}"
mkdir -p "_site/${SITE_PATH}"
cp -R dist/. "_site/${SITE_PATH}/"
fi
cat > _site/deploy-info.txt <<EOF
event=${{ github.event_name }}
ref=${{ github.ref }}
sha=${{ github.sha }}
run_id=${{ github.run_id }}
run_attempt=${{ github.run_attempt }}
EOF
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: _site
- name: Deploy
id: deployment
uses: actions/deploy-pages@v4
- name: Persist site state
if: always() && (steps.deployment.outputs.page_url != '')
run: |
git worktree remove --force ../site-state >/dev/null 2>&1 || true
if git ls-remote --exit-code --heads origin pages-state >/dev/null 2>&1; then
git fetch origin pages-state
git worktree add ../site-state origin/pages-state
else
git worktree add --detach ../site-state
cd ../site-state
git switch --orphan pages-state
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
cd -
fi
find ../site-state -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
cp -R _site/. ../site-state/
cd ../site-state
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No changes to persist."
exit 0
fi
git commit -m "pages-state: ${{ github.event_name }} ${{ github.sha }}"
git push origin HEAD:pages-state --force
- name: Show deployed URL
if: steps.deployment.outputs.page_url != ''
env:
BASE_URL: ${{ steps.deployment.outputs.page_url }}
SITE_PATH: ${{ steps.paths.outputs.site_path }}
EVENT_TYPE: ${{ github.event_name }}
run: |
if [[ "$EVENT_TYPE" == "release" || -z "$SITE_PATH" ]]; then
URL="$BASE_URL"
else
URL="${BASE_URL%/}/$SITE_PATH/"
fi
echo "Deployed URL: $URL"
echo "::notice title=Deployed URL::$URL"