git操作将工作流触发器保存到变量

时间:2021-07-06 11:08:12

标签: github github-actions

我写了一个 Github action 工作流,它只有在某些特定文件更新时才会触发:

name: CI

on:
  push:
    paths:
    ### If a push was applied on one of these files, the CI workflow is triggered.###
    ### I want to know which file triggered the CI workflow and save it to a variable s I can use later in the CI steps ###
    - 'dwh/helm/values-versions.yaml' 
    - 'ai/helm/values-versions.yaml'
    - 'platform/helm/values-versions.yaml'

jobs:
  copy-values-template-to-fluent-bit:
      runs-on: self-hosted
      container:
        image: ghcr.io/***/myImage
        credentials:
          username: ${{ secrets.GHCR_USER }}
          password: ${{ secrets.GHCR_PASS }}
      steps:
        - uses: actions/checkout@v2
        - name: show repo files
          run: |
            pwd
            ls -l

我需要一种方法来确定哪个文件触发了 CI 工作流并将其保存到变量中。

1 个答案:

答案 0 :(得分:0)

您可以使用此操作Get All Changed Files

- id: files
  uses: jitterbit/get-changed-files@v1
- run: |
    for changed_file in ${{ steps.files.outputs.all }}; do
      echo "Do something with this ${changed_file} to check if this is you file and set variable."
    done