From 6c2ede86b4f049901f1df111ce911a6d9b9024f1 Mon Sep 17 00:00:00 2001 From: shylocks Date: Mon, 25 Jan 2021 22:02:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E4=B8=8E=E8=A7=A6=E5=8F=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy_tencent_scf.yml | 1 + tencentscf.js | 46 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy_tencent_scf.yml b/.github/workflows/deploy_tencent_scf.yml index 8b0b1016..04d1a3df 100644 --- a/.github/workflows/deploy_tencent_scf.yml +++ b/.github/workflows/deploy_tencent_scf.yml @@ -22,6 +22,7 @@ jobs: run: | npm install npm install tencentcloud-sdk-nodejs + npm install js-yaml - name: "将Secrets里面配置的变量添加到severless.yml里面作为环境变量" run: | diff --git a/tencentscf.js b/tencentscf.js index f5d23e02..ba6a9bab 100644 --- a/tencentscf.js +++ b/tencentscf.js @@ -20,7 +20,7 @@ const clientConfig = { }; const client = new ScfClient(clientConfig); -const params = { +let params = { "Handler": "index.main_handler", "FunctionName": process.env.TENCENT_FUNCTION_NAME, // 云函数程序名,例如 jd_scripts "ZipFile": contents_in_base64 @@ -33,3 +33,47 @@ client.UpdateFunctionCode(params).then( console.error("error", err); } ); + +// 更新环境变量 +let vars = [] +for(let key in process.env){ + vars.push({ + "Key": key, + "Value": process.env[key] + }) +} + +params = { + "Environment": { + "Variables": vars + } +}; +client.UpdateFunctionConfiguration(params).then( + (data) => { + console.log(data); + }, + (err) => { + console.error("error", err); + } +); + +// 更新触发器 +const inputYML = 'serverless.yml'; +const yaml = require('js-yaml'); +const obj = yaml.load(fs.readFileSync(inputYML, {encoding: 'utf-8'})) +for(let vo of obj.inputs.events){ + let param = { + 'Type' : "timer", + 'TriggerDesc' : vo.timer.parameters.cronExpression, + 'CustomArgument' : vo.timer.parameters.argument, + 'Enable' : "true" + } + client.CreateTrigger(param).then( + (data) => { + console.log(data); + }, + (err) => { + console.error("error", err); + } + ); +}