Skip to content

Commit 6d64c3f

Browse files
committed
ci: enhance CI configuration
1 parent 5eb0d09 commit 6d64c3f

13 files changed

Lines changed: 145 additions & 81 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
steps:
3131
- name: Checkout
32-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
32+
uses: actions/checkout@v7
3333
with:
3434
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
3535
ref: ${{ github.event.pull_request.head.sha || github.sha }}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
steps:
3030
- name: Checkout
31-
uses: actions/checkout@v6
31+
uses: actions/checkout@v7
3232
with:
3333
persist-credentials: false
3434

@@ -48,7 +48,7 @@ jobs:
4848

4949
steps:
5050
- name: Checkout
51-
uses: actions/checkout@v6
51+
uses: actions/checkout@v7
5252
with:
5353
persist-credentials: false
5454

@@ -66,7 +66,7 @@ jobs:
6666

6767
steps:
6868
- name: Checkout
69-
uses: actions/checkout@v6
69+
uses: actions/checkout@v7
7070
with:
7171
persist-credentials: false
7272

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ jobs:
3131
printf '%s\n' "$PR_STATE" > ./pr-state.txt
3232
3333
- name: Upload PR number
34-
uses: actions/upload-artifact@v4
34+
uses: actions/upload-artifact@v7
3535
with:
3636
name: pr-id
3737
path: ./pr-id.txt
3838

3939
- name: Upload PR ref
40-
uses: actions/upload-artifact@v4
40+
uses: actions/upload-artifact@v7
4141
with:
4242
name: pr-ref
4343
path: ./pr-ref.txt
4444

4545
- name: Upload PR repo
46-
uses: actions/upload-artifact@v4
46+
uses: actions/upload-artifact@v7
4747
with:
4848
name: pr-repo
4949
path: ./pr-repo.txt
5050

5151
- name: Upload PR state
52-
uses: actions/upload-artifact@v4
52+
uses: actions/upload-artifact@v7
5353
with:
5454
name: pr-state
5555
path: ./pr-state.txt
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: 🌐 Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
tags:
7+
- 'v*.*.*'
8+
- 'v*.*.*-alpha.*'
9+
- 'v*.*.*-beta.*'
10+
- 'v*.*.*-rc.*'
11+
12+
concurrency:
13+
group: github-pages
14+
cancel-in-progress: false
15+
16+
permissions:
17+
contents: write
18+
pull-requests: read
19+
20+
jobs:
21+
deploy:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v7
27+
with:
28+
persist-credentials: false
29+
30+
- name: Setup Node.js
31+
uses: ./.github/actions/setup-node
32+
33+
# ================= Deploy Demo =================
34+
- name: 📦 Build demo
35+
run: pnpm build:demo
36+
37+
- name: Copy demo to workspace
38+
run: |
39+
mkdir -p dist
40+
cp -r ./examples/local/* dist
41+
42+
- name: 📦 Build react16 demo
43+
run: |
44+
pnpm use:react16
45+
pnpm build:demo
46+
47+
- name: Copy react16 demo
48+
run: |
49+
mkdir -p dist/react16
50+
cp -r ./examples/local/* dist/react16
51+
52+
# ================= Deploy Storybook =================
53+
- name: 📦 Build storybook
54+
run: pnpm storybook:build
55+
56+
- name: Copy storybook
57+
run: |
58+
mkdir -p dist/storybook
59+
cp -r ./common/storybook/storybook-static/* dist/storybook
60+
61+
- name: Checkout existing Pages branch
62+
uses: actions/checkout@v7
63+
continue-on-error: true
64+
with:
65+
ref: gh-pages
66+
path: gh-pages-current
67+
persist-credentials: false
68+
69+
- name: Preserve recent PR previews
70+
env:
71+
GH_TOKEN: ${{ github.token }}
72+
run: |
73+
if [ ! -d gh-pages-current/pr-preview ]; then
74+
exit 0
75+
fi
76+
77+
mkdir -p dist/pr-preview
78+
cutoff_epoch=$(date -u -d '30 days ago' +%s)
79+
shopt -s nullglob
80+
81+
for preview_dir in gh-pages-current/pr-preview/pr-*; do
82+
pr_number="${preview_dir##*/pr-}"
83+
if [[ ! "$pr_number" =~ ^[0-9]+$ ]]; then
84+
echo "Prune unexpected preview directory: ${preview_dir}"
85+
continue
86+
fi
87+
88+
if ! pr_info=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}" --jq '[.state, (.closed_at // "")] | @tsv' 2>/dev/null); then
89+
echo "Prune preview for missing PR #${pr_number}"
90+
continue
91+
fi
92+
93+
IFS=$'\t' read -r state closed_at <<< "$pr_info"
94+
if [ "$state" = "open" ]; then
95+
echo "Keep preview for open PR #${pr_number}"
96+
cp -a "$preview_dir" "dist/pr-preview/"
97+
continue
98+
fi
99+
100+
if [ -n "$closed_at" ]; then
101+
closed_epoch=$(date -u -d "$closed_at" +%s)
102+
if [ "$closed_epoch" -ge "$cutoff_epoch" ]; then
103+
echo "Keep preview for recently closed PR #${pr_number}"
104+
cp -a "$preview_dir" "dist/pr-preview/"
105+
continue
106+
fi
107+
fi
108+
109+
echo "Prune preview for PR #${pr_number}"
110+
done
111+
112+
- name: Check Pages publish size
113+
run: |
114+
size_kb=$(du -sk dist | awk '{print $1}')
115+
max_kb=950000
116+
echo "Pages publish directory size: ${size_kb} KB"
117+
if [ "$size_kb" -gt "$max_kb" ]; then
118+
echo "Pages publish directory exceeds ${max_kb} KB. Largest entries:"
119+
du -h -d 2 dist | sort -hr | head -50
120+
exit 1
121+
fi
122+
123+
# ================= Deploy to GitHub Pages =================
124+
- name: 🚀 Deploy to GitHub Pages
125+
uses: peaceiris/actions-gh-pages@v4
126+
with:
127+
github_token: ${{ secrets.GITHUB_TOKEN }}
128+
publish_dir: ./dist
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120

121121
steps:
122122
- name: Checkout
123-
uses: actions/checkout@v4
123+
uses: actions/checkout@v7
124124
with:
125125
repository: ${{ needs.setup.outputs.repo }}
126126
ref: ${{ needs.setup.outputs.ref }}
File renamed without changes.

.github/workflows/pages.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
steps:
2929
- name: Checkout
30-
uses: actions/checkout@v4
30+
uses: actions/checkout@v7
3131
with:
3232
persist-credentials: false
3333

@@ -56,7 +56,7 @@ jobs:
5656

5757
steps:
5858
- name: Checkout
59-
uses: actions/checkout@v4
59+
uses: actions/checkout@v7
6060
with:
6161
ref: ${{ github.ref_name }}
6262
persist-credentials: false
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
steps:
2525
- name: Checkout
26-
uses: actions/checkout@v4
26+
uses: actions/checkout@v7
2727
with:
2828
persist-credentials: false
2929

@@ -103,7 +103,7 @@ jobs:
103103

104104
- name: Upload Semgrep report artifact
105105
if: ${{ always() }}
106-
uses: actions/upload-artifact@v4
106+
uses: actions/upload-artifact@v7
107107
with:
108108
name: semgrep-sarif-${{ github.run_id }}
109109
path: reports/semgrep.sarif

0 commit comments

Comments
 (0)