使用值数组重复GitHub Actions工作流程中的步骤

时间:2019-12-04 16:18:00

标签: yaml workflow github-actions

我正在尝试创建GitHub Actions工作流,该工作流将收集上次提交中更改的特定路径,并对每个收集的路径(如果有)运行一个步骤。

当前,在我的工作流程中,我正在创建路径数组,但不确定如何继续执行该数组:

name: Test

on:
  push

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      # This step will create "an array" of strings, e.g. "path1 path2 path3"
      - name: array
        id: arr
        run: |
          arr=()
          for i in "$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }})"
          do
            if [[ $i == *"path1"* ]]; then
              arr+=("path1")
            fi
            if [[ $i == *"path2"* ]]; then
              arr+=("path2")
            fi
          done
          echo ::set-output name=arr::${arr[@]}

      # How to run this step by iterating the `${{ steps.arr.outputs.arr }}`?
      - name: reviewdog-lint
        uses: reviewdog/action-eslint@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-review
          eslint_flags: 'my_project/some_folder/${{ SINGLE_PATH }}/'  # `SINGLE_PATH` would be a path from the array

首先,这样的事情是否有可能?如果不是,那么建议使用什么方法来遍历某些值并将其用作其他工作流步骤中的参数?

1 个答案:

答案 0 :(得分:0)

不运行它就很难说,但是我想说,您需要在第二步中通过将输出分配给变量来使用输出,例如:

env:
          OUTPUT: ${{ steps.id.outputs.arr }}

然后,您将$OUTPUT用作操作内的环境变量。

该特定操作的问题是一次需要提交一次。但是您可以check out the code,它是一个shell脚本。您可以从第15行分支它,并使其分割输入并在其上运行一个循环,将eslint应用于其中的每一个。

相关问题