First commit

This commit is contained in:
zkqiang 2020-01-19 10:35:55 +08:00
commit 0caa1b4f62
7 changed files with 173 additions and 0 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
.git
.github
LICENSE
README.md
action.yml

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.idea
.vscode
.DS_Store
*.log

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM python:3.7-slim
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN pip install --upgrade --no-cache-dir coscmd
COPY "entrypoint.sh" "/entrypoint.sh"
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 zkqiang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

62
README.md Normal file
View File

@ -0,0 +1,62 @@
## 简介
该 [GitHub Action](https://help.github.com/cn/actions) 用于调用腾讯云
[coscmd](https://cloud.tencent.com/document/product/436/10976)
工具,实现对象存储的批量上传、下载、删除等操作。
## workflow 示例
在目标仓库中创建 `.github/workflows/xxx.yml` 即可,文件名任意,配置参考如下:
```yaml
name: CI
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v2
with:
ref: master
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: "10.x"
- name: Build project
run: yarn && yarn build
- name: Upload COS
uses: zkqiang/tencent-cos-action@master
with:
args: delete -r -f / && upload -r ./dist/ /
secret_id: ${{ secrets.SECRET_ID }}
secret_key: ${{ secrets.SECRET_KEY }}
bucket: ${{ secrets.BUCKET }}
region: ap-shanghai
```
其中 `${{ secrets.SECRET_XXX }}` 是调用 settings 配置的密钥,防止公开代码将权限密钥暴露,添加方式如下:
![](https://static.zkqiang.cn/images/20200118171056.png-slim)
## 相关参数
以下参数均可参见
[coscmd 官方文档](https://cloud.tencent.com/document/product/436/10976)
| 参数 | 是否必传 | 备注 |
| --- | --- | --- |
| args | 是 | coscmd 命令参数,参见官方文档,多个命令用 ` && ` 隔开<br>`delete -r -f / && upload -r ./dist/ /` |
| secret_id | 是 | 从 [控制台-API密钥管理](https://console.cloud.tencent.com/cam/capi) 获取 |
| secret_key | 是 | 同上 |
| bucket | 是 | 对象存储桶的名称,包含后边的数字 |
| region | 是 | 对象存储桶的地区,[参见文档](https://cloud.tencent.com/document/product/436/6224) |

25
action.yml Normal file
View File

@ -0,0 +1,25 @@
name: 'Tencent COS Action'
description: 'GitHub Action for Tencent COS Command (coscmd)'
author: 'zkqiang <zkqiang@126.com>'
branding:
icon: 'cloud'
color: 'blue'
inputs:
args:
description: 'COSCMD args, detail: https://cloud.tencent.com/document/product/436/10976'
required: true
secret_id:
description: 'Tencent cloud SecretId, from: https://console.cloud.tencent.com/cam/capi'
required: true
secret_key:
description: 'Tencent cloud SecretKey, from: https://console.cloud.tencent.com/cam/capi'
required: true
bucket:
description: 'COS bucket name'
required: true
region:
description: 'COS bucket region, detail: https://cloud.tencent.com/document/product/436/6224'
required: true
runs:
using: 'docker'
image: 'Dockerfile'

45
entrypoint.sh Normal file
View File

@ -0,0 +1,45 @@
#!/bin/bash
set -e
if [ -z "$INPUT_ARGS" ]; then
echo '::error::Required Args parameter'
exit 1
fi
if [ -z "$INPUT_SECRET_ID" ]; then
echo '::error::Required SecretId parameter'
exit 1
fi
if [ -z "$INPUT_SECRET_KEY" ]; then
echo '::error::Required SecretKey parameter'
exit 1
fi
if [ -z "$INPUT_BUCKET" ]; then
echo '::error::Required Bucket parameter'
exit 1
fi
if [ -z "$INPUT_REGION" ]; then
echo '::error::Required Region parameter'
exit 1
fi
coscmd config -a $INPUT_SECRET_ID -s $INPUT_SECRET_KEY -b $INPUT_BUCKET -r $INPUT_REGION -m 30
IFS="&&"
arrARGS=($INPUT_ARGS)
for each in ${arrARGS[@]}
do
unset IFS
each=$(echo ${each} | xargs)
if [ -n "$each" ]; then
echo "Running command: coscmd ${each}"
coscmd $each
fi
done
echo "Commands ran successfully"