Skip to content

Commit 2e7ba31

Browse files
marco-ippolitotargos
authored andcommitted
tools: automate cares update
PR-URL: #46993 Refs: nodejs/security-wg#828 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent cbdaaf6 commit 2e7ba31

File tree

4 files changed

+83
-68
lines changed

4 files changed

+83
-68
lines changed

.github/workflows/tools.yml

+8
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ jobs:
163163
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
164164
./tools/update-llhttp.sh "$NEW_VERSION"
165165
fi
166+
- id: c-ares
167+
subsystem: deps
168+
label: dependencies
169+
run: |
170+
./tools/dep_updaters/update-c-ares.sh > temp-output
171+
cat temp-output
172+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
173+
rm temp-output
166174
steps:
167175
- uses: actions/checkout@v3
168176
with:

doc/contributing/maintaining-c-ares.md

+4-12
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,11 @@ Updates to the c-ares dependency involve the following steps:
1313

1414
## Running the update script
1515

16-
The `tools/update-cares.sh` script automates the update of the c-ares source
17-
files, preserving the existing files added by Node.js.
16+
The `tools/dep_updaters/update-c-ares.sh` script automates the update of
17+
the c-ares source files, preserving the existing files added by Node.js.
1818

19-
In the following examples, `x.y.z` should match the c-ares version to update to.
20-
21-
```console
22-
./tools/update-cares.sh x.y.z
23-
```
24-
25-
e.g.
26-
27-
```console
28-
./tools/update-cares.sh 1.18.1
19+
```bash
20+
./tools/dep_updaters/update-c-ares.sh
2921
```
3022

3123
## Check that Node.js still builds and tests

tools/dep_updaters/update-c-ares.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update c-ares in the source tree to a 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+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
12+
const res = await fetch('https://api.github.com/repos/c-ares/c-ares/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('cares-', '').replaceAll('_', '.'));
16+
EOF
17+
)"
18+
19+
CURRENT_VERSION=$(grep "#define ARES_VERSION_STR" ./deps/cares/include/ares_version.h | sed -n "s/^.*VERSION_STR \"\(.*\)\"/\1/p")
20+
21+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
22+
23+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
24+
echo "Skipped because c-ares is on the latest version."
25+
exit 0
26+
fi
27+
28+
echo "Making temporary workspace"
29+
30+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
31+
32+
cleanup () {
33+
EXIT_CODE=$?
34+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
35+
exit $EXIT_CODE
36+
}
37+
38+
trap cleanup INT TERM EXIT
39+
40+
ARES_REF="cares-$(echo "$NEW_VERSION" | tr . _)"
41+
ARES_TARBALL="c-ares-$NEW_VERSION.tar.gz"
42+
43+
cd "$WORKSPACE"
44+
45+
echo "Fetching c-ares source archive"
46+
curl -sL "https://github.com/c-ares/c-ares/releases/download/$ARES_REF/$ARES_TARBALL" | tar xz
47+
mv "c-ares-$NEW_VERSION" cares
48+
49+
echo "Removing tests"
50+
rm -rf "$WORKSPACE/cares/test"
51+
52+
echo "Copying existing .gitignore, config and gyp files"
53+
cp -R "$DEPS_DIR/cares/config" "$WORKSPACE/cares"
54+
cp "$DEPS_DIR/cares/.gitignore" "$WORKSPACE/cares"
55+
cp "$DEPS_DIR/cares/cares.gyp" "$WORKSPACE/cares"
56+
57+
echo "Replacing existing c-ares"
58+
rm -rf "$DEPS_DIR/cares"
59+
mv "$WORKSPACE/cares" "$DEPS_DIR/"
60+
61+
echo "All done!"
62+
echo ""
63+
echo "Please git add c-ares, commit the new version:"
64+
echo ""
65+
echo "$ git add -A deps/cares"
66+
echo "$ git commit -m \"deps: update c-ares to $NEW_VERSION\""
67+
echo ""
68+
69+
# The last line of the script should always print the new version,
70+
# as we need to add it to $GITHUB_ENV variable.
71+
echo "NEW_VERSION=$NEW_VERSION"

tools/update-cares.sh

-56
This file was deleted.

0 commit comments

Comments
 (0)