From 64ee135f3635bca3d8588d6dd4657ee04a57b9e9 Mon Sep 17 00:00:00 2001 From: DoveBoy <393366046@qq.com> Date: Mon, 25 Jan 2021 10:53:37 +0800 Subject: [PATCH 1/3] Create tencentscf.js --- tencentscf.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tencentscf.js diff --git a/tencentscf.js b/tencentscf.js new file mode 100644 index 00000000..ca20172c --- /dev/null +++ b/tencentscf.js @@ -0,0 +1,35 @@ +// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher +const tencentcloud = require("tencentcloud-sdk-nodejs"); +const fs = require('fs') +const file_buffer = fs.readFileSync('./myfile.zip'); +const contents_in_base64 = file_buffer.toString('base64'); + +const ScfClient = tencentcloud.scf.v20180416.Client; + +const clientConfig = { + credential: { + secretId: process.env.TENCENT_SECRET_ID, + secretKey: process.env.TENCENT_SECRET_KEY, + }, + region: "ap-hongkong", + profile: { + httpProfile: { + endpoint: "scf.tencentcloudapi.com", + }, + }, +}; + +const client = new ScfClient(clientConfig); +const params = { + "Handler": "index.main_handler", + "FunctionName": "jd", + "ZipFile": contents_in_base64 +}; +client.UpdateFunctionCode(params).then( + (data) => { + console.log(data); + }, + (err) => { + console.error("error", err); + } +); From d212ef15350df63a2daf9e70569f1e4978f42a62 Mon Sep 17 00:00:00 2001 From: DoveBoy <393366046@qq.com> Date: Mon, 25 Jan 2021 10:55:40 +0800 Subject: [PATCH 2/3] Update deploy_tencent_scf.yml --- .github/workflows/deploy_tencent_scf.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_tencent_scf.yml b/.github/workflows/deploy_tencent_scf.yml index 844d094e..20c2d8ac 100644 --- a/.github/workflows/deploy_tencent_scf.yml +++ b/.github/workflows/deploy_tencent_scf.yml @@ -18,10 +18,10 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: "安装依赖和serverless工具" + - name: "安装依赖" run: | npm install - sudo npm install serverless -g + npm install tencentcloud-sdk-nodejs - name: "将Secrets里面配置的变量添加到severless.yml里面作为环境变量" run: | @@ -157,6 +157,8 @@ jobs: DREAMFACTORY_FORBID_ACCOUNT: ${{ secrets.DREAMFACTORY_FORBID_ACCOUNT}} JDFACTORY_FORBID_ACCOUNT: ${{ secrets.JDFACTORY_FORBID_ACCOUNT}} + - name: "压缩文件夹" + run: zip -r myfile.zip ./* - name: "部署到腾讯云函数" run: serverless deploy env: From e390101a5d5747a9dc115476c8c2865ddc5cc7ae Mon Sep 17 00:00:00 2001 From: DoveBoy <393366046@qq.com> Date: Mon, 25 Jan 2021 10:59:02 +0800 Subject: [PATCH 3/3] Update deploy_tencent_scf.yml --- .github/workflows/deploy_tencent_scf.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_tencent_scf.yml b/.github/workflows/deploy_tencent_scf.yml index 20c2d8ac..70d6d17e 100644 --- a/.github/workflows/deploy_tencent_scf.yml +++ b/.github/workflows/deploy_tencent_scf.yml @@ -160,7 +160,7 @@ jobs: - name: "压缩文件夹" run: zip -r myfile.zip ./* - name: "部署到腾讯云函数" - run: serverless deploy + run: node tencentscf.js env: STAGE: dev SERVERLESS_PLATFORM_VENDOR: tencent