Skip to content

Commit 29577cc

Browse files
committed
feat: add GitHub Pages workflow for multi-branch deployment
Add automated workflow to publish dist folder to GitHub Pages: - main branch deploys to root - other branches deploy to subfolders - no build step - requires pre-built dist to be committed
1 parent 73c13a4 commit 29577cc

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

.github/workflows/gh-pages.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish dist to GitHub Pages (per-branch, no build)
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
delete:
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
publish:
14+
if: github.ref_name != 'gh-pages' && github.event_name == 'push'
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Compute branch slug
22+
id: vars
23+
run: |
24+
BRANCH="${GITHUB_REF_NAME}"
25+
SLUG="$(printf '%s' "$BRANCH" \
26+
| tr '[:upper:]' '[:lower:]' \
27+
| sed -E 's#[/ ]+#-#g; s#[^a-z0-9._-]#-#g; s#-+#-#g; s#(^-|-$)##g')"
28+
echo "slug=$SLUG" >> $GITHUB_OUTPUT
29+
30+
- name: Ensure dist exists
31+
run: |
32+
if [ ! -d dist ]; then
33+
echo "Folder 'dist' not found. Commit your built assets to dist/." >&2
34+
exit 1
35+
fi
36+
37+
- name: Deploy master to root
38+
if: steps.vars.outputs.slug == 'master'
39+
uses: JamesIves/github-pages-deploy-action@v4
40+
with:
41+
token: ${{ secrets.GITHUB_TOKEN }}
42+
branch: gh-pages
43+
folder: dist
44+
clean: false
45+
46+
- name: Deploy branch to subfolder
47+
if: steps.vars.outputs.slug != 'master'
48+
uses: JamesIves/github-pages-deploy-action@v4
49+
with:
50+
token: ${{ secrets.GITHUB_TOKEN }}
51+
branch: gh-pages
52+
folder: dist
53+
target-folder: ${{ steps.vars.outputs.slug }}
54+
clean: true

dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs

0 commit comments

Comments
 (0)