如何创建具有不同步数的嵌套矩阵?

huangapple go评论54阅读模式
英文:

How to create a nested matrix with different number of steps?

问题

这是我们当前用于运行测试的矩阵配置:

strategy:
  fail-fast: false
  matrix:
    app:
      - contra-api
      - contra-database
      - contra-temporal-job-worker
      - contra-web-app
    shardIndex: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
    shardTotal: [15]

它使用了15个作业来运行每个 app 的测试。

然而,我想要调整它,使 contra-api 使用15个分片,而其他服务使用5个分片。

我可以想象以下类似的配置可能是可行的:

- app: contra-api
  shardIndex:
    - 1
    - ...
  shardTotal: 15
- app: contra-database
  ...

不过,我无法确定正确的语法。

英文:

This is our current matrix for running tests:

strategy:
  fail-fast: false
  matrix:
    app:
      - contra-api
      - contra-database
      - contra-temporal-job-worker
      - contra-web-app
    shardIndex: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
    shardTotal: [15]

It runs tests using 15 jobs for each app.

However, I would like to adjust it so that contra-api runs with 15 shards, but other services run with 5 shards.

I would imagine that something like:

- app: contra-api
  shardIndex:
    - 1
    - ...
  shardTotal: 15
- app: contra-database
  ...

would be possible, though I was not able to figure out the syntax

答案1

得分: 1

Microsoft Github Actions matrices 是一个包含数组属性的单一对象,还有 include: 属性 的附加部分,该属性是一个包含 null/boolean/number/string 属性的对象数组。

include: 属性将添加到由数组属性定义的 n 维矩阵中,include: 数组中的每个对象应具有与矩阵数组属性定义的相同属性。因此,您可以在 include: 属性下编写所有所需的 额外 组合。

所有服务/应用程序都运行在 5 个分片上,而 contra-api 运行在 15 个分片上:

  matrix:
    app:
      - contra-api
      - contra-database
      - contra-temporal-job-worker
      - contra-web-app
    shardIndex: [1,2,3,4,5]
    shardTotal: [5]
    include:
      - app: contra-api
        shardIndex: 6
        shardTotal: 15
      - app: contra-api
        shardIndex: 7
        shardTotal: 15
      - app: contra-api
        shardIndex: 8
        shardTotal: 15
      # ...
      - app: contra-api
        shardIndex: 13
        shardTotal: 15
      - app: contra-api
        shardIndex: 14
        shardTotal: 15
      - app: contra-api
        shardIndex: 15
        shardTotal: 15
英文:

Microsoft Github Actions matrices are per one single object of array properties with the addition of the include: property, which is an array of objects with null/boolean/number/string properties.

That include: property will add to n-dimensional matrix defined by the array properties and each object in the include: array should have the same properties as defined by the matrix array properties. Therefore you can just write all wanted additional combinations out under the include: property.

All services/apps run with 5 shards, and the contra-api with 15 shards:

  matrix:
    app:
      - contra-api
      - contra-database
      - contra-temporal-job-worker
      - contra-web-app
    shardIndex: [1,2,3,4,5]
    shardTotal: [5]
    include:
      - app: contra-api
        shardIndex: 6
        shardTotal: 15
      - app: contra-api
        shardIndex: 7
        shardTotal: 15
      - app: contra-api
        shardIndex: 8
        shardTotal: 15
      # ...
      - app: contra-api
        shardIndex: 13
        shardTotal: 15
      - app: contra-api
        shardIndex: 14
        shardTotal: 15
      - app: contra-api
        shardIndex: 15
        shardTotal: 15

huangapple
  • 本文由 发表于 2023年4月17日 03:09:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029849.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定