├── .all-contributorsrc ├── .github └── workflows │ └── main.yml ├── .gitignore ├── @v2 └── run.sh ├── README.md ├── action.yml ├── assets ├── logo.png ├── secret.png └── secrets.png ├── cloudbaserc.json └── functions └── example └── index.js /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "contributors": [ 8 | { 9 | "login": "beetcb", 10 | "name": "beet", 11 | "avatar_url": "https://avatars.githubusercontent.com/u/63141491?v=4", 12 | "profile": "http://www.beetcb.com", 13 | "contributions": [ 14 | "code" 15 | ] 16 | }, 17 | { 18 | "login": "TonyWu3027", 19 | "name": "Zhaoxuan \"Tony\" Wu", 20 | "avatar_url": "https://avatars.githubusercontent.com/u/22099504?v=4", 21 | "profile": "https://www.linkedin.com/in/zhaoxuan-wu-495b2a194/", 22 | "contributions": [ 23 | "code" 24 | ] 25 | } 26 | ], 27 | "contributorsPerLine": 7, 28 | "projectName": "cloudbase-action", 29 | "projectOwner": "TencentCloudBase", 30 | "repoType": "github", 31 | "repoHost": "https://github.com", 32 | "skipCi": true 33 | } 34 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: 2 | watch: 3 | # Test on star, not push 4 | types: [started] 5 | 6 | jobs: 7 | deploy: 8 | runs-on: ubuntu-latest 9 | name: Tencent Cloudbase Github Action Example 10 | env: 11 | accessToken: ${{ secrets.accessToken }} 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | - name: Deploy to Tencent CloudBase 16 | uses: ./ 17 | with: 18 | secretId: ${{secrets.secretId}} 19 | secretKey: ${{secrets.secretKey}} 20 | envId: ${{secrets.envId}} 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .idea 3 | .history 4 | .DS_Store 5 | yarn.lock 6 | node_modules 7 | build/ 8 | -------------------------------------------------------------------------------- /@v2/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SECRET_ID="$1" 4 | SECRET_KEY="$2" 5 | ENV_ID="$3" 6 | CONFIG_FILE="./cloudbaserc.json" 7 | 8 | # 9 | # Must Required variables check 10 | # 11 | if [ -z "$SECRET_ID" ] || [ -z "$SECRET_KEY" ] || [ -z "$ENV_ID" ]; then 12 | echo "::error:: Missing required parameters" 13 | exit 1 14 | fi 15 | 16 | # 17 | # Config file check 18 | # 19 | if [ ! -f "$CONFIG_FILE" ]; then 20 | echo "::error:: Missing cloudbase configuration file" 21 | exit 1 22 | fi 23 | 24 | # 25 | # Trace commands, print tips & description 26 | # @param command The actual command to execute 27 | # @param description Describe the purpose of the command, with ansi color 28 | # 29 | trace() { 30 | # Group inner steps 31 | echo -e "::group::$2" 32 | echo -e "\e[32m› $1" 33 | if ! eval "$1" ; then 34 | exit 1 35 | fi 36 | echo "::endgroup::" 37 | } 38 | 39 | trace "sudo npm install -g @cloudbase/cli --loglevel=error --no-fund --no-audit --no-progress --prefer-offline" "\e[34mDownload and install cloudbase cli" 40 | 41 | trace "tcb login --apiKeyId "$SECRET_ID" --apiKey "$SECRET_KEY"" "\e[34mLogin to cloudbase" 42 | 43 | trace "tcb framework deploy -e "$ENV_ID"" "\e[36mDeploy to cloudbase" 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | [](#contributors-) 5 | 6 | 7 | # Tencent CloudBase Github Action 8 | 9 | [](https://github.com/marketplace/actions/tencent-cloudbase-github-action) [](https://github.com/TencentCloudBase/cloudbase-action/actions) 10 | 11 | 云开发 Tencent CloudBase Github Action 借力于 [CloudBase Framework](https://github.com/Tencent/cloudbase-framework),可以将 Github 项目自动部署到云开发环境 12 | 13 | 如果你目前使用的是 Tencent CloudBase Github Action V1 版本,请参考 [V1 README](https://github.com/TencentCloudBase/cloudbase-action/blob/3354b442713265aa9d7c5bf03b0b8cb0173f546f/README.md),推荐使用 V2 版本以获取更多功能 14 | 15 | [🚀 在项目中使用此扩展](https://github.com/marketplace/actions/tencent-cloudbase-github-action) 16 | 17 | - 云开发官网地址: [https://cloudbase.net/](https://cloudbase.net/) 18 | - 云开发控制台地址: [https://console.cloud.tencent.com/tcb](https://console.cloud.tencent.com/tcb) 19 | 20 | 支持列表: 21 | 22 | - 部署静态网站 23 | - 部署云函数 24 | - 部署到云托管环境 25 | - 部署微信小程序应用 26 | - 配置登录鉴权和云数据库 27 | 28 | 完整列表请查看[插件介绍](https://docs.cloudbase.net/framework/plugins/) 29 | 30 | ## 输入参数 31 | 32 | > 提示:标注 🔐 的参数属于敏感信息,需要放在项目的 `secret` 存储中,用法可以参考最后的实例 33 | 34 | ### `secretId` 🔐 35 | 36 | **Required** 云开发的访问密钥 secretId. 37 | 38 | 在腾讯云[访问管理](https://console.cloud.tencent.com/cam/capi)页面获取 39 | 40 | ### `secretKey` 🔐 41 | 42 | **Required** 云开发的访问密钥 secretKey. 43 | 44 | 在腾讯云[访问管理](https://console.cloud.tencent.com/cam/capi)页面获取 45 | 46 | ### `envId` 🔐 47 | 48 | **Required** 云开发的环境 id envId. 49 | 50 | 可以在云开发的[控制台](https://console.cloud.tencent.com/tcb/env/index)获取 51 | 52 | ## 配置文件 53 | 54 | 请**确保**项目根目录存在 `cloudbaserc.json` 文件并配置好 CloudBase Framework,[参考教程](https://docs.cloudbase.net/framework/config.html#pei-zhi-shuo-ming) 55 | 56 | 如需配置部署**地域**,请参考[配置字段](https://docs.cloudbase.net/cli-v1/config.html#zi-duan) 57 | 58 | > 如果你的项目正在使用 CloudBase Framework,那么此 Action 就是 0 配置的 59 | 60 | 然后请根据你的需求引入相关插件,支持[自动检测生成插件配置](https://docs.cloudbase.net/framework/plugins/#zi-dong-jian-ce-sheng-cheng-cha-jian-pei-zhi)或[手动填写插件配置](https://docs.cloudbase.net/framework/plugins/#zi-dong-jian-ce-sheng-cheng-cha-jian-pei-zhi) 61 | 62 | ## 参考示例 63 | 64 | **以下示例将演示:如何快速部署云函数到 CloudBase(同时设定部署的私密环境变量)** 65 | 66 | 1. 编写如下的 Github Action 文件 `.github/workflows/main.yml` 67 | 68 | ```yaml 69 | on: [push] 70 | 71 | jobs: 72 | deploy: 73 | runs-on: ubuntu-latest 74 | name: Tencent Cloudbase Github Action Example 75 | steps: 76 | - name: Checkout 77 | uses: actions/checkout@v2 78 | - name: Deploy to Tencent CloudBase 79 | uses: TencentCloudBase/cloudbase-action@v2.0.1 80 | with: 81 | secretId: ${{secrets.secretId}} 82 | secretKey: ${{secrets.secretKey}} 83 | envId: ${{secrets.envId}} 84 | ``` 85 | 86 | 假设我们在部署时需要设置私密型的环境变量(比如小程序 `appid` 或访问数据库的 `accessToken`),请在以上代码中新增以下内容: 87 | 88 | ```diff 89 | name: Tencent Cloudbase Github Action Example 90 | +env: 91 | + accessToken: ${{ secrets.accessToken }} 92 | ``` 93 | 94 | 其中 `env` 下的 `accessToken` 键值对是我们[部署时设置的环境变量](https://docs.github.com/en/actions/reference/environment-variables#about-environment-variables),它的功能与本地的 `.env` 文件相同 95 | 96 | 2. 在项目中配置 `cloudbaserc.json` 文件并引入我们刚刚配置的环境变量: 97 | 98 | ```json 99 | { 100 | "envId": "{{env.ENV_ID}}", 101 | "version": "2.0", 102 | "framework": { 103 | "name": "gh-actions-test", 104 | "plugins": { 105 | "func": { 106 | "use": "@cloudbase/framework-plugin-function", 107 | "inputs": { 108 | "functions": [ 109 | { 110 | "name": "example", 111 | "memorySize": 128, 112 | "timeout": 5, 113 | "runtime": "Nodejs10.15", 114 | "handler": "index.main", 115 | "envVariables": { 116 | "accessToken": "{{env.accessToken}}" 117 | } 118 | } 119 | ] 120 | } 121 | } 122 | } 123 | } 124 | } 125 | ``` 126 | 127 | 3. 在项目 Settings/Secrets 里设置 `secretId`, `secretKey`, `envId`, `accessToken` 信息 128 | 129 |  130 | 131 | 4. 配置完成后,提交代码到 Github 时,就会自动部署项目中的 `example` 函数到云开发中,即时函数的环境变量也会设置成功 132 | 133 | ## 谁在用 Tencent CloudBase Github Action 134 | 135 | - [Linux 中国: TLDR 命令查询工具](https://github.com/LCTT/tldr.linux.cn) 136 | - [EndureBlaze/EndureBlaze.github.io](https://github.com/EndureBlaze/EndureBlaze.github.io) 137 | 138 | ## Contributors ✨ 139 | 140 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 141 | 142 | 143 | 144 | 145 |
beet 💻 |
148 | Zhaoxuan "Tony" Wu 💻 |
149 |