-
Notifications
You must be signed in to change notification settings - Fork 94
114 lines (100 loc) · 3.33 KB
/
cd.yaml
File metadata and controls
114 lines (100 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: CD
concurrency: production
permissions:
actions: read
on:
push:
branches: [master]
# uncomment this, and change env to development, to use cd flow in dev
# pull_request:
# branches: [master]
jobs:
build:
runs-on: macos-latest
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
ARTIFACT_NAME: build-files
steps:
- uses: actions/checkout@v6
- name: Setup Node # this provides global polyfills?
uses: actions/setup-node@v6
with:
node-version: latest
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Build
run: bun run build
- name: Download previous build files
run: |
URL="https://api.github.com/repos/$REPO/actions/artifacts"
ARTIFACT_JSON=$(curl -s -H "Authorization: token $TOKEN" \
"$URL?name=$ARTIFACT_NAME&per_page=1")
mkdir prev
if [ "$(echo $ARTIFACT_JSON | jq '.total_count')" -gt 0 ]; then
ARTIFACT_ID=$(echo $ARTIFACT_JSON | jq '.artifacts[0].id')
echo "Downloading artifact ID: $ARTIFACT_ID"
curl -L -H "Authorization: token $TOKEN" \
"$URL/$ARTIFACT_ID/zip" -o artifact.zip
unzip -q artifact.zip -d prev
else
echo "No previous artifacts found"
fi
- name: Upload build files
uses: actions/upload-artifact@v7
with:
name: build-files
path: dist/
retention-days: 90
- name: Diff artifacts
run: |
rsync -ainc --delete dist/ prev/ | tee diff-list
- name: Upload diff list
uses: actions/upload-artifact@v7
with:
name: diff-list
path: diff-list
deploy:
needs: build
runs-on: ubuntu-latest
environment: production
env:
OSS_ACCESS_KEY_ID: ${{ secrets.OSS_ACCESS_KEY_ID }}
OSS_ACCESS_KEY_SECRET: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
OSS_REGION: ${{ secrets.OSS_REGION }}
BUCKET: oss://sustech-application
steps:
- name: Download build files
uses: actions/download-artifact@v8
with:
name: build-files
path: dist/
# https://help.aliyun.com/zh/oss/developer-reference/ossutil-overview/
- name: Setup ossutil
run: |
VERSION=2.1.0
FILE_NAME=ossutil-$VERSION-linux-amd64.zip
curl -o $FILE_NAME \
https://gosspublic.alicdn.com/ossutil/v2/$VERSION/$FILE_NAME
unzip -j $FILE_NAME
chmod +x ossutil
./ossutil version
- name: Download diff list
uses: actions/download-artifact@v8
with:
name: diff-list
path: ./
- name: Deploy - delete files
run: |
echo "======== Files to be deleted... ========"
grep '^\*' diff-list | sed 's/^\*.* //' | tee delete-list
echo "======== End of deletion list ========"
./ossutil rm -rf $BUCKET --files-from delete-list
- name: Deploy - update files
run: |
echo "======== Files to be updated... ========"
grep '^>' diff-list | sed 's/^>.* //' | tee update-list
echo "======== End of update list ========"
./ossutil sync -f dist/ $BUCKET --files-from update-list