我正在尝试将秘密传递给可重用的工作流程,如下所示: https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
但是管道失败了,说明:
The workflow is not valid. .github/workflows/test.workflow-test.yml (Line: 17, Col: 9): Unexpected value 'secrets'
我的 .github/actions/test/action.yml 看起来像这样:
name: Reusable workflow example
on:
workflow_call:
inputs:
username:
required: true
type: string
secrets:
token:
required: true
jobs:
example_job:
name: show
runs-on: ubuntu-latest
steps:
- name: show data
runs: echo ${{ secrets.token }}
我相应地称呼它:
name: Call a reusable workflow
on:
push:
branches:
- "feature/workflow-test"
jobs:
my-test-job:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- uses: ./.github/actions/test
with:
username: John
secrets:
token: secret Token
我在这里缺少什么?它与 GitHub 文档中的代码示例几乎相同。
从你的例子中我可以看出两个问题。
可重用工作流程的路径需要是
.github/workflows
。目前不支持子目录。
此外,您调用可重用工作流程的方式也不符合文档。
这是一个应该有效的示例:
name: Call a reusable workflow
on:
workflow_dispatch:
jobs:
reusable-job:
uses: <owner>/<repo>/.github/workflows/<reusable workflow>@master
with:
username: john
secrets:
token: test
以及以下可重复使用的工作流程:
name: Reusable workflow
on:
workflow_call:
inputs:
username:
required: true
type: string
secrets:
token:
required: true
jobs:
show:
runs-on: ubuntu-latest
steps:
- name: Show data
run: |
echo ${{ inputs.username }}
echo ${{ secrets.token}}
问题是您在一个步骤内调用工作流程,而这作为一项作业受到支持。
你应该拥有的是:
jobs:
my-test-job:
uses: ./.github/actions/test
with:
username: John
secrets:
token: secret Token