2
2
set -e
3
3
# Shell script to update nghttp2 in the source tree to specific version
4
4
5
- BASE_DIR=$( cd " $( dirname " $0 " ) /.." && pwd)
5
+ BASE_DIR=$( cd " $( dirname " $0 " ) /../.. " && pwd)
6
6
DEPS_DIR=" $BASE_DIR /deps"
7
- NGHTTP2_VERSION=$1
8
7
9
- if [ " $# " -le 0 ]; then
10
- echo " Error: please provide an nghttp2 version to update to"
11
- exit 1
8
+ [ -z " $NODE " ] && NODE=" $BASE_DIR /out/Release/node"
9
+ [ -x " $NODE " ] || NODE=$( command -v node)
10
+
11
+ NEW_VERSION=" $( " $NODE " --input-type=module << 'EOF '
12
+ const res = await fetch('https://api.github.com/repos/nghttp2/nghttp2/releases/latest');
13
+ if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
14
+ const { tag_name } = await res.json();
15
+ console.log(tag_name.replace('v', ''));
16
+ EOF
17
+ ) "
18
+
19
+ CURRENT_VERSION=$( grep " #define NGHTTP2_VERSION" ./deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h | sed -n " s/^.*VERSION \" \(.*\)\" /\1/p" )
20
+
21
+ echo " Comparing $NEW_VERSION with $CURRENT_VERSION "
22
+
23
+ if [ " $NEW_VERSION " = " $CURRENT_VERSION " ]; then
24
+ echo " Skipped because nghttp2 is on the latest version."
25
+ exit 0
12
26
fi
13
27
14
28
echo " Making temporary workspace"
@@ -23,16 +37,16 @@ cleanup () {
23
37
24
38
trap cleanup INT TERM EXIT
25
39
26
- NGHTTP2_REF=" v$NGHTTP2_VERSION "
27
- NGHTTP2_TARBALL=" nghttp2-$NGHTTP2_VERSION .tar.gz"
40
+ NGHTTP2_REF=" v$NEW_VERSION "
41
+ NGHTTP2_TARBALL=" nghttp2-$NEW_VERSION .tar.gz"
28
42
29
43
cd " $WORKSPACE "
30
44
31
45
echo " Fetching nghttp2 source archive"
32
46
curl -sL -o " $NGHTTP2_TARBALL " " https://github.com/nghttp2/nghttp2/releases/download/$NGHTTP2_REF /$NGHTTP2_TARBALL "
33
47
gzip -dc " $NGHTTP2_TARBALL " | tar xf -
34
48
rm " $NGHTTP2_TARBALL "
35
- mv " nghttp2-$NGHTTP2_VERSION " nghttp2
49
+ mv " nghttp2-$NEW_VERSION " nghttp2
36
50
37
51
echo " Removing everything, except lib/ and COPYING"
38
52
cd nghttp2
@@ -59,5 +73,9 @@ echo ""
59
73
echo " Please git add nghttp2, commit the new version:"
60
74
echo " "
61
75
echo " $ git add -A deps/nghttp2"
62
- echo " $ git commit -m \" deps: update nghttp2 to $NGHTTP2_VERSION \" "
76
+ echo " $ git commit -m \" deps: update nghttp2 to $NEW_VERSION \" "
63
77
echo " "
78
+
79
+ # The last line of the script should always print the new version,
80
+ # as we need to add it to $GITHUB_ENV variable.
81
+ echo " NEW_VERSION=$NEW_VERSION "
0 commit comments