Skip to content

Commit 596c041

Browse files
committed
feat: incremental deployment (#154)
* feat: incremental deployment * feat: incremental deployment * use --delete and --checksum flag * trigger at PR * do not download previous builds and diff * trigger redeployment * upgrade to ossutil 2.1.0 * use new version of ossutil * remove redundant prefix before diff items * add description for deletion and updates * fix typo * polish up
1 parent 6cc3ad8 commit 596c041

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

.github/workflows/cd.yml

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
name: CD
22
concurrency: production
3+
permissions:
4+
actions: read
35
on:
46
push:
57
branches: [master]
68

79
jobs:
810
build:
911
runs-on: ubuntu-latest
12+
env:
13+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
REPO: ${{ github.repository }}
15+
ARTIFACT_NAME: build-files
1016
steps:
11-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1218

1319
- name: Setup Bun
1420
uses: oven-sh/setup-bun@v1
@@ -21,11 +27,39 @@ jobs:
2127
- name: Build
2228
run: bun run build
2329

30+
- name: Download previous build files
31+
run: |
32+
URL="https://api.github.com/repos/$REPO/actions/artifacts"
33+
ARTIFACT_JSON=$(curl -s -H "Authorization: token $TOKEN" \
34+
"$URL?name=$ARTIFACT_NAME&per_page=1")
35+
mkdir prev
36+
if [ "$(echo $ARTIFACT_JSON | jq '.total_count')" -gt 0 ]; then
37+
ARTIFACT_ID=$(echo $ARTIFACT_JSON | jq '.artifacts[0].id')
38+
echo "Downloading artifact ID: $ARTIFACT_ID"
39+
curl -L -H "Authorization: token $TOKEN" \
40+
"$URL/$ARTIFACT_ID/zip" -o artifact.zip
41+
unzip -q artifact.zip -d prev
42+
else
43+
echo "No previous artifacts found"
44+
fi
45+
2446
- name: Upload build files
2547
uses: actions/upload-artifact@v4
2648
with:
2749
name: build-files
2850
path: .vitepress/dist/
51+
retention-days: 90
52+
overwrite: true
53+
54+
- name: Diff artifacts
55+
run: |
56+
rsync -ainc --delete .vitepress/dist/ prev/ | tee diff-list
57+
58+
- name: Upload diff list
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: diff-list
62+
path: diff-list
2963

3064
deploy:
3165
needs: build
@@ -35,21 +69,43 @@ jobs:
3569
OSS_ACCESS_KEY_ID: ${{ secrets.OSS_ACCESS_KEY_ID }}
3670
OSS_ACCESS_KEY_SECRET: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
3771
OSS_REGION: ${{ secrets.OSS_REGION }}
72+
BUCKET: oss://sustech-application
3873
steps:
3974
- name: Download build files
4075
uses: actions/download-artifact@v4
4176
with:
4277
name: build-files
4378
path: dist/
4479

45-
# see https://help.aliyun.com/zh/oss/developer-reference/ossutil-overview/
80+
# https://help.aliyun.com/zh/oss/developer-reference/ossutil-overview/
4681
- name: Setup ossutil
4782
run: |
48-
curl -o ossutil-2.0.6-beta.01091200-linux-amd64.zip \
49-
https://gosspublic.alicdn.com/ossutil/v2-beta/2.0.6-beta.01091200/ossutil-2.0.6-beta.01091200-linux-amd64.zip
50-
unzip -j ossutil-2.0.6-beta.01091200-linux-amd64.zip
83+
VERSION=2.1.0
84+
FILE_NAME=ossutil-$VERSION-linux-amd64.zip
85+
curl -o $FILE_NAME \
86+
https://gosspublic.alicdn.com/ossutil/v2/$VERSION/$FILE_NAME
87+
unzip -j $FILE_NAME
5188
chmod +x ossutil
5289
./ossutil version
5390
54-
- name: Deploy
55-
run: ./ossutil sync --delete --force dist/ oss://sustech-application/
91+
- name: Download diff list
92+
uses: actions/download-artifact@v4
93+
with:
94+
name: diff-list
95+
path: ./
96+
97+
- name: Deploy - delete files
98+
continue-on-error: true
99+
run: |
100+
echo "======== Files to be deleted... ========"
101+
grep '^\*' diff-list | sed 's/^\*.* //' | tee delete-list
102+
echo "======== End of deletion list ========"
103+
./ossutil rm -rf $BUCKET --files-from delete-list
104+
105+
- name: Deploy - update files
106+
continue-on-error: true
107+
run: |
108+
echo "======== Files to be updated... ========"
109+
grep '^>' diff-list | sed 's/^>.* //' | tee update-list
110+
echo "======== End of update list ========"
111+
./ossutil sync -f dist/ $BUCKET --files-from update-list

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ package-lock.json
1313
pnpm-lock.yaml
1414
bun.lockb
1515
bun.lock
16+
17+
ossutil
18+
.ossutilconfig

0 commit comments

Comments
 (0)