Skip to content

Commit 1bf468e

Browse files
committed
tools: add update script for ata dependency
1 parent d8df486 commit 1bf468e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tools/dep_updaters/update-ata.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update ata 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/ata-core/ata-validator/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=$(grep "#define ATA_VERSION" "$DEPS_DIR/ata/ata.h" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
27+
28+
# This function exit with 0 if new version and current version are the same
29+
compare_dependency_version "ata" "$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+
ATA_REF="v$NEW_VERSION"
44+
ATA_ZIP="ata-$NEW_VERSION.zip"
45+
46+
cd "$WORKSPACE"
47+
48+
echo "Fetching ata source archive..."
49+
curl -sL -o "$ATA_ZIP" "https://github.com/ata-core/ata-validator/archive/refs/tags/$ATA_REF.zip"
50+
unzip "$ATA_ZIP"
51+
cd "ata-validator-$NEW_VERSION"
52+
53+
echo "Replacing existing ata (except GYP build files)"
54+
mv "$DEPS_DIR/ata/ata.gyp" "$WORKSPACE/"
55+
rm -rf "$DEPS_DIR/ata"
56+
mkdir -p "$DEPS_DIR/ata"
57+
mv singleheader/ata.h "$DEPS_DIR/ata/"
58+
mv singleheader/ata.cpp "$DEPS_DIR/ata/"
59+
mv LICENSE "$DEPS_DIR/ata/"
60+
mv "$WORKSPACE/ata.gyp" "$DEPS_DIR/ata/"
61+
62+
# Update the version number on maintaining-dependencies.md
63+
# and print the new version as the last line of the script as we need
64+
# to add it to $GITHUB_ENV variable
65+
finalize_version_update "ata" "$NEW_VERSION"

0 commit comments

Comments
 (0)