auto-deploy-tencent-scf #25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/June1991/serverless-express | |
name: auto-deploy-tencent-scf | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 2 * * 1,3,5" # 每周一、三、五的10点 | |
env: | |
IsAutoDeployTencentScf: ${{ secrets.IS_AUTO_DEPLOY_TENCENT_SCF }} # 是否开启自动部署云函数 | |
jobs: | |
pre-check: | |
runs-on: ubuntu-latest | |
outputs: | |
result: ${{ steps.check.outputs.result }} # 不能直接传递secrets的值,否则会被skip,需要转一下 | |
steps: | |
- id: check | |
run: | | |
[ ${{ github.event_name }} == 'workflow_dispatch' -o true == "${{ env.IsAutoDeployTencentScf }}" ] && echo "result=开启" >> $GITHUB_OUTPUT || echo "result=关闭" >> $GITHUB_OUTPUT | |
deploy: | |
name: deploy serverless | |
runs-on: ubuntu-latest | |
needs: pre-check | |
# if: env.IsAutoDeployTencentScf=='true' # 这里job.if读取不到env或secrets,很坑...但是发现可以读到needs的outputs值 | |
if: needs.pre-check.outputs.result=='开启' | |
steps: | |
- name: clone local repository | |
uses: actions/checkout@v3 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
- name: install serverless | |
run: npm i -g serverless-cloud-framework | |
- name: deploy serverless | |
run: | | |
cd ./tencentScf | |
echo "开始配置云函数:" | |
echo "$Tencent_Serverless_Yml" | |
[ -z "$Tencent_Serverless_Yml" ] && echo "未配置serverless.yml,使用默认值" || echo "$Tencent_Serverless_Yml" > serverless.yml | |
echo "开始发布项目" | |
chmod +x publish.sh | |
./publish.sh | |
echo "开始部署到云函数" | |
scf deploy | |
env: # 环境变量 | |
STAGE: dev #您的部署环境 | |
SERVERLESS_PLATFORM_VENDOR: tencent # serverless海外默认为aws部署,配置为腾讯部署 | |
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} # 您的腾讯云账号sercret ID | |
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} # 您的腾讯云账号sercret key | |
Tencent_Serverless_Yml: ${{ secrets.TENCENT_SERVERLESS_YML }} # 云函数配置(区域、环境变量、触发器等) |