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

checks: Sync engines across all package.json files #19748

Merged
merged 2 commits into from
May 6, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Added engines in package.json


4 changes: 4 additions & 0 deletions projects/github-actions/repo-gardening/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
},
"scripts": {
"build": "ncc build src/index.js -o dist --source-map --license licenses.txt"
},
"engines": {
"node": "^14.16.0",
"yarn": "^1.3.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Added engines in package.json


4 changes: 4 additions & 0 deletions projects/github-actions/required-review/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
},
"scripts": {
"build": "ncc build src/main.js -o dist --source-map --license licenses.txt"
},
"engines": {
"node": "^14.16.0",
"yarn": "^1.3.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Added engines in package.json


4 changes: 4 additions & 0 deletions projects/js-packages/connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
],
"scripts": {
"test": "NODE_ENV=test NODE_PATH=tests:. ../../../tools/js-test-runner.js --jsdom --initfile=test-main.jsx 'glob:./!(node_modules)/**/test/*.jsx'"
},
"engines": {
"node": "^14.16.0",
"yarn": "^1.3.2"
}
}
56 changes: 55 additions & 1 deletion tools/check-copied-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ EXIT=0
# $3 - (optional) Starting delimiter. If empty, comparison starts at the start of the files.
# $4 - (optional) Ending delimiter. If empty, comparison runs to the end of the files.
compare () {
FAIL=
local FAIL=
local F D
for F in "$1" "$2"; do
for D in "$3" "$4"; do
if [[ -n "$D" ]] && ! grep -q "$D" "$F"; then
Expand All @@ -31,6 +32,7 @@ compare () {
return
fi

local LA LB
if [[ -n "$CI" && -n "$3" ]]; then
LA=$(grep --line-number --max-count=1 "$3" "$1")
LB=$(grep --line-number --max-count=1 "$3" "$2")
Expand All @@ -39,6 +41,7 @@ compare () {
LB=1
fi

local MSG A B
if [[ -n "$3" && -n "$4" ]]; then
MSG="Files $1 and $2 must be identical between \`$3\` and \`$4\`."
A=$(sed -n -e "/$3/,/$4/p" "$1")
Expand Down Expand Up @@ -71,8 +74,59 @@ compare () {
fi
}

# Compare objects in two JSON files
# $1 - First file.
# $2 - Second file.
# $3 - jq style path expression.
compareJSON () {
local JSPATH=$(jq -n "path( $3 )" 2>/dev/null)
if [[ -z "$JSPATH" ]]; then
[[ -n "$CI" ]] && printf '::error::'
error "Invalid path expression \`$3\`."
EXIT=1
return
fi

local FAIL=
local A=$(jq --argjson path "$JSPATH" 'getpath( $path )' "$1" 2>/dev/null)
local LA=$(jq --stream --arg obj "$A" --argjson path "$JSPATH" 'if length == 1 then .[0][:-1] else .[0] end | if . == $path then input_line_number - ( $obj | gsub( "[^\n]"; "" ) | length ) else empty end' "$1")
if [[ -z "$LA" ]]; then
[[ -n "$CI" ]] && printf '::error file=%s::' "$1"
error "Did not find path \`$3\` in $1."
FAIL=1
fi
local B=$(jq --argjson path "$JSPATH" 'getpath( $path )' "$2" 2>/dev/null)
local LB=$(jq --stream --arg obj "$B" --argjson path "$JSPATH" 'if length == 1 then .[0][:-1] else .[0] end | if . == $path then input_line_number - ( $obj | gsub( "[^\n]"; "" ) | length ) else empty end' "$2")
if [[ -z "$LB" ]]; then
[[ -n "$CI" ]] && printf '::error file=%s::' "$2"
error "Did not find path \`$3\` in $2."
FAIL=1
fi
if [[ -n "$FAIL" ]]; then
EXIT=1
return
fi

if [[ "$A" != "$B" ]]; then
printf '\n'
local MSG="JSON values at \`$3\` in $1 and $2 must be identical."
if [[ -n "$CI" ]]; then
printf "::error file=%s,line=%d::%s\\n" "$1" "${LA}" "$MSG"
printf "::error file=%s,line=%d::%s\\n" "$2" "${LB}" "$MSG"
else
error "$MSG"
fi
diff -u /dev/fd/3 --label "$1" /dev/fd/4 --label "$2" 3<<<"$A" 4<<<"$B" || true
EXIT=1
fi
}

compare readme.md projects/plugins/jetpack/readme.md '^## Security' '^<!-- end sync section -->$'
compare LICENSE.txt projects/plugins/jetpack/LICENSE.txt
compare SECURITY.md projects/plugins/jetpack/SECURITY.md

for f in $(git ls-files '**/package.json'); do
compareJSON package.json "$f" '.engines'
done

exit $EXIT
4 changes: 4 additions & 0 deletions tools/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
"chai": "4.3.4",
"mocha": "8.2.1",
"yargs-parser": "20.2.4"
},
"engines": {
"node": "^14.16.0",
"yarn": "^1.3.2"
}
}