Skip to content

Commit

Permalink
release: check code from either file. build.gradle or build.gradle.kts
Browse files Browse the repository at this point in the history
[release build]
  • Loading branch information
FireLord committed Jan 14, 2024
1 parent d0e85e9 commit 1f02fb8
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions release/deploy-telegram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,41 @@ function send_to_tg() {
curl -F chat_id="${CHAT_ID}" -F document="@${FILE}" -F caption="${CAPTION}" -F parse_mode="Markdown" "https://api.telegram.org/bot${TG_TOKEN:?}/sendDocument" >/dev/null 2>&1
}

# Extract versionCode and versionName from build.gradle
versionCode=$(grep "versionCode" app/build.gradle | awk '{print $2}' | tr -d '\r')
versionName=$(grep "versionName" app/build.gradle | awk -F'"' '{print $2}' | tr -d '\r')
# Function to extract version information from build.gradle or build.gradle.kts
function extract_version_info() {
local FILE="${1}"

# Check if the file exists
if [ ! -f "${FILE}" ]; then
echo "File not found: ${FILE}"
return 1 # File not found
fi

# Extract versionCode and versionName using awk
VERSION_CODE=$(awk -F'[= \t]+' '/versionCode/ {print $NF}' "${FILE}" | tr -d '\r')
VERSION_NAME=$(awk -F'"' '/versionName/ {print $2}' "${FILE}" | tr -d '\r')

# If the above extraction fails for versionCode, try another approach
if [ -z "${VERSION_CODE}" ]; then
VERSION_CODE=$(awk -F= '/versionCode/ {gsub(/[ \t]+/, "", $2); print $2}' "${FILE}" | tr -d '\r' | tr -d '\n' | tr -d ' ')
fi

# Print version information
echo "Version Code: ${VERSION_CODE}"
echo "Version Name: ${VERSION_NAME}"

return 0 # Success
}

# Extract version information from either build.gradle or build.gradle.kts
if extract_version_info "app/build.gradle"; then
:
elif extract_version_info "app/build.gradle.kts"; then
:
else
echo "Neither build.gradle nor build.gradle.kts found."
exit 1
fi

# Set the source and destination paths
source_file="${TG_FILE:?}"
Expand All @@ -22,4 +54,4 @@ destination_path="app/build/outputs/apk/release/Weathering${versionCode}(${versi
mv "${source_file}" "${destination_path}"

# Send to Telegram
send_to_tg "${destination_path}" "${TG_TO:?}" "weathering-alpha-${GITHUB_RUN_NUMBER}-release"
send_to_tg "${destination_path}" "${TG_TO:?}" "weathering-alpha-${versionName}-release"

0 comments on commit 1f02fb8

Please sign in to comment.