Skip to content

Commit

Permalink
Generate list of changed files without use of action
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Jan 19, 2023
1 parent 740cb3f commit 3a8fa64
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions .github/workflows/lint_changed_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ jobs:
# Get list of changed files:
- name: 'Get list of changed files'
id: changed-files
uses: tj-actions/changed-files@v35
with:
separator: ' '
run: |
if [ -n "${{ github.event.pull_request.number }}" ]; then
# Get the list of changed files in pull request via the GitHub API. We use `awk` to get the value of the link header with the URL for the next page of results, and keep requesting next pages until all the files are retrieved:
files=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ github.event.pull_request.number }}/files?page=1&per_page=100" -D - | awk '{if (match($0, "Link:")){print}}' | awk '{print $2}' | tr -d '<>' | tr -d ',' | xargs -I {} curl -s -H "Accept: application/vnd.github.v3+json" {} | jq -r '.[] | .filename')
else
# Get changed files by comparing the current commit to the commit before the push event:
files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
fi
echo "files=${files}" >> $GITHUB_OUTPUT
# Lint file names
- name: 'Lint file names'
Expand All @@ -94,13 +100,13 @@ jobs:
lint_filenames="${root}/lib/node_modules/@stdlib/_tools/lint/filenames/bin/cli"
# Lint filenames:
echo "${{ steps.changed-files.outputs.all_changed_files }}" || "${lint_filenames}"
echo "${{ steps.changed-files.outputs.files }}" || "${lint_filenames}"
# Lint Markdown files:
- name: 'Lint Markdown files'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.md$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.md$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
make lint-markdown-files FILES="${files}"
fi
Expand All @@ -109,7 +115,7 @@ jobs:
- name: 'Lint shell script files'
if: success() || failure()
run: |
files=$(echo "${{ steps.random-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -vE '\.(js|md|json|ts|c|h)$' | while read -r file; do head -n1 "$file" | grep -q '^\#\!/usr/bin/env bash' && echo "$file"; done | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ' ' '\n' | grep -vE '\.(js|md|json|ts|c|h)$' | while read -r file; do head -n1 "$file" | grep -q '^\#\!/usr/bin/env bash' && echo "$file"; done | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
# Install shellcheck:
make install-deps-shellcheck
Expand All @@ -128,7 +134,7 @@ jobs:
# Define the path to a utility for linting package.json files:
lint_package_json="${root}/lib/node_modules/@stdlib/_tools/lint/pkg-json/bin/cli"
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep 'package\.json$' | grep -v 'datapackage\.json$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep 'package\.json$' | grep -v 'datapackage\.json$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
echo "Linting package.json files that have changed..."
printf "${files}" | "${lint_package_json}" --split=" "
Expand All @@ -146,7 +152,7 @@ jobs:
# Define the path to a utility for linting REPL help files:
lint_repl_help="${root}/lib/node_modules/@stdlib/_tools/lint/repl-txt/bin/cli"
files=$(echo ${{ steps.changed-files.outputs.all_changed_files }} | tr ' ' '\n' | grep 'repl\.txt$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo ${{ steps.changed-files.outputs.files }} | tr ' ' '\n' | grep 'repl\.txt$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
printf "${files}" | "${lint_repl_help}" --split=" "
fi
Expand All @@ -168,31 +174,31 @@ jobs:
eslint_benchmarks_conf="${root}/etc/eslint/.eslintrc.benchmarks.js"
# Lint JavaScript source files:
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}"
fi
# Lint JavaScript command-line interfaces...
file=$(echo ${{ steps.changed-files.outputs.all_changed_files }} | tr ' ' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ' | sed 's/ $//')
file=$(echo ${{ steps.changed-files.outputs.files }} | tr ' ' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${file}" ]]; then
make lint-javascript-files FILES="${file}"
fi
# Lint JavaScript example files:
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}" ESLINT_CONF="${eslint_examples_conf}"
fi
# Lint JavaScript test files:
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '/test/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/test/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}" ESLINT_CONF="${eslint_tests_conf}"
fi
# Lint JavaScript benchmark files:
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}"
fi
Expand All @@ -201,7 +207,7 @@ jobs:
- name: 'Lint Python files'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.py$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.py$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
# Install Python dependencies:
make install-deps-python
Expand All @@ -215,7 +221,7 @@ jobs:
if: success() || failure()
id: check-r-files
run: |
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.R$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.R$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
# Add space-separated list of R files to output:
echo "files=${files}" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -258,31 +264,31 @@ jobs:
cppcheck_benchmarks_suppressions_list="${root}/etc/cppcheck/suppressions.benchmarks.txt"
# Install cppcheck if C files have changed:
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.c$|\.h$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.c$|\.h$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make install-deps-cppcheck
fi
# Lint C source files...
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.c$' | grep -v -e '/examples' -e '/test' -e '/benchmark' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.c$' | grep -v -e '/examples' -e '/test' -e '/benchmark' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}"
fi
# Lint C example files...
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '/examples/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/examples/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}" CPPCHECK_SUPPRESSIONS_LIST="${cppcheck_examples_suppressions_list}"
fi
# Lint C test fixtures files...
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '/test/fixtures/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/test/fixtures/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}" CPPCHECK_SUPPRESSIONS_LIST="${cppcheck_tests_fixtures_suppressions_list}"
fi
# Lint C benchmark files...
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '/benchmark/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/benchmark/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}" CPPCHECK_SUPPRESSIONS_LIST="${cppcheck_benchmarks_suppressions_list}"
fi
Expand All @@ -291,7 +297,7 @@ jobs:
- name: 'Lint TypeScript declarations files'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.d\.ts$' | tr '\n' ' ' | sed 's/ $//')
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.d\.ts$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-typescript-declarations-files FILES="${files}"
fi
Expand All @@ -300,7 +306,7 @@ jobs:
- name: 'Lint license headers'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}")
files=$(echo "${{ steps.changed-files.outputs.files }}")
if [[ -n "${files}" ]]; then
make lint-license-headers-files FILES="${files}"
fi

0 comments on commit 3a8fa64

Please sign in to comment.