From 83dfd138e81a9009777f4185df66f0820e504b63 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Wed, 23 Nov 2022 15:46:30 +0100 Subject: [PATCH] (#13748) github actions: don't use tj-actions/changed-files * github actions: don't use tj-actions/changed-files avoids all its bugs alltogether eg https://github.com/tj-actions/changed-files/issues/704 * fix forks * add github token * don't use PurePath.is_relative_to * fixup * add yml error * add conanfile.py error * add test error * touch linter * use fnmatch * fxup * use a dedicated action * Update config.yml * Update conanfile.py * Update conanfile.py * Update conanv2_transition.py * improve file matching python's fnmatch treats * as any character any number oftime, including /. This is not coherent with bash, which excludes / from *. The fix is to split the pattern and filenames by / and call fnmatch on each part. * add a test error * fixup * silence warning * Update conanfile.py Co-authored-by: Chris Mc --- .github/actions/pr_changed_files/action.yml | 49 +++++++++++++++++++++ .github/workflows/linter-conan-v2.yml | 12 ++--- .github/workflows/linter-yaml.yml | 12 ++--- 3 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 .github/actions/pr_changed_files/action.yml diff --git a/.github/actions/pr_changed_files/action.yml b/.github/actions/pr_changed_files/action.yml new file mode 100644 index 0000000000000..2afad1b52a531 --- /dev/null +++ b/.github/actions/pr_changed_files/action.yml @@ -0,0 +1,49 @@ +name: 'Changed files in PR' +description: 'Get all changed files in a Pull Request' +author: 'ericLemanissier' +inputs: + files: + description: "Check for changes using only this list of files (Defaults to the entire repo)" + required: false + default: "" + +outputs: + all_changed_files: + description: List of all copied, modified, and added files. + value: ${{ steps.changed-files.outputs.all_changed_files }} + any_changed: + description: Return true only when any files provided using the files input have changed. + value: ${{ steps.changed-files.outputs.any_changed }} +runs: + using: "composite" + steps: + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Get changed files + id: changed-files + shell: python + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + import json + import subprocess + import fnmatch + import os + from pathlib import Path + + patterns = [Path(p).parts for p in '''${{ inputs.files }}'''.splitlines()] + + res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True) + files = [] + for f in json.loads(res.stdout): + filename = Path(f["filename"]).parts + for pattern in patterns: + if len(pattern) != len(filename): + continue + if all(fnmatch.fnmatch(filename[i], pattern[i]) for i in range(len(pattern))): + files.append(f["filename"]) + break + with open(os.getenv("GITHUB_OUTPUT"), "a") as output_file: + output_file.write(f"any_changed={'true' if files else 'false'}\n") + output_file.write(f"all_changed_files={' '.join(files)}\n") diff --git a/.github/workflows/linter-conan-v2.yml b/.github/workflows/linter-conan-v2.yml index 7a00231462537..146c807267d26 100644 --- a/.github/workflows/linter-conan-v2.yml +++ b/.github/workflows/linter-conan-v2.yml @@ -15,10 +15,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - fetch-depth: 2 - name: Get changed files - uses: tj-actions/changed-files@v20 + uses: ./.github/actions/pr_changed_files id: changed_files with: files: | @@ -83,11 +81,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v20 + uses: ./.github/actions/pr_changed_files with: files: | recipes/*/*/conanfile.py @@ -118,11 +114,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v20 + uses: ./.github/actions/pr_changed_files with: files: | recipes/*/*/test_*/conanfile.py diff --git a/.github/workflows/linter-yaml.yml b/.github/workflows/linter-yaml.yml index edc701a2db86d..d7d4050e8071d 100644 --- a/.github/workflows/linter-yaml.yml +++ b/.github/workflows/linter-yaml.yml @@ -16,11 +16,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - name: Get changed files - uses: tj-actions/changed-files@v20 + uses: ./.github/actions/pr_changed_files id: changed_files with: files: | @@ -69,9 +66,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - uses: actions/setup-python@v4 with: python-version: ${{ env.PYVER }} @@ -83,7 +77,7 @@ jobs: - name: Get changed files (config) id: changed_files_config if: always() - uses: tj-actions/changed-files@v20 + uses: ./.github/actions/pr_changed_files with: files: | ${{ env.CONFIG_FILES_PATH }} @@ -105,7 +99,7 @@ jobs: - name: Get changed files (conandata) id: changed_files_conandata if: always() - uses: tj-actions/changed-files@v20 + uses: ./.github/actions/pr_changed_files with: files: | ${{ env.CONANDATA_FILES_PATH }}