mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-10 20:59:03 -04:00

Former-commit-id: dc8564b2a7c4ee871bb8068ee9f94c473de8b661 Former-commit-id: b92f9d600ea47496f0e0f113b4f0fa2747a018d6 [formerly f928121de7112edda765c233832e0ba347034a45 [formerly d08fa63e326f0c9452f0175233d75ffc95150d14]] Former-commit-id: d36e8623ce45c3fcdc1eabea3752bc45c606f580 [formerly 68d5bbf6da23a166ccbd71b862061cd5211ab666] Former-commit-id: faf6cd5861ad5aa84598f5c3cb4fb20816ba88fe
52 lines
2.3 KiB
Bash
52 lines
2.3 KiB
Bash
#!/bin/bash
|
|
|
|
# [Script run by build-electron workflow]
|
|
# Replaces the version numbers in init.js, service-worker.js and package.json with the following priority:
|
|
#
|
|
# 1. use the override value set in the workflow dispatch;
|
|
# 2. use the tag pattern (if there is a tag and no override value was set)
|
|
#
|
|
# This script can be tested manually by replacing ${INPUT_VERSION} and ${TAG_VERSION}
|
|
# with test strings
|
|
|
|
# Use the override value by preference
|
|
VERSION=${INPUT_VERSION}
|
|
if [[ ${INPUT_TARGET} = "nightly" ]]; then
|
|
echo "User manually requested a nightly build..."
|
|
CRON_LAUNCHED="1"
|
|
fi
|
|
if [[ "rr$VERSION" = "rr" ]]; then
|
|
# There was no version, so get version from init.js
|
|
VERSION="$(grep 'params\[.appVersion' www/js/init.js | sed -E "s/[^[:digit:]]+([^\"']+).*/\1/")"
|
|
fi
|
|
# If the script was launched by Cron, then version needs commit SHA
|
|
if [[ "qq${CRON_LAUNCHED}" != "qq" ]]; then
|
|
echo "This script was launched by the GitHub Cron job"
|
|
COMMIT_ID=$(git rev-parse --short HEAD)
|
|
VERSION="v$VERSION-$COMMIT_ID"
|
|
fi
|
|
if [[ $VERSION =~ ^v?[0-9.]+ ]]; then
|
|
VERSION=$(sed 's/^v//' <<<"$VERSION") # Remove any leading v
|
|
echo "Using the valid override input and setting version to $VERSION"
|
|
else
|
|
# If no valid override input was entered, then try to use the release tag
|
|
VERSION=${TAG_VERSION}
|
|
if [[ $VERSION =~ ^v?[0-9.]+ ]]; then
|
|
VERSION=$(sed 's/^v//' <<<"$VERSION")
|
|
echo "Using the release tag and setting version to $VERSION"
|
|
else
|
|
echo "No valid override or tag was provided. File version numbers were unchanged."
|
|
echo "To rewrite version numbers in app, ensure the tag matches ^v?[0-9.]+"
|
|
fi
|
|
fi
|
|
# If Version matches a release pattern, then set the appVersion in the files to be published
|
|
if [[ $VERSION =~ ^[0-9.]+ ]]; then
|
|
echo "Rewriting appVersion in service-worker.js and init.js to $VERSION ..."
|
|
sed -i -E "s/appVersion\s*=\s*[^;]+/appVersion = '$VERSION'/" ./service-worker.js
|
|
sed -i -E "s/params..appVersion[^=]+?=\s*[^;]+/params['appVersion'] = '$VERSION'/" ./www/js/init.js
|
|
CUSTOM_VERSION=$(sed -E 's/-(WikiMed|Wikivoyage)//' <<<"$VERSION")
|
|
CUSTOM_VERSION=$(sed -E 's/^([^-]+)(-[0-9a-z]{7})?.*/\1\2-E/' <<<"$VERSION")
|
|
echo "Rewriting version in package.json to $CUSTOM_VERSION"
|
|
sed -i -E 's/"version":\s*"[^"]+"/"version": "'$CUSTOM_VERSION'"/' ./package.json
|
|
fi
|