Skip to content

Commit b92e26f

Browse files
author
George Adams
committed
tools: add download testing
This script will take an environment variable (NODE_VERSION) and download all of the files from `http://nodejs.org/dist/v<NODE_VERSION>/` It will then loop through the `SHASUMS256.txt` file to check if the SHA256SUMS match up. Initial issue here: #513
1 parent 5aea8f0 commit b92e26f

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

jenkins/download-test.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Pass `NODE_VERSION` as an environment variable. Can be an exact or vague version.
3+
# NODE_VERSION=v8 ./download-test.sh --tap ./test.tap
4+
5+
while [ $# -gt 1 ]; do
6+
7+
case "$1y" in
8+
-t|--tap)
9+
tapFile="$2"
10+
shift # Past option argument.
11+
;;
12+
*) # unknown option
13+
echo "Ignoring unknown option: $1"
14+
;;
15+
esac
16+
shift # Past option.0
17+
done
18+
19+
if [ "$DOWNLOAD_LOCATION" == "Nightly" ]; then
20+
downloadDir="nightly"
21+
else
22+
downloadDir="release"
23+
fi
24+
25+
if [ -z "$NODE_VERSION" ]; then
26+
echo "NODE_VERSION is undefined! Please declare NODE_VERSION"
27+
exit 1
28+
fi
29+
30+
# If the provided NODE_VERSION is inexact, e.g. `v8`, get the most recent matching version.
31+
LINK=`rsync rsync://unencrypted.nodejs.org/nodejs/$downloadDir/ | grep $NODE_VERSION | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1 | awk '{print $5}'`
32+
33+
# Remove old files
34+
[ "$tapFile" ] && rm -rf "$tapFile" && echo "TAP version 13" > $tapFile
35+
rm -rf v*
36+
37+
# Scrape the download server
38+
rsync -av rsync://unencrypted.nodejs.org/nodejs/"$downloadDir"/"$LINK" .
39+
40+
testNumber=0
41+
cat "$LINK"/SHASUMS256.txt | {
42+
while read line; do
43+
let testNumber++ # Increment at the beginning
44+
sha=$(echo "${line}" | awk '{print $1}')
45+
file=$(echo "${line}" | awk '{print $2}')
46+
echo "Checking shasum for $file"
47+
calculatedSHA=$(shasum -a 256 "$LINK/$file" | awk '{print $1}')
48+
if [ "$calculatedSHA" != "$sha" ]; then
49+
echo "Error - SHASUMS256 does not match for $file"
50+
echo "Expected - $sha"
51+
echo "Found - $calculatedSHA"
52+
if [ "$tapFile" ]; then
53+
echo "not ok $testNumber SHASUMS256 does not match for $file
54+
---
55+
echo "Expected - $sha"
56+
echo "Found - $remoteSHA"
57+
...
58+
" >> "$tapFile"
59+
fi
60+
else
61+
echo "Pass - SHASUMS256 is correct for $file"
62+
[ "$tapFile" ] && echo "ok $testNumber SHASUMS256 for $file is correct" >> "$tapFile"
63+
fi
64+
done
65+
[ "$tapFile" ] && echo "1..$testNumber" >> "$tapFile"
66+
}

0 commit comments

Comments
 (0)