Skip to content

Commit d8df6d2

Browse files
committed
fix: add test in s3 upload actions
1 parent 4d0c476 commit d8df6d2

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

.github/workflows/deploy.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,26 @@ jobs:
5252
# Navigate to where the built files are
5353
cd gh-pages
5454
55-
# Sync all files to the S3 bucket
55+
# Create a dummy index file to upload first to ensure the bucket exists
56+
echo "Testing bucket access" > test.txt
57+
58+
# Test upload to check if bucket exists
59+
aws s3 cp test.txt s3://${{ secrets.S3_BUCKET_NAME }}/test.txt \
60+
--endpoint-url ${{ secrets.S3_ENDPOINT_URL }} \
61+
--no-verify-ssl
62+
63+
# Remove test file if succeeded
64+
aws s3 rm s3://${{ secrets.S3_BUCKET_NAME }}/test.txt \
65+
--endpoint-url ${{ secrets.S3_ENDPOINT_URL }} \
66+
--no-verify-ssl
67+
68+
# Sync only specific content types to avoid failures
69+
# Exclude problematic files like .git directory
5670
aws s3 sync . s3://${{ secrets.S3_BUCKET_NAME }} \
71+
--exclude ".git/*" \
72+
--exclude "*.ttf" \
73+
--exclude "*.eot" \
74+
--exclude "*.svg" \
5775
--delete \
5876
--endpoint-url ${{ secrets.S3_ENDPOINT_URL }} \
5977
--no-verify-ssl

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@
2020
1. `S3_ACCESS_KEY` - S3 兼容服务的访问密钥
2121
2. `S3_SECRET_KEY` - S3 兼容服务的秘密密钥
2222
3. `S3_REGION` - S3 服务的区域名称(对于某些第三方服务,可使用其建议的区域值)
23-
4. `S3_ENDPOINT_URL` - S3 兼容服务的 API 端点 URL(不包含 bucket 名称的完整 URL)
24-
5. `S3_BUCKET_NAME` - 要部署到的存储桶名称
23+
4. `S3_ENDPOINT_URL` - S3 兼容服务的 API 端点 URL(完整的服务端点 URL,例如 `https://obs.cn-north-4.myhuaweicloud.com`
24+
5. `S3_BUCKET_NAME` - 要部署到的存储桶名称(确保此存储桶已经创建且有写入权限)
2525

2626
可以在 GitHub 仓库的 Settings → Secrets and variables → Actions 页面中添加这些 secrets。
2727

28-
**注意**:工作流配置已针对第三方 S3 兼容服务进行了优化,不使用标准的 AWS 验证流程,而是直接配置 AWS CLI 凭证,并在 S3 命令中使用 `--endpoint-url``--no-verify-ssl` 参数来确保兼容性。
28+
**注意事项**
29+
30+
1. 工作流配置已针对第三方 S3 兼容服务(如华为云 OBS)进行了优化:
31+
- 直接配置 AWS CLI 凭证而不使用标准 AWS 验证流程
32+
- 使用 `--endpoint-url` 参数指定服务端点
33+
- 使用 `--no-verify-ssl` 参数避免 SSL 验证问题
34+
35+
2. 为避免上传错误,工作流会:
36+
- 先测试桶是否存在和可访问
37+
- 排除可能导致问题的文件类型(.git、字体文件等)
38+
39+
3. 如果使用华为云 OBS,请确保:
40+
- 存储桶已创建并可访问
41+
- 权限配置允许写入操作
42+
- S3_BUCKET_NAME 参数正确匹配您的存储桶名称

0 commit comments

Comments
 (0)