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

scripts/deploy.sh: add handmade linter for translation-related json files to check for tabs and odd spaces #2064

Merged
merged 10 commits into from
Feb 1, 2025
Merged
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:

steps:
- name: Install dependencies (apk)
run: apk add --no-cache git
run: apk add --no-cache git bash grep

- uses: actions/checkout@v4
with:
Expand All @@ -227,4 +227,4 @@ jobs:
run: git config --global --add safe.directory /__w/IronOS/IronOS && git config --global safe.directory "$GITHUB_WORKSPACE"

- name: Check and verify documentation
run: /bin/sh ./scripts/deploy.sh docs
run: ./scripts/deploy.sh docs
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ test-md:
@echo ""
@echo "---- Checking documentation... ----"
@echo ""
@/bin/sh ./scripts/deploy.sh docs
@./scripts/deploy.sh docs

# shell style & linter check (github CI version of shellcheck is more recent than alpine one so the latter may not catch some policies)
test-sh:
Expand Down
2 changes: 1 addition & 1 deletion Translations/translation_UZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"menuOptions": {
"DCInCutoff": {
"displayText": "Quvvat\nmanbai",
"description": "Batareya haddan tashqari zaryadsizlanishini oldini olish uchun kuchlanish chegarasini o'rnatish (DC 10V) (S=3.3V har bir yacheyka uchun, quvvat PWR chegarasini o'chirish)"
"description": "Batareya haddan tashqari zaryadsizlanishini oldini olish uchun kuchlanish chegarasini o'rnatish (DC 10V) (S=3.3V har bir yacheyka uchun, quvvat PWR chegarasini o'chirish)"
},
"MinVolCell": {
"displayText": "Minimal\nkuchlanish",
Expand Down
33 changes: 28 additions & 5 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ docs_links()
{
ver_git="$(git tag -l | sort | grep -e "^v" | grep -v "rc" | tail -1)"
md="README.md"
test -f "${md}" || (echo "deploy.sh: docs_links: ERROR with the project directory structure!" && exit 1)
ver_md="$(grep -c "${ver_git}" "${md}")"
ret=0
if [ "${ver_md}" -ne 0 ]; then
if [ "${ver_md}" -eq 0 ]; then
Copy link
Collaborator Author

@ia ia Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right way, and it was wrong, but it didn't trigger any errors, because at this point local directory was Translations/ (because I forgot to add cd .., which is now on the line 119 120 below).

UPD: also added a couple of checks hopefully to avoid this in the future.

ret=1
echo "Please, update mention & links in ${md} inside Builds section for release builds with version ${ver_git}."
fi;
Expand All @@ -108,16 +109,38 @@ docs_links()
build_langs()
{
mk="../source/Makefile"
cd Translations/ || exit 1
cd Translations/ || (echo "deploy.sh: build_langs: ERROR with the project directory structure!" && exit 1)
langs="$(echo "$(find ./*.json | sed -ne 's,^\./translation_,,; s,\.json$,,; /[A-Z]/p' ; sed -ne 's/^ALL_LANGUAGES=//p;' "${mk}")" | sed 's, ,\n,g; s,\r,,g' | sort | uniq -u)"
ret=0
if [ -n "${langs}" ]; then
ret=1
echo "It seems there is mismatch between supported languages and enabled builds."
echo "Please, check files in Translations/ and ALL_LANGUAGES variable in source/Makefile for:"
echo "${langs}"
return 1
fi;
return "${ret}"
cd ..

echo -ne "\n"
grep -nH $'\11' Translations/translation*.json
ret="${?}"
if [ "${ret}" -eq 0 ]; then
echo -ne "\t^^^^\t^^^^\n"
echo "Please, remove any tabs as indention from json file(s) in Translations/ directory (see the exact files & lines in the list above)."
echo "Use spaces only to indent in the future, please."
echo -ne "\n"
return 1
fi;

grep -nEH -e "^( {1}| {3}| {5}| {7}| {9}| {11})[^ ]" Translations/translation*.json
ret="${?}"
if [ "${ret}" -eq 0 ]; then
echo -ne "\t^^^^\t^^^^\n"
echo "Please, remove any odd amount of extra spaces as indention from json file(s) in Translations/ directory (see the exact files & lines in the list above)."
echo "Use even amount of spaces to indent in the future, please (two actual spaces per one indent, not tab)."
echo -ne "\n"
return 1
fi;

return 0
}

# Helper function to check code style using clang-format & grep/sed custom parsers:
Expand Down