1+ name : Publish Docs
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+ pull_request :
8+ branches :
9+ - master
10+ workflow_dispatch :
11+ inputs :
12+ pr_number :
13+ description : ' PR number to deploy preview for'
14+ required : true
15+ type : number
16+
17+ permissions :
18+ contents : write
19+ pull-requests : write
20+
21+ jobs :
22+ build :
23+ runs-on : ubuntu-latest
24+ steps :
25+ - name : Checkout
26+ uses : actions/checkout@v4
27+
28+ - name : Setup Node.js
29+ uses : actions/setup-node@v4
30+ with :
31+ node-version : 20
32+
33+ - name : Install dependencies
34+ run : npm ci
35+
36+ - name : Determine Base URL
37+ id : base-url
38+ run : |
39+ REPO_NAME="${{ github.event.repository.name }}"
40+ OWNER="${{ github.repository_owner }}"
41+
42+ # Check if it's an org page (owner.github.io)
43+ if [[ "${REPO_NAME,,}" == "${OWNER,,}.github.io" ]]; then
44+ BASE_PATH="/"
45+ else
46+ BASE_PATH="/$REPO_NAME/"
47+ fi
48+
49+ echo "base_path=$BASE_PATH" >> $GITHUB_OUTPUT
50+
51+ - name : Build
52+ run : npm run build
53+ env :
54+ BASE_URL : ${{ steps.base-url.outputs.base_path }}
55+
56+ - name : Upload build artifact
57+ uses : actions/upload-artifact@v4
58+ with :
59+ name : site
60+ path : build/
61+
62+ deploy-pr-preview :
63+ if : ${{ github.event_name == 'workflow_dispatch' }}
64+ runs-on : ubuntu-latest
65+ steps :
66+ - name : Checkout
67+ uses : actions/checkout@v4
68+ with :
69+ ref : refs/pull/${{ inputs.pr_number }}/head
70+
71+ - name : Setup Node.js
72+ uses : actions/setup-node@v4
73+ with :
74+ node-version : 20
75+
76+ - name : Install dependencies
77+ run : npm ci
78+
79+ - name : Determine Base URL
80+ id : base-url
81+ run : |
82+ REPO_NAME="${{ github.event.repository.name }}"
83+ OWNER="${{ github.repository_owner }}"
84+ PR_NUM="${{ inputs.pr_number }}"
85+
86+ # Check if it's an org page (owner.github.io)
87+ if [[ "${REPO_NAME,,}" == "${OWNER,,}.github.io" ]]; then
88+ BASE_PATH="/pr-$PR_NUM/"
89+ FULL_URL="https://$OWNER.github.io/pr-$PR_NUM/"
90+ else
91+ BASE_PATH="/$REPO_NAME/pr-$PR_NUM/"
92+ FULL_URL="https://$OWNER.github.io/$REPO_NAME/pr-$PR_NUM/"
93+ fi
94+
95+ echo "base_path=$BASE_PATH" >> $GITHUB_OUTPUT
96+ echo "full_url=$FULL_URL" >> $GITHUB_OUTPUT
97+
98+ - name : Build
99+ run : npm run build
100+ env :
101+ BASE_URL : ${{ steps.base-url.outputs.base_path }}
102+
103+ - name : Deploy PR Preview
104+ uses : JamesIves/github-pages-deploy-action@v4
105+ with :
106+ token : ${{ secrets.GITHUB_TOKEN }}
107+ branch : gh-pages
108+ folder : build
109+ target-folder : pr-${{ inputs.pr_number }}
110+ clean : true
111+ git-config-name : github-actions[bot]
112+ git-config-email : github-actions[bot]@users.noreply.github.com
113+
114+ - name : Comment Preview URL
115+ uses : marocchino/sticky-pull-request-comment@v2
116+ with :
117+ recreate : true
118+ number : ${{ inputs.pr_number }}
119+ message : |
120+ 🚀 **Preview Ready!**
121+ Your docs preview for this PR is available here:
122+
123+ **${{ steps.base-url.outputs.full_url }}**
124+
125+ deploy-production :
126+ if : ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
127+ runs-on : ubuntu-latest
128+ needs : build
129+ steps :
130+ - name : Checkout
131+ uses : actions/checkout@v4
132+
133+ - name : Download build artifact
134+ uses : actions/download-artifact@v4
135+ with :
136+ name : site
137+ path : site
138+
139+ - name : Deploy to GitHub Pages
140+ uses : JamesIves/github-pages-deploy-action@v4
141+ with :
142+ branch : gh-pages
143+ folder : site
0 commit comments