Skip to content

Commit 715cf81

Browse files
marco-ippolitoMoLow
authored andcommitted
tools: automate histogram update
PR-URL: #48171 Refs: nodejs/security-wg#828 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0e3312b commit 715cf81

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

.github/workflows/tools.yml

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ on:
2424
- doc
2525
- eslint
2626
- googletest
27+
- histogram
2728
- icu
2829
- libuv
2930
- lint-md-dependencies
@@ -163,6 +164,14 @@ jobs:
163164
cat temp-output
164165
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
165166
rm temp-output
167+
- id: histogram
168+
subsystem: deps
169+
label: dependencies
170+
run: |
171+
./tools/dep_updaters/update-histogram.sh > temp-output
172+
cat temp-output
173+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
174+
rm temp-output
166175
- id: llhttp
167176
subsystem: deps
168177
label: dependencies
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update histogram in the source tree to specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_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+
14+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
15+
const res = await fetch('https://api.github.com/repos/HdrHistogram/HdrHistogram_c/releases/latest');
16+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
17+
const { tag_name } = await res.json();
18+
console.log(tag_name.replace('v', ''));
19+
EOF
20+
)"
21+
22+
CURRENT_VERSION=$(grep "#define HDR_HISTOGRAM_VERSION" ./deps/histogram/include/hdr/hdr_histogram_version.h | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
23+
24+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
25+
26+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
27+
echo "Skipped because histogram is on the latest version."
28+
exit 0
29+
fi
30+
31+
echo "Making temporary workspace"
32+
33+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
34+
35+
cleanup () {
36+
EXIT_CODE=$?
37+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
38+
exit $EXIT_CODE
39+
}
40+
41+
trap cleanup INT TERM EXIT
42+
43+
HISTOGRAM_TARBALL="$NEW_VERSION.tar.gz"
44+
45+
cd "$WORKSPACE"
46+
47+
echo "Fetching histogram source archive"
48+
49+
curl -sL -o "$HISTOGRAM_TARBALL" "https://github.com/HdrHistogram/HdrHistogram_c/archive/refs/tags/$HISTOGRAM_TARBALL"
50+
51+
log_and_verify_sha256sum "histogram" "$HISTOGRAM_TARBALL"
52+
53+
gzip -dc "$HISTOGRAM_TARBALL" | tar xf -
54+
55+
rm "$HISTOGRAM_TARBALL"
56+
57+
mv "HdrHistogram_c-$NEW_VERSION" histogram
58+
59+
cp "$WORKSPACE/histogram/include/hdr/hdr_histogram_version.h" "$WORKSPACE/histogram/include/hdr/hdr_histogram.h" "$DEPS_DIR/histogram/include/hdr"
60+
61+
cp "$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+
64+
echo "All done!"
65+
echo ""
66+
echo "Please git add histogram, commit the new version:"
67+
echo ""
68+
echo "$ git add -A deps/histogram"
69+
echo "$ git commit -m \"deps: update histogram to $NEW_VERSION\""
70+
echo ""
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.
74+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)