|
| 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" |
0 commit comments