-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
misc(i18n): add assertion script #5686
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
## | ||
# @license Copyright 2018 Google Inc. All Rights Reserved. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
## | ||
|
||
pwd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
lhroot_path="$pwd/../../.." | ||
lh_tmp_path="$lhroot_path/.tmp" | ||
mkdir -p "$lh_tmp_path" | ||
|
||
purple='\033[1;35m' | ||
red='\033[1;31m' | ||
green='\033[1;32m' | ||
colorText() { | ||
printf "\\n$2$1%b\\n" '\033[0m' | ||
} | ||
|
||
collectedstringsPath="$lhroot_path/lighthouse-core/lib/locales/en-US.json"; | ||
currentstringsPath="$lh_tmp_path/current_strings.json"; | ||
freshstringsPath="$lh_tmp_path/fresh_strings.json"; | ||
|
||
# always run this before exiting | ||
function teardown { rm -f "$currentstringsPath" "$freshstringsPath"; } | ||
trap teardown EXIT | ||
|
||
cp $collectedstringsPath $currentstringsPath | ||
|
||
colorText "Collecting strings..." "$purple" | ||
set -x | ||
node "$lhroot_path/lighthouse-core/scripts/i18n/collect-strings.js" | ||
set +x | ||
|
||
cp $collectedstringsPath $freshstringsPath | ||
|
||
colorText "Diff'ing golden strings against the fresh strings" "$purple" | ||
git --no-pager diff --color=always --no-index "$currentstringsPath" "$freshstringsPath" | ||
|
||
# Use the return value from last command | ||
retVal=$? | ||
|
||
if [ $retVal -eq 0 ]; then | ||
colorText "✅ PASS. All strings have been collected." "$green" | ||
else | ||
colorText "❌ FAIL. Strings have changed." "$red" | ||
echo "Commit the changes to `lighthouse-core/lib/locales/` update the strings." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in bash, backticks evaluate. ;) so this actually triggers this error: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha, whoops! that'll show me to make aesthetic changes after running :) |
||
fi | ||
exit $retVal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually wanna throw quotes around these paths? shellcheck prefers it like that in case there are spaces in my project path. (hint: there aren't)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya, done