├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .github 3 | LICENSE 4 | README.md 5 | action.yml 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | .DS_Store 4 | *.log 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7-slim 2 | 3 | ENV PYTHONDONTWRITEBYTECODE 1 4 | ENV PYTHONUNBUFFERED 1 5 | 6 | RUN pip install --upgrade --no-cache-dir coscmd 7 | 8 | COPY "entrypoint.sh" "/entrypoint.sh" 9 | RUN chmod +x /entrypoint.sh 10 | 11 | ENTRYPOINT ["/entrypoint.sh"] 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 zkqiang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | 该 [GitHub Action](https://help.github.com/cn/actions) 用于调用腾讯云 4 | [coscmd](https://cloud.tencent.com/document/product/436/10976) 5 | 工具,实现对象存储的批量上传、下载、删除等操作。 6 | 7 | ## workflow 示例 8 | 9 | 在目标仓库中创建 `.github/workflows/xxx.yml` 即可,文件名任意,配置参考如下: 10 | 11 | ```yaml 12 | name: CI 13 | 14 | on: 15 | push: 16 | branches: 17 | - master 18 | 19 | jobs: 20 | build: 21 | runs-on: ubuntu-latest 22 | 23 | steps: 24 | - name: Checkout master 25 | uses: actions/checkout@v2 26 | with: 27 | ref: master 28 | 29 | - name: Setup node 30 | uses: actions/setup-node@v1 31 | with: 32 | node-version: "10.x" 33 | 34 | - name: Build project 35 | run: yarn && yarn build 36 | 37 | - name: Upload COS 38 | uses: zkqiang/tencent-cos-action@v0.1.0 39 | with: 40 | args: delete -r -f / && upload -r ./dist/ / 41 | secret_id: ${{ secrets.SECRET_ID }} 42 | secret_key: ${{ secrets.SECRET_KEY }} 43 | bucket: ${{ secrets.BUCKET }} 44 | region: ap-shanghai 45 | ``` 46 | 47 | 其中 `${{ secrets.SECRET_XXX }}` 是调用 settings 配置的密钥,防止公开代码将权限密钥暴露,添加方式如下: 48 | 49 | ![](https://static.zkqiang.cn/images/20200118171056.png-slim) 50 | 51 | ## 相关参数 52 | 53 | 以下参数均可参见 54 | [coscmd 官方文档](https://cloud.tencent.com/document/product/436/10976) 55 | 56 | | 参数 | 是否必传 | 备注 | 57 | | --- | --- | --- | 58 | | args | 是 | coscmd 命令参数,参见官方文档,多个命令用 ` && ` 隔开
如 `delete -r -f / && upload -r ./dist/ /` | 59 | | secret_id | 是 | 从 [控制台-API密钥管理](https://console.cloud.tencent.com/cam/capi) 获取 | 60 | | secret_key | 是 | 同上 | 61 | | bucket | 是 | 对象存储桶的名称,包含后边的数字 | 62 | | region | 是 | 对象存储桶的地区,[参见文档](https://cloud.tencent.com/document/product/436/6224) | 63 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Tencent COS Action' 2 | description: 'GitHub Action for Tencent COS Command (coscmd)' 3 | author: 'zkqiang ' 4 | branding: 5 | icon: 'cloud' 6 | color: 'blue' 7 | inputs: 8 | args: 9 | description: 'COSCMD args, detail: https://cloud.tencent.com/document/product/436/10976' 10 | required: true 11 | secret_id: 12 | description: 'Tencent cloud SecretId, from: https://console.cloud.tencent.com/cam/capi' 13 | required: true 14 | secret_key: 15 | description: 'Tencent cloud SecretKey, from: https://console.cloud.tencent.com/cam/capi' 16 | required: true 17 | bucket: 18 | description: 'COS bucket name' 19 | required: true 20 | region: 21 | description: 'COS bucket region, detail: https://cloud.tencent.com/document/product/436/6224' 22 | required: true 23 | runs: 24 | using: 'docker' 25 | image: 'Dockerfile' 26 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | if [ -z "$INPUT_ARGS" ]; then 6 | echo '::error::Required Args parameter' 7 | exit 1 8 | fi 9 | 10 | if [ -z "$INPUT_SECRET_ID" ]; then 11 | echo '::error::Required SecretId parameter' 12 | exit 1 13 | fi 14 | 15 | if [ -z "$INPUT_SECRET_KEY" ]; then 16 | echo '::error::Required SecretKey parameter' 17 | exit 1 18 | fi 19 | 20 | if [ -z "$INPUT_BUCKET" ]; then 21 | echo '::error::Required Bucket parameter' 22 | exit 1 23 | fi 24 | 25 | if [ -z "$INPUT_REGION" ]; then 26 | echo '::error::Required Region parameter' 27 | exit 1 28 | fi 29 | 30 | coscmd config -a $INPUT_SECRET_ID -s $INPUT_SECRET_KEY -b $INPUT_BUCKET -r $INPUT_REGION -m 30 31 | 32 | IFS="&&" 33 | arrARGS=($INPUT_ARGS) 34 | 35 | for each in ${arrARGS[@]} 36 | do 37 | unset IFS 38 | each=$(echo ${each} | xargs) 39 | if [ -n "$each" ]; then 40 | echo "Running command: coscmd ${each}" 41 | coscmd $each 42 | fi 43 | done 44 | 45 | echo "Commands ran successfully" 46 | --------------------------------------------------------------------------------