Skip to content

Commit f6ff318

Browse files
marco-ippolitotargos
authored andcommittedMay 12, 2023
tools: automate icu-small update
PR-URL: #47727 Refs: nodejs/security-wg#828 Reviewed-By: Steven R Loomis <srl295@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 7ed99e8 commit f6ff318

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
 

‎.github/workflows/tools.yml

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ on:
2424
- doc
2525
- eslint
2626
- googletest
27+
- icu
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
260+
subsystem: deps
261+
label: dependencies, test
262+
run: |
263+
./tools/dep_updaters/update-icu.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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
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' && (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:

‎doc/contributing/maintaining/maintaining-icu.md

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ Node.js is built.
101101
102102
## How to upgrade ICU
103103
104+
> The script `tools/dep_updaters/update-icu.sh` automates
105+
> this process.
106+
104107
* Make sure your Node.js workspace is clean (`git status`
105108
should be sufficient).
106109
* Configure Node.js with the specific [ICU version](http://site.icu-project.org/download)

‎tools/dep_updaters/update-icu.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update icu 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-', '').replace('-','.'));
17+
EOF
18+
)"
19+
20+
ICU_VERSION_H="$DEPS_DIR/icu-small/source/common/unicode/uvernum.h"
21+
22+
CURRENT_VERSION="$(grep "#define U_ICU_VERSION " "$ICU_VERSION_H" | cut -d'"' -f2)"
23+
24+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
25+
26+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
27+
echo "Skipped because icu is on the latest version."
28+
exit 0
29+
fi
30+
31+
DASHED_NEW_VERSION=$(echo "$NEW_VERSION" | sed 's/\./-/g')
32+
33+
LOW_DASHED_NEW_VERSION=$(echo "$NEW_VERSION" | sed 's/\./_/g')
34+
35+
NEW_VERSION_TGZ="icu4c-${LOW_DASHED_NEW_VERSION}-src.tgz"
36+
37+
NEW_VERSION_TGZ_URL="https://github.com/unicode-org/icu/releases/download/release-${DASHED_NEW_VERSION}/$NEW_VERSION_TGZ"
38+
39+
NEW_VERSION_MD5="https://github.com/unicode-org/icu/releases/download/release-${DASHED_NEW_VERSION}/icu4c-${LOW_DASHED_NEW_VERSION}-src.md5"
40+
41+
./configure --with-intl=full-icu --with-icu-source="$NEW_VERSION_TGZ_URL"
42+
43+
"$TOOLS_DIR/icu/shrink-icu-src.py"
44+
45+
rm -rf "$DEPS_DIR/icu"
46+
47+
CHECKSUM=$(curl -sL "$NEW_VERSION_MD5" | grep "$NEW_VERSION_TGZ" | grep -v "\.asc$" | awk '{print $1}')
48+
49+
GENERATED_CHECKSUM=$( curl -sL "$NEW_VERSION_TGZ_URL" | md5sum | cut -d ' ' -f1)
50+
51+
echo "Comparing checksums: deposited $CHECKSUM with $GENERATED_CHECKSUM"
52+
53+
if [ "$CHECKSUM" != "$GENERATED_CHECKSUM" ]; then
54+
echo "Skipped because checksums do not match."
55+
exit 0
56+
fi
57+
58+
sed -i '' -e "s|\"url\": \"\(.*\)\".*|\"url\": \"$NEW_VERSION_TGZ_URL\",|" "$TOOLS_DIR/icu/current_ver.dep"
59+
60+
sed -i '' -e "s|\"md5\": \"\(.*\)\".*|\"md5\": \"$CHECKSUM\"|" "$TOOLS_DIR/icu/current_ver.dep"
61+
62+
rm -rf out "$DEPS_DIR/icu" "$DEPS_DIR/icu4c*"
63+
64+
echo "All done!"
65+
echo ""
66+
echo "Please git add icu, commit the new version:"
67+
echo ""
68+
echo "$ git add -A deps/icu-small"
69+
echo "$ git add tools/icu/current_ver.dep"
70+
echo "$ git commit -m \"deps: update icu to $NEW_VERSION\""
71+
echo ""
72+
73+
# The last line of the script should always print the new version,
74+
# as we need to add it to $GITHUB_ENV variable.
75+
echo "NEW_VERSION=$NEW_VERSION"

‎tools/icu/shrink-icu-src.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)