在GitHub操作中检索修改文件列表

10

我目前正在使用foo-software/lighthouse-check-action自动进行审核。但由于urls必须是硬编码的,所以当希望仅对提交中修改的页面进行审核并根据这些页面失败时,它就不那么有用。

有没有办法实现上述功能?我查看了一些操作,例如actions/get-changed-files,但我无法使其工作。我还查看了GitHub事件和引用文档,但无法找到相关信息。


尝试使用此 GitHub 存储库 - https://github.com/aseem-hegshetye/gha-files-changed - Aseem
2个回答

10

lots0logs/gh-action-get-changed-files操作目前由于此问题而无法使用。请看一下jitterbit/get-changed-files操作。对我来说它完美地工作:

.github/workflows/test.yml

name: Test

on: push

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.1.0
      - uses: jitterbit/get-changed-files@v1
        id: abc
        with:
          format: space-delimited
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Printing
        run: |
          echo "All:"
          echo "${{ steps.abc.outputs.all }}"
          echo "Added:"
          echo "${{ steps.abc.outputs.added }}"
          echo "Removed:"
          echo "${{ steps.abc.outputs.removed }}"
          echo "Renamed:"
          echo "${{ steps.abc.outputs.renamed }}"
          echo "Modified:"
          echo "${{ steps.abc.outputs.modified }}"
          echo "Added+Modified:"
          echo "${{ steps.abc.outputs.added_modified }}"

日志输出:

2020-05-15T13:47:15.5267496Z All:
2020-05-15T13:47:15.5268424Z .github/workflows/test.yml .tidy-renamed2 Test.ts hello.py
2020-05-15T13:47:15.5268537Z Added:
2020-05-15T13:47:15.5268609Z hello.py
2020-05-15T13:47:15.5268697Z Removed:
2020-05-15T13:47:15.5268787Z Test.ts
2020-05-15T13:47:15.5268880Z Renamed:
2020-05-15T13:47:15.5269260Z .tidy-renamed2
2020-05-15T13:47:15.5269357Z Modified:
2020-05-15T13:47:15.5269450Z .github/workflows/test.yml
2020-05-15T13:47:15.5269547Z Added+Modified:
2020-05-15T13:47:15.5269625Z .github/workflows/test.yml hello.py
2020-05-15T13:47:15.5306656Z Post job cleanup.

目前这个功能无法正常工作,如果您已经压缩了提交记录,它似乎只会返回一个空列表。详见 https://github.com/jitterbit/get-changed-files/issues/11#issuecomment-718254652。 - reim
似乎已经在一个分支存储库中修复了这个问题(https://github.com/Ana06/get-changed-files/releases/tag/v1.2),所以现在人们实际上可以使用它。或者指定提交哈希而不是标签,例如jitterbit/get-changed-files@b17fbb0,在以前的版本中可以工作。 - fabasoad

7

在尝试了上述两个插件和其他一些插件后,我决定采用以下方法:

- uses: actions/checkout@v2
  with:
    fetch-depth: 0
- name: (CI) Dependencies update check
  run: |
    current_commit=`git log -n 1 --pretty=format:%H`
    echo $current_commit
    last_deps_mod_commit=`git log -n 1 --pretty=format:%H -- composer.json`
    echo $last_deps_mod_commit
    if [ $current_commit == $last_deps_mod_commit ]; then echo USE_LOCK=0 > ci.conf; else echo USE_LOCK=1 > ci.conf; fi

请注意,它必须是完整的检出(深度为0),而不是扁平的检出,否则它将始终返回true。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接