|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | +# Shell script to update icu-small in the source tree to a specific version |
| 4 | + |
| 5 | +BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) |
| 6 | +DEPS_DIR="$BASE_DIR/deps" |
| 7 | +TOOLS_DIR="$BASE_DIR/tools" |
| 8 | + |
| 9 | +[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" |
| 10 | +[ -x "$NODE" ] || NODE=$(command -v node) |
| 11 | + |
| 12 | +NEW_VERSION="$("$NODE" --input-type=module <<'EOF' |
| 13 | +const res = await fetch('https://api.github.com/repos/unicode-org/icu/releases/latest'); |
| 14 | +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); |
| 15 | +const { tag_name } = await res.json(); |
| 16 | +console.log(tag_name.replace('release-', '')); |
| 17 | +EOF |
| 18 | +)" |
| 19 | + |
| 20 | +ICU_VERSION_H="$DEPS_DIR/icu-small/source/common/unicode/uvernum.h" |
| 21 | +CURRENT_MAJOR_VERSION=$(grep "#define U_ICU_VERSION_MAJOR_NUM" "$ICU_VERSION_H" | cut -d ' ' -f3 | tr -d '\r') |
| 22 | +CURRENT_MINOR_VERSION=$(grep "#define U_ICU_VERSION_MINOR_NUM" "$ICU_VERSION_H" | cut -d ' ' -f3 | tr -d '\r') |
| 23 | + |
| 24 | +CURRENT_VERSION="$CURRENT_MAJOR_VERSION-$CURRENT_MINOR_VERSION" |
| 25 | + |
| 26 | +echo "Comparing $NEW_VERSION with $CURRENT_VERSION" |
| 27 | + |
| 28 | +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then |
| 29 | + echo "Skipped because icu-small is on the latest version." |
| 30 | + exit 0 |
| 31 | +fi |
| 32 | + |
| 33 | +NEW_MAJOR_VERSION=$(echo "$NEW_VERSION" | cut -d '-' -f1) |
| 34 | +NEW_MINOR_VERSION=$(echo "$NEW_VERSION" | cut -d '-' -f2) |
| 35 | + |
| 36 | +NEW_VERSION_TGZ="https://github.com/unicode-org/icu/releases/download/release-$NEW_VERSION/icu4c-$NEW_MAJOR_VERSION"_"$NEW_MINOR_VERSION-src.tgz" |
| 37 | + |
| 38 | +./configure --with-intl=full-icu --with-icu-source="$NEW_VERSION_TGZ" |
| 39 | + |
| 40 | +"tools/icu/shrink-icu-src.py" |
| 41 | + |
| 42 | +rm -rf "$DEPS_DIR/icu" |
| 43 | + |
| 44 | +CHECKSUM=$(curl -s "$NEW_VERSION_TGZ" | md5sum | cut -d ' ' -f1) |
| 45 | + |
| 46 | +sed -i '' -e "s|\"url\": \"\(.*\)\".*|\"url\": \"$NEW_VERSION_TGZ\",|" "$TOOLS_DIR/icu/current_ver.dep" |
| 47 | + |
| 48 | +sed -i '' -e "s|\"md5\": \"\(.*\)\".*|\"md5\": \"$CHECKSUM\"|" "$TOOLS_DIR/icu/current_ver.dep" |
| 49 | + |
| 50 | +rm -rf out "$DEPS_DIR/icu" "$DEPS_DIR/icu4c*" |
| 51 | + |
| 52 | +echo "All done!" |
| 53 | +echo "" |
| 54 | +echo "Please git add icu-small, commit the new version:" |
| 55 | +echo "" |
| 56 | +echo "$ git add -A deps/icu-small" |
| 57 | +echo "$ git add tools/icu/current_ver.dep" |
| 58 | +echo "$ git commit -m \"deps: update icu-small to $NEW_VERSION\"" |
| 59 | +echo "" |
| 60 | + |
| 61 | +# The last line of the script should always print the new version, |
| 62 | +# as we need to add it to $GITHUB_ENV variable. |
| 63 | +echo "NEW_VERSION=$NEW_VERSION" |
0 commit comments