From b92e26f5fda2db38c88feb4e9e1ea8865b7f503e Mon Sep 17 00:00:00 2001 From: George Adams Date: Wed, 19 Jul 2017 19:08:11 +0100 Subject: [PATCH] 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/` It will then loop through the `SHASUMS256.txt` file to check if the SHA256SUMS match up. Initial issue here: https://github.com/nodejs/build/issues/513 --- jenkins/download-test.sh | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 jenkins/download-test.sh diff --git a/jenkins/download-test.sh b/jenkins/download-test.sh new file mode 100755 index 000000000..547f64662 --- /dev/null +++ b/jenkins/download-test.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# Pass `NODE_VERSION` as an environment variable. Can be an exact or vague version. +# NODE_VERSION=v8 ./download-test.sh --tap ./test.tap + +while [ $# -gt 1 ]; do + + case "$1y" in + -t|--tap) + tapFile="$2" + shift # Past option argument. + ;; + *) # unknown option + echo "Ignoring unknown option: $1" + ;; + esac + shift # Past option.0 +done + +if [ "$DOWNLOAD_LOCATION" == "Nightly" ]; then + downloadDir="nightly" +else + downloadDir="release" +fi + +if [ -z "$NODE_VERSION" ]; then + echo "NODE_VERSION is undefined! Please declare NODE_VERSION" + exit 1 +fi + +# If the provided NODE_VERSION is inexact, e.g. `v8`, get the most recent matching version. +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}'` + +# Remove old files +[ "$tapFile" ] && rm -rf "$tapFile" && echo "TAP version 13" > $tapFile +rm -rf v* + +# Scrape the download server +rsync -av rsync://unencrypted.nodejs.org/nodejs/"$downloadDir"/"$LINK" . + +testNumber=0 +cat "$LINK"/SHASUMS256.txt | { + while read line; do + let testNumber++ # Increment at the beginning + sha=$(echo "${line}" | awk '{print $1}') + file=$(echo "${line}" | awk '{print $2}') + echo "Checking shasum for $file" + calculatedSHA=$(shasum -a 256 "$LINK/$file" | awk '{print $1}') + if [ "$calculatedSHA" != "$sha" ]; then + echo "Error - SHASUMS256 does not match for $file" + echo "Expected - $sha" + echo "Found - $calculatedSHA" + if [ "$tapFile" ]; then + echo "not ok $testNumber SHASUMS256 does not match for $file + --- + echo "Expected - $sha" + echo "Found - $remoteSHA" + ... + " >> "$tapFile" + fi + else + echo "Pass - SHASUMS256 is correct for $file" + [ "$tapFile" ] && echo "ok $testNumber SHASUMS256 for $file is correct" >> "$tapFile" + fi + done +[ "$tapFile" ] && echo "1..$testNumber" >> "$tapFile" +}