Skip to content

Commit a19cf8a

Browse files
committed
intiai implementation
1 parent f6a3bec commit a19cf8a

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Docusaurus CI, Previews & Cleanup
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, closed]
9+
10+
permissions:
11+
contents: write
12+
pages: write
13+
id-token: write
14+
15+
jobs:
16+
build:
17+
if: github.event.action != 'closed'
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 18
28+
29+
- name: Cache npm dependencies
30+
uses: actions/cache@v4
31+
with:
32+
path: ~/.npm
33+
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
34+
restore-keys: |
35+
${{ runner.os }}-npm-
36+
37+
- name: Install dependencies
38+
run: npm ci
39+
40+
- name: Build Docusaurus site
41+
run: npm run build
42+
43+
- name: Upload site build as artifact
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: docusaurus-build
47+
path: build
48+
49+
deploy:
50+
if: github.event.action != 'closed'
51+
needs: build
52+
runs-on: ubuntu-latest
53+
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v4
57+
58+
- name: Download build artifact
59+
uses: actions/download-artifact@v4
60+
with:
61+
name: docusaurus-build
62+
path: build
63+
64+
- name: Determine deploy target
65+
id: vars
66+
run: |
67+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
68+
echo "branch=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT
69+
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.number }}/" >> $GITHUB_OUTPUT
70+
else
71+
echo "branch=gh-pages" >> $GITHUB_OUTPUT
72+
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" >> $GITHUB_OUTPUT
73+
fi
74+
75+
- name: Deploy to GitHub Pages
76+
uses: peaceiris/actions-gh-pages@v4
77+
with:
78+
github_token: ${{ secrets.GITHUB_TOKEN }}
79+
publish_dir: ./build
80+
publish_branch: ${{ steps.vars.outputs.branch }}
81+
82+
- name: Comment preview link on PR
83+
if: github.event_name == 'pull_request'
84+
uses: marocchino/sticky-pull-request-comment@v2
85+
with:
86+
header: docusaurus-preview
87+
message: |
88+
🚀 **Docusaurus preview deployed!**
89+
🔗 [View Preview](${{ steps.vars.outputs.url }})
90+
91+
cleanup:
92+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
93+
runs-on: ubuntu-latest
94+
95+
steps:
96+
- name: Delete preview branch
97+
uses: dawidd6/action-delete-branch@v3
98+
with:
99+
github_token: ${{ secrets.GITHUB_TOKEN }}
100+
branches: pr-${{ github.event.pull_request.number }}
101+
soft_fail: true
102+

0 commit comments

Comments
 (0)