• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2set -e
3# Shell script to update brotli in the source tree to a specific version
4
5BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6DEPS_DIR="$BASE_DIR/deps"
7
8[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
9[ -x "$NODE" ] || NODE=$(command -v node)
10
11# shellcheck disable=SC1091
12. "$BASE_DIR/tools/dep_updaters/utils.sh"
13
14NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
15const res = await fetch('https://api.github.com/repos/google/brotli/releases/latest');
16if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
17const { tag_name } = await res.json();
18console.log(tag_name.replace('v', ''));
19EOF
20)"
21
22VERSION_HEX=$(grep "#define BROTLI_VERSION" ./deps/brotli/c/common/version.h | sed 's/.* //')
23
24major=$(( ($VERSION_HEX >> 24) & 0xff ))
25minor=$(( ($VERSION_HEX >> 12) & 0xfff ))
26patch=$(( $VERSION_HEX & 0xfff ))
27CURRENT_VERSION="${major}.${minor}.${patch}"
28
29echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
30
31if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
32  echo "Skipped because brotli is on the latest version."
33  exit 0
34fi
35
36echo "Making temporary workspace"
37
38WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
39
40cleanup () {
41  EXIT_CODE=$?
42  [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
43  exit $EXIT_CODE
44}
45
46trap cleanup INT TERM EXIT
47
48cd "$WORKSPACE"
49
50BROTLI_TARBALL="brotli-v$NEW_VERSION.tar.gz"
51
52echo "Fetching brotli source archive"
53curl -sL -o "$BROTLI_TARBALL" "https://github.com/google/brotli/archive/v$NEW_VERSION.tar.gz"
54log_and_verify_sha256sum "brotli" "$BROTLI_TARBALL"
55gzip -dc "$BROTLI_TARBALL" | tar xf -
56rm "$BROTLI_TARBALL"
57mv "brotli-$NEW_VERSION" "brotli"
58
59echo "Copying existing gyp file"
60cp "$DEPS_DIR/brotli/brotli.gyp" "$WORKSPACE/brotli"
61
62echo "Deleting existing brotli"
63rm -rf "$DEPS_DIR/brotli"
64mkdir "$DEPS_DIR/brotli"
65
66echo "Update c and LICENSE"
67mv "$WORKSPACE/brotli/c" "$WORKSPACE/brotli/LICENSE" "$WORKSPACE/brotli/brotli.gyp" "$DEPS_DIR/brotli"
68
69echo "All done!"
70echo ""
71echo "Please git add brotli, commit the new version:"
72echo ""
73echo "$ git add -A deps/brotli"
74echo "$ git commit -m \"deps: update brotli to $NEW_VERSION\""
75echo ""
76
77# The last line of the script should always print the new version,
78# as we need to add it to $GITHUB_ENV variable.
79echo "NEW_VERSION=$NEW_VERSION"
80