【发布时间】:2022-08-11 15:31:53
【问题描述】:
我有一个包,它是我组织内多个其他包的核心依赖项。我的目标是编写一个动作来自动化/促进这些反向依赖的测试。粗略地说,该行动应该:
- 触发 PR 中的评论。
- 使用该 PR 中的代码运行一组反向依赖项的单元测试。
- 回复 PR 并评论哪些测试失败(如果有)。
第 1 步和第 3 步我开始工作了,但是第 2 步遇到了问题。我目前的解决方案是硬编码所有作业输出,以将第 2 步的结果传递到第 3 步,但我想知道是否有避免硬编码的方法。
以下示例工作流程说明了我的问题:
name: Test
on: push
jobs:
unit-tests:
runs-on: ${{ matrix.os }}
continue-on-error: true
name: ${{ matrix.os }} (${{ matrix.pkg }})
strategy:
fail-fast: false
matrix:
# there will be more pkgs and OSes
os: [ubuntu-latest]
pkg: [pkgA, pkgB]
# how to avoid hardcoding these?
outputs:
ubuntu-latest-pkgA: ${{ steps.update-output.outputs.ubuntu-latest-pkgA }}
ubuntu-latest-pkgB: ${{ steps.update-output.outputs.ubuntu-latest-pkgB }}
steps:
- uses: actions/checkout@v2
- name: fake unit tests
run: |
exit 1 # fail all tests for now
shell: bash
- name: set error if tests fail
id: update-output
if: ${{ failure() }}
run: echo \"::set-output name=${{ matrix.os }}-${{ matrix.pkg }}::error\"
shell: bash
aggregate-results:
runs-on: ubuntu-latest
needs: unit-tests
steps:
- name: Aggregate results
env:
NEEDS: ${{ toJSON(needs) }}
run: echo \"$NEEDS\"
作业聚合结果(受this post 启发)运行良好并打印:
{
\"unit-tests\": {
\"result\": \"success\",
\"outputs\": {
\"ubuntu-latest-pkgA\": \"error\",
\"ubuntu-latest-pkgB\": \"error\"
}
}
}
我可以用它来创建内容丰富的评论。但是,unit-tests 的工作要求我对 os 和 pkg 的所有组合的输出进行硬编码。有没有办法动态地做到这一点?
标签: github-actions