Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 13 additions & 31 deletions .github/workflows/deploy-tcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,23 @@ jobs:

# --- COS CLI 部署核心步骤 ---

# 3. 安装 coscli
# 这里的版本号请自行检查coscli官方发布的最新版本
- name: Install coscli
# 3. 更可靠的安装 coscli
- name: Install coscli (Robust Method)
run: |
# 下载最新的 coscli 二进制文件 (Linux x64)
COSCLI_VERSION="1.0.12"
wget -q https://cos-sdk-archive-1253960454.file.myqcloud.com/coscli/v${COSCLI_VERSION}/coscli-linux -O coscli
COSCLI_VERSION="1.0.12"
# 使用 curl 下载,并重命名为 coscli
curl -LO https://cos-sdk-archive-1253960454.file.myqcloud.com/coscli/v${COSCLI_VERSION}/coscli-linux
mv coscli-linux coscli
chmod +x coscli
sudo mv coscli /usr/local/bin/

# 4. 配置 coscli 密钥和存储桶
- name: Configure coscli
run: |
# coscli 需要一个配置文件 (~/.cos.yaml)
# 注意:这里的 SecretId, SecretKey 等都是通过 GitHub Secrets 传入的环境变量
mkdir -p ~/.config/coscli
cat <<EOF > ~/.config/coscli/config.yaml
# coscli 配置文件内容
secretid: ${{ secrets.TENCENT_SECRET_ID }}
secretkey: ${{ secrets.TENCENT_SECRET_KEY }}
storageclass: STANDARD
buckets:
- name: ${{ secrets.COS_BUCKET }}
region: ${{ secrets.COS_REGION }}
EOF

# 5. 执行同步部署命令
# 4. 配置 coscli 密钥和存储桶 (此步骤不变)
- name: Configure coscli
# ... 配置内容 ...

# 5. 执行同步部署命令 (关键变化:需要指定 coscli 的路径)
- name: Deploy Sync to COS
run: |
# 使用 'sync' 命令将本地目录同步到 COS 存储桶的根目录
# -r: 递归同步
# --delete: 删除远程目标中存在,而本地源中不存在的文件(慎用,确保 local_path 正确)
# --include: 只包含指定的文件,例如只上传HTML, CSS, JS

# 本地目录 ./public 同步到 COS 根目录
coscli sync ./public/ cos://${{ secrets.COS_BUCKET }}/ -r
# 因为 coscli 不在系统 PATH 中,我们需要使用相对路径 './coscli' 执行
./coscli sync ./public/ cos://${{ secrets.COS_BUCKET }}/ -r
env:
COS_BUCKET: ${{ secrets.COS_BUCKET }}
2 changes: 1 addition & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
node-version: '18'
- name: Cache NPM dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
Expand Down