Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github actions: don't use tj-actions/changed-files #13748

Merged
merged 24 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/actions/pr_changed_files/action.yml
Original file line number Diff line number Diff line change
@@ -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
ericLemanissier marked this conversation as resolved.
Show resolved Hide resolved
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")
12 changes: 3 additions & 9 deletions .github/workflows/linter-conan-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/linter-yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down