Skip to content

Commit c556d55

Browse files
committed
build: refactor to check even when package.json files have not changed
1 parent 149c4ef commit c556d55

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

.github/workflows/lint_changed_files.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,34 @@ jobs:
152152
update_package_json_directories="${root}/lib/node_modules/@stdlib/_tools/package-json/scripts/update_directories"
153153
update_package_json_gypfile="${root}/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile"
154154
155+
# Lint changed package.json files:
155156
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep 'package\.json$' | grep -v 'datapackage\.json$' | tr '\n' ' ' | sed 's/ $//')
156157
if [ -n "${files}" ]; then
157158
echo "Linting package.json files that have changed..."
158159
printf "${files}" | "${lint_package_json}" --split=" "
159-
160-
# Check if metadata fields need to be updated:
161-
dirs=$(dirname ${files})
162-
needs_changes=0
163-
for dir in ${dirs}; do
164-
echo "Checking package.json in ${dir}..."
165-
"${update_package_json_directories}" "${dir}"
166-
"${update_package_json_gypfile}" "${dir}"
167-
if [[ `git status --porcelain` ]]; then
168-
echo "::error::Package.json in ${dir} needs updates to directories and/or gypfile fields"
169-
git diff
170-
needs_changes=1
171-
fi
172-
done
173-
174-
# Exit with failure if any needed changes were detected:
175-
if [ $needs_changes -eq 1 ]; then
176-
exit 1
177-
fi
178160
else
179161
echo "No package.json files to lint."
180162
fi
181163
164+
# Check if metadata fields need to be updated in package.json files of affected packages:
165+
dirs=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | xargs dirname | sort -u)
166+
needs_changes=0
167+
for dir in ${dirs}; do
168+
echo "Checking package.json in ${dir}..."
169+
"${update_package_json_directories}" "${dir}"
170+
"${update_package_json_gypfile}" "${dir}"
171+
if [[ `git status --porcelain` ]]; then
172+
echo "::error::Package.json in ${dir} needs updates to directories and/or gypfile fields"
173+
git diff
174+
needs_changes=1
175+
fi
176+
done
177+
178+
# Exit with failure if any needed changes were detected:
179+
if [ $needs_changes -eq 1 ]; then
180+
exit 1
181+
fi
182+
182183
# Lint REPL help files...
183184
- name: 'Lint REPL help files'
184185
if: success() || failure()

0 commit comments

Comments
 (0)