Skip to content

Commit

Permalink
use a dedicated action
Browse files Browse the repository at this point in the history
  • Loading branch information
ericLemanissier committed Oct 25, 2022
1 parent 8446626 commit d291020
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 116 deletions.
38 changes: 38 additions & 0 deletions .github/actions/pr_changed_files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Changed files in PR'
description: 'Get all changed files in a Pull Request'
author: 'ericLemanissier'
inputs:
filter:
description: "The filter"
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
- name: Get changed files
id: changed-files
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import subprocess
import fnmatch
import os
res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True)
files = json.loads(res.stdout)
files = [f["filename"] for f in files]
files = [f for f in files if fnmatch.fnmatch(f, '${{ inputs.filter }}')]
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")
89 changes: 27 additions & 62 deletions .github/workflows/linter-conan-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,23 @@ jobs:
name: Test linter changes (v2 migration)
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYVER }}
- uses: actions/checkout@v3
- name: Get changed files
uses: ./.github/actions/pr_changed_files
id: changed_files
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import subprocess
import fnmatch
import os
res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True)
files = json.loads(res.stdout)
files = [f["filename"] for f in files]
files = [f for f in files if fnmatch.fnmatch(f, 'linter/**')]
with open(os.getenv("GITHUB_OUTPUT"), "a") as output_file:
output_file.write(f"any_changed={'true' if files else 'false'}\n")
- uses: actions/checkout@v3
if: steps.changed_files.outputs.any_changed == 'true'
with:
files: |
linter/**
- name: Get Conan v1 version
id: parse_conan_v1_version
if: steps.changed_files.outputs.any_changed == 'true'
uses: mikefarah/yq@master
with:
cmd: yq '.conan.version' '.c3i/config_v1.yml'
- uses: actions/setup-python@v4
if: steps.changed_files.outputs.any_changed == 'true'
with:
python-version: ${{ env.PYVER }}
- name: Install requirements
if: steps.changed_files.outputs.any_changed == 'true'
run: |
Expand Down Expand Up @@ -91,35 +80,23 @@ jobs:
name: Lint changed conanfile.py (v2 migration)
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYVER }}
- uses: actions/checkout@v3
- name: Get changed files
id: changed-files
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import subprocess
import fnmatch
import os
res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True)
files = json.loads(res.stdout)
files = [f["filename"] for f in files]
files = [f for f in files if fnmatch.fnmatch(f, 'recipes/*/*/conanfile.py')]
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")
- uses: actions/checkout@v3
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/actions/pr_changed_files
with:
files: |
recipes/*/*/conanfile.py
- name: Get Conan v1 version
id: parse_conan_v1_version
if: steps.changed-files.outputs.any_changed == 'true'
uses: mikefarah/yq@master
with:
cmd: yq '.conan.version' '.c3i/config_v1.yml'
- uses: actions/setup-python@v4
if: steps.changed-files.outputs.any_changed == 'true'
with:
python-version: ${{ env.PYVER }}
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: |
Expand All @@ -136,35 +113,23 @@ jobs:
name: Lint changed test_package/conanfile.py (v2 migration)
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYVER }}
- uses: actions/checkout@v3
- name: Get changed files
id: changed-files
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import subprocess
import fnmatch
import os
res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True)
files = json.loads(res.stdout)
files = [f["filename"] for f in files]
files = [f for f in files if fnmatch.fnmatch(f, 'recipes/*/*/test_*/conanfile.py')]
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")
- uses: actions/checkout@v3
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/actions/pr_changed_files
with:
files: |
recipes/*/*/test_*/conanfile.py
- name: Get Conan v1 version
id: parse_conan_v1_version
if: steps.changed-files.outputs.any_changed == 'true'
uses: mikefarah/yq@master
with:
cmd: yq '.conan.version' '.c3i/config_v1.yml'
- uses: actions/setup-python@v4
if: steps.changed-files.outputs.any_changed == 'true'
with:
python-version: ${{ env.PYVER }}
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: |
Expand Down
72 changes: 18 additions & 54 deletions .github/workflows/linter-yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,19 @@ jobs:
name: Test linter changes (YAML files)
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYVER }}
- uses: actions/checkout@v3
- name: Get changed files
uses: ./.github/actions/pr_changed_files
id: changed_files
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import subprocess
import fnmatch
import os
res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True)
files = json.loads(res.stdout)
files = [f["filename"] for f in files]
files = [f for f in files if fnmatch.fnmatch(f, "linter/**")]
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")
- uses: actions/checkout@v3
with:
files: |
linter/**
- uses: actions/setup-python@v4
if: steps.changed_files.outputs.any_changed == 'true'
with:
fetch-depth: 2
python-version: ${{ env.PYVER }}

- name: Install dependencies
if: steps.changed_files.outputs.any_changed == 'true'
run: pip install yamllint strictyaml argparse
Expand Down Expand Up @@ -77,6 +65,7 @@ jobs:
name: Lint changed files (YAML files)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYVER }}
Expand All @@ -88,23 +77,10 @@ jobs:
- name: Get changed files (config)
id: changed_files_config
if: always()
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import subprocess
import fnmatch
import os
res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True)
files = json.loads(res.stdout)
files = [f["filename"] for f in files]
files = [f for f in files if fnmatch.fnmatch(f, '${{ env.CONFIG_FILES_PATH }}')]
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")
- uses: actions/checkout@v3
uses: ./.github/actions/pr_changed_files
with:
files: |
${{ env.CONFIG_FILES_PATH }}
- name: Run linter (config.yml)
if: steps.changed_files_config.outputs.any_changed == 'true' && always()
Expand All @@ -123,22 +99,10 @@ jobs:
- name: Get changed files (conandata)
id: changed_files_conandata
if: always()
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import subprocess
import fnmatch
import os
res = subprocess.run(["gh", "api", "/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", "--paginate"], capture_output=True, check=True)
files = json.loads(res.stdout)
files = [f["filename"] for f in files]
files = [f for f in files if fnmatch.fnmatch(f, '${{ env.CONANDATA_FILES_PATH }}')]
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")
uses: ./.github/actions/pr_changed_files
with:
files: |
${{ env.CONANDATA_FILES_PATH }}
- name: Run linter (conandata.yml)
if: steps.changed_files_conandata.outputs.any_changed == 'true' && always()
Expand Down

0 comments on commit d291020

Please sign in to comment.