我有一个 Github 复合操作,它使用无服务器框架来部署我的堆栈。该动作需要两个输入,
serverless-path
和 stage
,包括以下步骤:
inputs:
serverless-path:
description: 'The relative path to the project root.'
type: string
required: true
stage:
description: 'The serverless deployment stage to use.'
type: string
required: true
default: 'dev'
otherArgs:
description: 'Additional arguments to provide to the serverless deploy command.'
type: string
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.13.0'
cache: yarn
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-east-1
role-to-assume: ***
- name: Install project dependencies
shell: bash
run: yarn install --frozen-lockfile
working-directory: ${{ inputs.serverless-path }}
- name: debug step
shell: bash
run: yarn run serverless print --stage ${STAGE}
working-directory: ${{ inputs.serverless-path }}
env:
STAGE: ${{ inputs.stage }}
但是,当我运行此操作时,无服务器命令失败并出现以下错误:
Error:
Cannot resolve serverless.yml: Variables resolution errored with:
- Cannot resolve variable at "provider.environment.SHOP": Value not found at "self" source
有趣的是,如果我将
${{ inputs.stage }}
替换为像 dev
这样的静态字符串,无服务器命令将成功运行。这让我怀疑问题与如何将输入传递给无服务器命令有关。
什么可能导致此错误,我该如何解决?
更新
添加一些额外的调试信息。我尝试了几件事来测试
${{inputs.stage}}
的值是否有效。
echo '${{ inputs.stage }}'
。输出看起来是正确的:Run echo 'dev'
echo 'dev'
shell: /usr/bin/bash -e {0}
...
dev
provider:
...
environment:
CUSTOM_STAGE: ${self:custom.stage}
OPT_STAGE: ${opt:stage}
SLS_STAGE: ${sls:stage}
# SHOP: ${self:custom.environment.${self:custom.stage}.SHOP}
...
custom:
stage: ${opt:stage, 'default'}
当我运行它时,
sls print
命令实际上没有错误地执行,并且阶段定义都符合预期,即它们从 dev
:中获取
inputs.stage
值
provider:
...
CUSTOM_STAGE: dev
OPT_STAGE: dev
SLS_STAGE: dev
所以看起来好像这个值实际上正在进入无服务器变量解析过程,但是不知何故当涉及嵌套变量时,并且该值是从 Github 的
inputs
中获取的,它爆炸了......