GitHub 不允许将秘密传递给可重复使用的工作流

GitHub does not allow secrets to be passed down to reusable workflow

我正在尝试将秘密传递给可重复使用的工作流程,如下所示: 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}}