使用upload-cloud-storage Action时如何覆盖替换GCS目标文件夹内容
要实现GCS目标路径与仓库内容完全一致、自动删除仓库已不存在的旧文件,只需在你当前使用的google-github-actions/upload-cloud-storage Action配置中新增delete: true参数即可。该参数开启后,Action会在完成新文件上传后,自动扫描GCS目标路径,删除所有不存在于本地上传目录的冗余文件。
修改后的完整工作流配置如下:
name: Move artifacts on: push: branches: - main jobs: move_artifacts: name: Move artifacts runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - id: upload-files uses: google-github-actions/upload-cloud-storage@main with: credentials: ${{ secrets.gcp_credentials }} path: . destination: my-bucket/my-folder/ # 新增以下参数开启同步删除逻辑 delete: true
可选补充配置:
- 如果你需要保留GCS目标路径下部分不需要同步删除的文件/目录,可以搭配
exclude参数指定排除规则,示例:exclude: 'log/**,*.tmp' - 建议首次配置时先在测试bucket验证参数效果,避免路径填写错误导致误删GCS内的其他文件。
内容的提问来源于stack exchange,提问作者David Masip
相关产品推荐
相关产品推荐

