77
88set -ex
99
10- cd " $( dirname " $0 " ) /.." || exit
10+ ROOT=$( cd " $( dirname " $0 " ) /../.." && pwd)
11+ [ -z " $NODE " ] && NODE=" $ROOT /out/Release/node"
12+ [ -x " $NODE " ] || NODE=$( command -v node)
13+ NPM=" $ROOT /deps/npm/bin/npm-cli.js"
14+
15+ NEW_VERSION=$( " $NODE " " $NPM " view undici dist-tags.latest)
16+ CURRENT_VERSION=$( " $NODE " -p " require('./deps/undici/src/package.json').version" )
17+
18+ echo " Comparing $NEW_VERSION with $CURRENT_VERSION "
19+
20+ if [ " $NEW_VERSION " = " $CURRENT_VERSION " ]; then
21+ echo " Skipped because Undici is on the latest version."
22+ exit 0
23+ fi
24+
25+ cd " $( dirname " $0 " ) /../.." || exit
1126rm -rf deps/undici/src
1227rm -f deps/undici/undici.js
1328
@@ -16,25 +31,18 @@ rm -f deps/undici/undici.js
1631 mkdir undici-tmp
1732 cd undici-tmp || exit
1833
19- ROOT=" $PWD /.."
20- [ -z " $NODE " ] && NODE=" $ROOT /out/Release/node"
21- [ -x " $NODE " ] || NODE=$( command -v node)
22- NPM=" $ROOT /deps/npm/bin/npm-cli.js"
23-
2434 " $NODE " " $NPM " init --yes
2535
2636 " $NODE " " $NPM " install --global-style --no-bin-links --ignore-scripts undici
2737 cd node_modules/undici
2838 " $NODE " " $NPM " run build:node
29- # get the new version of undici
30- UNDICI_VERSION=$( " $NODE " -p " require('./package.json').version" )
3139 # update this version information in src/undici_version.h
3240 FILE_PATH=" $ROOT /src/undici_version.h"
3341 echo " // This is an auto generated file, please do not edit." > " $FILE_PATH "
3442 echo " // Refer to tools/update-undici.sh" >> " $FILE_PATH "
3543 echo " #ifndef SRC_UNDICI_VERSION_H_" >> " $FILE_PATH "
3644 echo " #define SRC_UNDICI_VERSION_H_" >> " $FILE_PATH "
37- echo " #define UNDICI_VERSION \" $UNDICI_VERSION \" " >> " $FILE_PATH "
45+ echo " #define UNDICI_VERSION \" $NEW_VERSION \" " >> " $FILE_PATH "
3846 echo " #endif // SRC_UNDICI_VERSION_H_" >> " $FILE_PATH "
3947)
4048
@@ -43,3 +51,7 @@ mv deps/undici/src/undici-fetch.js deps/undici/undici.js
4351cp deps/undici/src/LICENSE deps/undici/LICENSE
4452
4553rm -rf undici-tmp/
54+
55+ # The last line of the script should always print the new version,
56+ # as we need to add it to $GITHUB_ENV variable.
57+ echo " NEW_VERSION=$NEW_VERSION "
0 commit comments