Skip to content

Commit 7261c4a

Browse files
tools: automate icu-small update
1 parent 2ac5e98 commit 7261c4a

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.github/workflows/tools.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ on:
2424
- doc
2525
- eslint
2626
- googletest
27+
- icu-small
2728
- libuv
2829
- lint-md-dependencies
2930
- llhttp
@@ -36,6 +37,9 @@ on:
3637
- undici
3738
- uvwasi
3839

40+
env:
41+
PYTHON_VERSION: '3.11'
42+
3943
permissions:
4044
contents: read
4145

@@ -252,11 +256,24 @@ jobs:
252256
cat temp-output
253257
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
254258
rm temp-output
259+
- id: icu-small
260+
subsystem: deps
261+
label: dependencies, test
262+
run: |
263+
./tools/dep_updaters/update-icu-small.sh > temp-output
264+
cat temp-output
265+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
266+
rm temp-output
255267
steps:
256268
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
257269
if: github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
258270
with:
259271
persist-credentials: false
272+
- name: Set up Python ${{ env.PYTHON_VERSION }}
273+
if: matrix.id == 'icu-small' && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id)
274+
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
275+
with:
276+
python-version: ${{ env.PYTHON_VERSION }}
260277
- run: ${{ matrix.run }}
261278
if: github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
262279
env:
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)