• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2set -e
3# Shell script to update c-ares 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/c-ares/c-ares/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('cares-', '').replaceAll('_', '.'));
19EOF
20)"
21
22CURRENT_VERSION=$(grep "#define ARES_VERSION_STR" ./deps/cares/include/ares_version.h |  sed -n "s/^.*VERSION_STR \"\(.*\)\"/\1/p")
23
24echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
25
26if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
27  echo "Skipped because c-ares 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
43ARES_REF="cares-$(echo "$NEW_VERSION" | tr . _)"
44ARES_TARBALL="c-ares-$NEW_VERSION.tar.gz"
45
46cd "$WORKSPACE"
47
48echo "Fetching c-ares source archive"
49curl -sL -o "$ARES_TARBALL" "https://github.com/c-ares/c-ares/releases/download/$ARES_REF/$ARES_TARBALL"
50log_and_verify_sha256sum "c-ares" "$ARES_TARBALL"
51gzip -dc "$ARES_TARBALL" | tar xf -
52rm "$ARES_TARBALL"
53mv "c-ares-$NEW_VERSION" cares
54
55echo "Removing tests"
56rm -rf "$WORKSPACE/cares/test"
57
58echo "Copying existing .gitignore, config and gyp files"
59cp -R "$DEPS_DIR/cares/config" "$WORKSPACE/cares"
60cp "$DEPS_DIR/cares/.gitignore" "$WORKSPACE/cares"
61cp "$DEPS_DIR/cares/cares.gyp" "$WORKSPACE/cares"
62
63echo "Replacing existing c-ares"
64rm -rf "$DEPS_DIR/cares"
65mv "$WORKSPACE/cares" "$DEPS_DIR/"
66
67echo "All done!"
68echo ""
69echo "Please git add c-ares, commit the new version:"
70echo ""
71echo "$ git add -A deps/cares"
72echo "$ git commit -m \"deps: update c-ares to $NEW_VERSION\""
73echo ""
74
75# The last line of the script should always print the new version,
76# as we need to add it to $GITHUB_ENV variable.
77echo "NEW_VERSION=$NEW_VERSION"
78