Skip to content

Commit f8d1983

Browse files
committed
build: update action workflow file
1 parent 6dc3cee commit f8d1983

File tree

2 files changed

+18
-48
lines changed

2 files changed

+18
-48
lines changed
Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,32 @@
1-
name: Deploy to Tencent COS via coscli
1+
name: Deploy to Tencent COS
22

33
on:
44
push:
55
branches:
6-
- hexo # 监听主分支推送
6+
- hexo
77

88
jobs:
99
deploy:
1010
runs-on: ubuntu-latest
11-
1211
steps:
13-
# 1. 拉取代码
1412
- name: Checkout Repository
1513
uses: actions/checkout@v4
1614

17-
# 2. (可选) 安装 Node.js 并构建前端项目
18-
- name: Setup Node.js and Build
15+
- name: Setup Node.js
1916
uses: actions/setup-node@v4
2017
with:
2118
node-version: '20'
22-
- run: |
19+
20+
- name: Install Dependencies and Build
21+
run: |
2322
npm install
2423
npm run build
25-
# 假设构建产物在 ./dist 目录
2624
27-
# --- COS CLI 部署核心步骤 ---
28-
29-
# 3. 更可靠的安装 coscli
30-
- name: Install coscli (Robust Method)
31-
run: |
32-
COSCLI_VERSION="1.0.12"
33-
# 使用 curl 下载,并重命名为 coscli
34-
curl -LO https://cos-sdk-archive-1253960454.file.myqcloud.com/coscli/v${COSCLI_VERSION}/coscli-linux
35-
mv coscli-linux coscli
36-
chmod +x coscli
37-
38-
# 4. 配置 coscli 密钥和存储桶 (此步骤不变)
39-
- name: Configure coscli
40-
run: |
41-
# coscli 需要一个配置文件 (~/.cos.yaml)
42-
# 注意:这里的 SecretId, SecretKey 等都是通过 GitHub Secrets 传入的环境变量
43-
mkdir -p ~/.config/coscli
44-
cat <<EOF > ~/.config/coscli/config.yaml
45-
# coscli 配置文件内容
46-
secretid: ${{ secrets.TENCENT_SECRET_ID }}
47-
secretkey: ${{ secrets.TENCENT_SECRET_KEY }}
48-
storageclass: STANDARD
49-
buckets:
50-
- name: ${{ secrets.COS_BUCKET }}
51-
region: ${{ secrets.COS_REGION }}
52-
EOF
53-
54-
55-
56-
# 5. 执行同步部署命令 (关键变化:需要指定 coscli 的路径)
57-
- name: Deploy Sync to COS
58-
run: |
59-
# 因为 coscli 不在系统 PATH 中,我们需要使用相对路径 './coscli' 执行
60-
./coscli sync ./public/ cos://${{ secrets.COS_BUCKET }}/ -r
61-
env:
62-
COS_BUCKET: ${{ secrets.COS_BUCKET }}
25+
- name: Deploy to COS
26+
uses: zkqiang/tencent-cos-action@v0.1.0
27+
with:
28+
args: delete -r -f / && upload -r ./public/ /
29+
secret_id: ${{ secrets.TENCENT_SECRET_ID }}
30+
secret_key: ${{ secrets.TENCENT_SECRET_KEY }}
31+
bucket: ${{ secrets.COS_BUCKET }}
32+
region: ${{ secrets.COS_REGION }}

.github/workflows/deployment.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
with:
1414
token: ${{ secrets.GITHUB_TOKEN }}
1515
# If your repository depends on submodule, please see: https://github.com/actions/checkout
1616
submodules: recursive
1717
- name: Use Node.js 18.X
18-
uses: actions/setup-node@v2
18+
uses: actions/setup-node@v4
1919
with:
2020
node-version: '18'
2121
- name: Cache NPM dependencies
@@ -30,7 +30,7 @@ jobs:
3030
- name: Build
3131
run: npm run build
3232
- name: Upload Pages artifact
33-
uses: actions/upload-pages-artifact@v2
33+
uses: actions/upload-pages-artifact@v3
3434
with:
3535
path: ./public
3636
deploy:
@@ -45,4 +45,4 @@ jobs:
4545
steps:
4646
- name: Deploy to GitHub Pages
4747
id: deployment
48-
uses: actions/deploy-pages@v2
48+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)