带有策略矩阵的作业的动态输出

Van*_*man 26 github-actions

我有一个包,它是我组织内多个其他包的核心依赖项。我的目标是编写一个操作来自动化/促进这些反向依赖项的测试。粗略地说,该行动应该:

\n
    \n
  • 触发 PR 中的评论。
  • \n
  • 使用该 PR 中的代码运行一组反向​​依赖项的单元测试。
  • \n
  • 回复 PR,并评论哪些测试失败(如果有)。
  • \n
\n

步骤 1 和 3 我开始工作,但我\xe2\x80\x99m 遇到了步骤 2 的问题。我当前的解决方案是对所有作业输出进行硬编码,以将结果从步骤 2 传递到步骤 3,但我想知道如果有办法避免硬编码。

\n

以下示例工作流程说明了我的问题:

\n
name: Test\non: push\n\njobs:\n  unit-tests:\n    runs-on: ${{ matrix.os }}\n    continue-on-error: true\n\n    name: ${{ matrix.os }} (${{ matrix.pkg }})\n\n    strategy:\n      fail-fast: false\n      matrix:\n        # there will be more pkgs and OSes\n        os: [ubuntu-latest]\n        pkg: [pkgA, pkgB]\n\n    # how to avoid hardcoding these?\n    outputs:\n      ubuntu-latest-pkgA: ${{ steps.update-output.outputs.ubuntu-latest-pkgA }}\n      ubuntu-latest-pkgB: ${{ steps.update-output.outputs.ubuntu-latest-pkgB }}     \n  \n    steps:\n      - uses: actions/checkout@v2\n      \n      - name: fake unit tests\n        run: |\n          exit 1 # fail all tests for now\n        shell: bash\n\n      - name: set error if tests fail\n        id: update-output\n        if: ${{ failure() }}\n        run: echo "::set-output name=${{ matrix.os }}-${{ matrix.pkg }}::error"\n        shell: bash\n\n  aggregate-results:\n    runs-on: ubuntu-latest\n    needs: unit-tests\n    steps:\n      - name: Aggregate results\n        env:\n          NEEDS: ${{ toJSON(needs) }}\n        run: echo "$NEEDS"\n
Run Code Online (Sandbox Code Playgroud)\n

这项工作aggregate-results(受这篇文章的启发)运行良好并打印:

\n
{\n  "unit-tests": {\n    "result": "success",\n    "outputs": {\n      "ubuntu-latest-pkgA": "error",\n      "ubuntu-latest-pkgB": "error"\n    }\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我可以用它来创建内容丰富的评论。然而,这项工作要求我对和unit-tests的所有组合的输出进行硬编码。有没有办法动态地做到这一点?ospkg

\n

小智 2

我也在寻找这个解决方案。实现这一方法的唯一方法是切换到可重用的工作流程,该工作流程允许访问一个特定的工作上下文

https://docs.github.com/en/actions/learn-github-actions/contexts#jobs-context