From 26c39e5f346c647da9b7dfca628aa451c7785764 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 2 Mar 2023 20:18:39 +0100 Subject: [PATCH 1/5] Improve build scripts - Make scripts work from any directory - Detect sed version just like Makefile does --- build/test-env-check.sh | 6 +----- build/test-env-prepare.sh | 5 +---- build/update-locales.sh | 20 ++++++++------------ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/build/test-env-check.sh b/build/test-env-check.sh index 38e5a28823114..44f444206c23a 100755 --- a/build/test-env-check.sh +++ b/build/test-env-check.sh @@ -2,11 +2,7 @@ set -e -if [ ! -f ./build/test-env-check.sh ]; then - echo "${0} can only be executed in gitea source root directory" - exit 1 -fi - +cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. # cd into parent folder echo "check uid ..." diff --git a/build/test-env-prepare.sh b/build/test-env-prepare.sh index 0c5bc25f116f1..29e130d0a1931 100755 --- a/build/test-env-prepare.sh +++ b/build/test-env-prepare.sh @@ -2,10 +2,7 @@ set -e -if [ ! -f ./build/test-env-prepare.sh ]; then - echo "${0} can only be executed in gitea source root directory" - exit 1 -fi +cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. # cd into parent folder echo "change the owner of files to gitea ..." chown -R gitea:gitea . diff --git a/build/update-locales.sh b/build/update-locales.sh index b7611c0c9a747..97d871f604590 100755 --- a/build/update-locales.sh +++ b/build/update-locales.sh @@ -2,16 +2,12 @@ set -e -SED=sed +cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. # cd into parent folder -if [[ $OSTYPE == 'darwin'* ]]; then - # for macOS developers, use "brew install gnu-sed" - SED=gsed -fi - -if [ ! -f ./options/locale/locale_en-US.ini ]; then - echo "please run this script in the root directory of the project" - exit 1 +if sed --version 2>/dev/null | grep -q GNU; then + SED_INPLACE="sed -i" +else + SED_INPLACE="sed -i ''" fi mv ./options/locale/locale_en-US.ini ./options/ @@ -32,7 +28,7 @@ mv ./options/locale/locale_en-US.ini ./options/ # * remove the trailing quote # * unescape the quotes # * eg: key="...\"..." => key=..."... -$SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { +$SED_INPLACE -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { s/^([-.A-Za-z0-9_]+)[ ]*=[ ]*"/\1=/ s/"$// s/\\"/"/g @@ -41,8 +37,8 @@ $SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { # * if the escaped line is incomplete like `key="...` or `key=..."`, quote it with backticks # * eg: key="... => key=`"...` # * eg: key=..." => key=`..."` -$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini -$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini +$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini +$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini # Remove translation under 25% of en_us baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1) From ea3f793fc284fa9da34ba0efe9bd52b1416d99be Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 2 Mar 2023 20:28:34 +0100 Subject: [PATCH 2/5] allow non-zero sed exit --- build/update-locales.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/update-locales.sh b/build/update-locales.sh index 97d871f604590..e472c2b51b552 100755 --- a/build/update-locales.sh +++ b/build/update-locales.sh @@ -4,11 +4,13 @@ set -e cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. # cd into parent folder +set +e if sed --version 2>/dev/null | grep -q GNU; then SED_INPLACE="sed -i" else SED_INPLACE="sed -i ''" fi +set -e mv ./options/locale/locale_en-US.ini ./options/ From 05221190599dba510323e82ffd0f89474309e34f Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 2 Mar 2023 21:17:06 +0100 Subject: [PATCH 3/5] back out of cd changes --- build/test-env-check.sh | 6 +++++- build/test-env-prepare.sh | 5 ++++- build/update-locales.sh | 10 ++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/build/test-env-check.sh b/build/test-env-check.sh index 44f444206c23a..38e5a28823114 100755 --- a/build/test-env-check.sh +++ b/build/test-env-check.sh @@ -2,7 +2,11 @@ set -e -cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. # cd into parent folder +if [ ! -f ./build/test-env-check.sh ]; then + echo "${0} can only be executed in gitea source root directory" + exit 1 +fi + echo "check uid ..." diff --git a/build/test-env-prepare.sh b/build/test-env-prepare.sh index 29e130d0a1931..0c5bc25f116f1 100755 --- a/build/test-env-prepare.sh +++ b/build/test-env-prepare.sh @@ -2,7 +2,10 @@ set -e -cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. # cd into parent folder +if [ ! -f ./build/test-env-prepare.sh ]; then + echo "${0} can only be executed in gitea source root directory" + exit 1 +fi echo "change the owner of files to gitea ..." chown -R gitea:gitea . diff --git a/build/update-locales.sh b/build/update-locales.sh index e472c2b51b552..93568c620305f 100755 --- a/build/update-locales.sh +++ b/build/update-locales.sh @@ -1,17 +1,19 @@ #!/bin/bash -set -e - -cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. # cd into parent folder - set +e if sed --version 2>/dev/null | grep -q GNU; then SED_INPLACE="sed -i" else SED_INPLACE="sed -i ''" fi + set -e +if [ ! -f ./options/locale/locale_en-US.ini ]; then + echo "please run this script in the root directory of the project" + exit 1 +fi + mv ./options/locale/locale_en-US.ini ./options/ # the "ini" library for locale has many quirks From 84b27297e0d22fae2b998dc78ea03d62213e6c99 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 2 Mar 2023 21:20:58 +0100 Subject: [PATCH 4/5] remove newline --- build/update-locales.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/build/update-locales.sh b/build/update-locales.sh index 93568c620305f..3cd4b0b968ff4 100755 --- a/build/update-locales.sh +++ b/build/update-locales.sh @@ -6,7 +6,6 @@ if sed --version 2>/dev/null | grep -q GNU; then else SED_INPLACE="sed -i ''" fi - set -e if [ ! -f ./options/locale/locale_en-US.ini ]; then From 3218c0822fb1a9fba9f403dde77456e9cdffd37f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 3 Mar 2023 21:45:05 +0800 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: wxiaoguang --- build/update-locales.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/update-locales.sh b/build/update-locales.sh index 3cd4b0b968ff4..596ddfec032b2 100755 --- a/build/update-locales.sh +++ b/build/update-locales.sh @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh + +# this script runs in alpine image which only has `sh` shell set +e if sed --version 2>/dev/null | grep -q GNU; then