Skip to content

Commit

Permalink
ci: trim variable and ignore empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
evan361425 committed Jul 12, 2024
1 parent 2e710ef commit d052e63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Push to GitHub
run: |
file='android/fastlane/metadata/android/%s/changelogs/${{ needs.check-version.outputs.build_code }}.txt'
printf "$file" "en-US"
printf "Source file: $file\n" "en-US"
printf '%s\n' "$(cat <<EOF
${{ needs.get-release.outputs.changelog }}
Expand Down
20 changes: 20 additions & 0 deletions android/fastlane/translate-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ set -eo pipefail
# Supported languages:
# - zh-TW Traditional Chinese

#######################################
# Trim leading and trailing whitespace
# Usage:
# trim_string " example string "
# Arguments:
# $1: The string to trim
# Outputs:
# The trimmed string
#######################################
function trim_string() {
: "${1#"${1%%[![:space:]]*}"}"
: "${_%"${_##*[![:space:]]}"}"
printf '%s' "$_"
}

function main() {
local changelogFile="$1" googleApiKey="$2" languages="
zh-TW Traditional Chinese
Expand All @@ -25,6 +40,11 @@ zh-TW Traditional Chinese
changelog="$(cat "$(printf "$changelogFile" 'en-US')")"

while IFS= read -r lang; do
lang="$(trim_string "$lang")"
if [ -z "$lang" ]; then
continue
fi

local langCode langName prompt changelog
langCode="$(echo "$lang" | cut -d' ' -f1)"
langName="$(echo "$lang" | cut -d' ' -f2-)"
Expand Down
2 changes: 1 addition & 1 deletion android/fastlane/translate-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Translate the following product changelog from English to %s.
Ensuring that each bullet point maintains the same prefix.
You should not give me any other information or anything prefix.
Thank you very much.
Thank you.

0 comments on commit d052e63

Please sign in to comment.