Skip to content

Commit 0bde388

Browse files
committed
tools: add ncrypto updater script
1 parent f6464c5 commit 0bde388

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
/lib/tls.js @nodejs/crypto @nodejs/net
6565
/src/crypto/* @nodejs/crypto
6666
/src/node_crypto* @nodejs/crypto
67-
/deps/ncrypto/* @nodejs/crypto
6867

6968
# http
7069

.github/workflows/tools.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030
- llhttp
3131
- minimatch
3232
- nbytes
33+
- ncrypto
3334
- nixpkgs-unstable
3435
- nghttp2
3536
- nghttp3
@@ -191,6 +192,14 @@ jobs:
191192
cat temp-output
192193
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
193194
rm temp-output
195+
- id: ncrypto
196+
subsystem: deps
197+
label: dependencies
198+
run: |
199+
./tools/dep_updaters/update-ncrypto.sh > temp-output
200+
cat temp-output
201+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
202+
rm temp-output
194203
- id: nixpkgs-unstable
195204
subsystem: tools
196205
# dont-land labels are there so we can guarantee released versions of

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,7 @@ LINT_CPP_EXCLUDE += $(LINT_CPP_ADDON_DOC_FILES)
14911491
# These files were copied more or less verbatim from V8.
14921492
LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h
14931493

1494-
# deps/ncrypto is included in this list, as it is maintained in
1495-
# this repository, and should be linted. Eventually it should move
1496-
# to its own repo, at which point we should remove it from this list.
1497-
LINT_CPP_DEPS = deps/ncrypto/*.cc deps/ncrypto/*.h
1494+
LINT_CPP_DEPS =
14981495

14991496
LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
15001497
benchmark/napi/*/*.cc \
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
set -ex
3+
# Shell script to update ncrypto in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
8+
[ -x "$NODE" ] || NODE=$(command -v node)
9+
10+
# shellcheck disable=SC1091
11+
. "$BASE_DIR/tools/dep_updaters/utils.sh"
12+
13+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
14+
const res = await fetch('https://api.github.com/repos/nodejs/ncrypto/releases/latest',
15+
process.env.GITHUB_TOKEN && {
16+
headers: {
17+
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`
18+
},
19+
});
20+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
21+
const { tag_name } = await res.json();
22+
console.log(tag_name.replace('v', ''));
23+
EOF
24+
)"
25+
26+
CURRENT_VERSION=$(awk -F'"' '/^#define NCRYPTO_VERSION /{ print $2 }' "$DEPS_DIR/ncrypto/ncrypto/version.h" || true)
27+
28+
# This function exit with 0 if new version and current version are the same
29+
compare_dependency_version "ncrypto" "$NEW_VERSION" "$CURRENT_VERSION"
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+
echo "Fetching ncrypto source archive..."
44+
NCRYPTO_TARBALL="ncrypto-v$NEW_VERSION.tar.gz"
45+
curl -sL "https://api.github.com/repos/nodejs/ncrypto/tarball/v$NEW_VERSION" \
46+
| tar xz --strip-components=1 -C "$WORKSPACE" --wildcards \
47+
'*/README.md' \
48+
'*/src/engine.cpp' \
49+
'*/src/ncrypto.cpp' \
50+
'*/include/ncrypto.h' \
51+
'*/include/ncrypto/version.h'
52+
53+
mv "$WORKSPACE/README.md" "$DEPS_DIR/ncrypto/."
54+
mv "$WORKSPACE/src/engine.cpp" "$DEPS_DIR/ncrypto/engine.cc"
55+
mv "$WORKSPACE/src/ncrypto.cpp" "$DEPS_DIR/ncrypto/ncrypto.cc"
56+
mv "$WORKSPACE/include/"* "$DEPS_DIR/ncrypto/."
57+
58+
cleanup
59+
60+
# Update the version number on maintaining-dependencies.md
61+
# and print the new version as the last line of the script as we need
62+
# to add it to $GITHUB_ENV variable
63+
finalize_version_update "ncrypto" "$NEW_VERSION"

0 commit comments

Comments
 (0)