• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2set -e
3# Shell script to update histogram in the source tree to 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/HdrHistogram/HdrHistogram_c/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
22CURRENT_VERSION=$(grep "#define HDR_HISTOGRAM_VERSION" ./deps/histogram/include/hdr/hdr_histogram_version.h | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
23
24echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
25
26if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
27  echo "Skipped because histogram is on the latest version."
28  exit 0
29fi
30
31echo "Making temporary workspace"
32
33WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
34
35cleanup () {
36  EXIT_CODE=$?
37  [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
38  exit $EXIT_CODE
39}
40
41trap cleanup INT TERM EXIT
42
43HISTOGRAM_TARBALL="$NEW_VERSION.tar.gz"
44
45cd "$WORKSPACE"
46
47echo "Fetching histogram source archive"
48
49curl -sL -o "$HISTOGRAM_TARBALL" "https://github.com/HdrHistogram/HdrHistogram_c/archive/refs/tags/$HISTOGRAM_TARBALL"
50
51log_and_verify_sha256sum "histogram" "$HISTOGRAM_TARBALL"
52
53gzip -dc "$HISTOGRAM_TARBALL" | tar xf -
54
55rm "$HISTOGRAM_TARBALL"
56
57mv "HdrHistogram_c-$NEW_VERSION" histogram
58
59cp "$WORKSPACE/histogram/include/hdr/hdr_histogram_version.h" "$WORKSPACE/histogram/include/hdr/hdr_histogram.h" "$DEPS_DIR/histogram/include/hdr"
60
61cp "$WORKSPACE/histogram/src/hdr_atomic.h" "$WORKSPACE/histogram/src/hdr_malloc.h" "$WORKSPACE/histogram/src/hdr_tests.h" "$WORKSPACE/histogram/src/hdr_histogram.c" "$DEPS_DIR/histogram/src"
62
63
64echo "All done!"
65echo ""
66echo "Please git add histogram, commit the new version:"
67echo ""
68echo "$ git add -A deps/histogram"
69echo "$ git commit -m \"deps: update histogram to $NEW_VERSION\""
70echo ""
71
72# The last line of the script should always print the new version,
73# as we need to add it to $GITHUB_ENV variable.
74echo "NEW_VERSION=$NEW_VERSION"
75