Skip to content

Commit

Permalink
tools: fix c-ares update script
Browse files Browse the repository at this point in the history
PR-URL: #53414
Fixes: #53407
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
marco-ippolito committed Jul 19, 2024
1 parent 3bd5f46 commit 53a7b6e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tools/dep_updaters/update-c-ares.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ DEPS_DIR="$BASE_DIR/deps"
# shellcheck disable=SC1091
. "$BASE_DIR/tools/dep_updaters/utils.sh"

NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
NEW_VERSION_METADATA="$("$NODE" --input-type=module <<'EOF'
const res = await fetch('https://api.github.com/repos/c-ares/c-ares/releases/latest',
process.env.GITHUB_TOKEN && {
headers: {
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`
},
});
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
const { tag_name } = await res.json();
console.log(tag_name.replace('cares-', '').replaceAll('_', '.'));
const { tag_name, assets } = await res.json();
const { browser_download_url, name } = assets.find(({ name }) => name.endsWith('.tar.gz'));
if(!browser_download_url || !name) throw new Error('No tarball found');
console.log(`${tag_name} ${browser_download_url} ${name}`);
EOF
)"

IFS=' ' read -r NEW_VERSION NEW_VERSION_URL ARES_TARBALL <<EOF
$NEW_VERSION_METADATA
EOF

CURRENT_VERSION=$(grep "#define ARES_VERSION_STR" ./deps/cares/include/ares_version.h | sed -n "s/^.*VERSION_STR \"\(.*\)\"/\1/p")

# This function exit with 0 if new version and current version are the same
Expand All @@ -41,17 +47,17 @@ cleanup () {

trap cleanup INT TERM EXIT

ARES_REF="cares-$(echo "$NEW_VERSION" | tr . _)"
ARES_TARBALL="c-ares-$NEW_VERSION.tar.gz"

cd "$WORKSPACE"

echo "Fetching c-ares source archive"
curl -sL -o "$ARES_TARBALL" "https://github.com/c-ares/c-ares/releases/download/$ARES_REF/$ARES_TARBALL"
curl -sL -o "$ARES_TARBALL" "$NEW_VERSION_URL"
log_and_verify_sha256sum "c-ares" "$ARES_TARBALL"
gzip -dc "$ARES_TARBALL" | tar xf -
rm "$ARES_TARBALL"
mv "c-ares-$NEW_VERSION" cares
rm -- "$ARES_TARBALL"

FOLDER=$(ls -d -- */)

mv -- "$FOLDER" cares

echo "Removing tests"
rm -rf "$WORKSPACE/cares/test"
Expand Down

0 comments on commit 53a7b6e

Please sign in to comment.