Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
chore(ci): add scripts to test against multiple releases of AngularJS
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko committed Sep 22, 2015
1 parent 3bd16be commit 1a0fc6b
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
dist
/.idea/
.nvmrc
tmp/
94 changes: 94 additions & 0 deletions scripts/find-max-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// INPUT = $1 = VERSION
// (something like 1.3 or 1.4.5)

// OUTPUT = a specific version number
// (something like 1.3.19 or 1.5.0-beta.2)

// this is used so that we can run a `git`
// command which is required to parse the
// collection of tags so that we can figure out
// the max version for the provided branch value
var exec = require('child_process').exec;

// this is the provided input value which could
// be a general branch like `1.3` or a specific
// version like `1.4.6`.
var version = process.argv[2];
if (!version) return;

exec("git --git-dir ./tmp/angular.js/.git tag", function(error, output) {
var v = findMaxVersion(version, output);
if (v) {
// drop the `v` prefix from the version
// `v1.3.5` => `1.3.5`
//
// this will relay the version number over
// to the build script that used this
console.log(v.substr(1));
}
});

function findMaxVersion(branch, output) {
var lines;
var highestVersion;
var majorBranch;

// these weights are used to figure out which
// releases are more important than others
// (e.g. 1.3.0 > 1.3.0.beta.2)
var WEIGHTS = {
'beta': 10,
'rc': 1000,
'stable': 1000000
};

// this happens if the user provides a specific
// version like `1.3.5` or `1.5.0-beta.2` instead
// of a general branch like `1.3` or `1.5`.
if (branch.match(/\./g).length > 1) {
lines = ['v' + branch];
majorBranch = branch.match(/^\d+\.\d+/)[0];
} else {
majorBranch = branch;
lines = output.split("\n");
}

var versionRegex = new RegExp('^v' + majorBranch + '.(\\d+)(?:-(beta|rc).(\\d+))?');

for (var i = lines.length - 1; i >= 0; i--) {
var line = lines[i];
var result = line.match(versionRegex);
if (result && result.length > 0) {
// stable releases have a higher weight than beta/RC versions
// so we want to include
var weight = result[1] * WEIGHTS.stable;

if (result[2]) {
// something like "1.3.0-beta.2" will have a weight
// of 20 while "1.3.0-rc.2" will have a weight of
// 2000 while "1.3.2" will have a weight of 2000000
// (which is calculated a few lines above here).
// we add "1" to the end incase we match something
// like "beta.0"
//
// so 1.3.0-beta.0 => 10 and 1.3.0-rc.0 => 1000
var multiplier = WEIGHTS[result[2]];
weight += multiplier * (result[3] + 1);
} else {
// this adds an extra 1 as well so that
// 1.3.0 => 1000000
weight += WEIGHTS.stable;
}

if (!highestVersion || highestVersion.weight < weight) {
highestVersion = { version: line, weight: weight };
}
}
}

// in the event that we don't figure out a version
// due to mismatched branches/tags we should not
// return anything. The build scripts will detect
// this and set a failing exit code.
return highestVersion && highestVersion.version;
}
125 changes: 125 additions & 0 deletions scripts/test-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# the purpose of this file is to download
# assigned AngularJS source files and test
# them against this build of AngularMaterial.

# This works by pulling in all of the tags
# form angular.js, finding the highest version
# numbers for each branch (e.g. 1.3 => 1.3.X where
# X is the highest patch release). For each
# detected version it will then copy over each
# of the source files to the node_modules/angular-X
# folder and then run `gulp karma` to see if
# they pass. If there are one or more failed tests
# then this script will propagate a failed exit code

# [INPUT]
# just run `./scripts/test-versions.sh`

# [OUTPUT]
# an exit code of "0" (passing) or "1" (failing)

# [CONFIG VALUES]

# Available Options are: 1.X, 1.X.X, 1.X.X-(beta|rc).X or snapshot
VERSIONS=(1.3 1.4 1.5 snapshot)

#
# DO NOT EDIT PASSED THIS LINE

This comment has been minimized.

Copy link
@Frank3K

Frank3K Sep 22, 2015

Contributor

Typo? PASSED vs PAST (or is BELOW better?)

#
CDN="https://code.angularjs.org"
FAILED=false
ANGULAR_FILES=(
angular
angular-animate
angular-route
angular-aria
angular-messages
angular-mocks
)

if [ ${#VERSIONS[@]} == 0 ]; then
echo "Error: please specify one or more versions of AngularJS to test..."
exit 1
fi;

if [ ! -e ./tmp ]; then
mkdir -p ./tmp
fi

if [ ! -e ./tmp/angular.js ]; then
git clone https://github.com/angular/angular.js ./tmp/angular.js
fi

for VERSION in "${VERSIONS[@]}"; do
if [ $VERSION == "snapshot" ]; then
ZIP_FILE_SHA=$(curl "$CDN/snapshot/version.txt")
ZIP_URL="$CDN/snapshot/angular-$ZIP_FILE_SHA.zip"
else
LATEST_VERSION=$(node ./scripts/find-max-version.js $VERSION)
echo $LATEST_VERSION
if [ ! $LATEST_VERSION ]; then
echo "Error: version "$VERSION" of angular does not exist..."
exit 1
fi

VERSION=$LATEST_VERSION
ZIP_FILE_SHA=$VERSION
ZIP_URL="$CDN/$VERSION/angular-$VERSION.zip"
fi

BASE_DIR="./tmp/angular-$VERSION"

if [ ! -d $BASE_DIR ]; then
ZIP_FILE="angular-$VERSION.zip"
ZIP_FILE_PATH="./tmp/$ZIP_FILE"

curl $ZIP_URL > $ZIP_FILE_PATH
unzip -d $BASE_DIR $ZIP_FILE_PATH
mv "$BASE_DIR/angular-$ZIP_FILE_SHA" "$BASE_DIR/files"
fi

echo "\n\n--- Testing AngularMaterial against AngularJS (${VERSION}) ---\n"

for ANGULAR_FILE in "${ANGULAR_FILES[@]}"; do
REPLACEMENT_FILE="$BASE_DIR/files/$ANGULAR_FILE.js"
MIN_REPLACEMENT_FILE="$BASE_DIR/files/$ANGULAR_FILE.min.js"

NODE_LIB_FILE="./node_modules/$ANGULAR_FILE/$ANGULAR_FILE.js"
MIN_NODE_LIB_FILE="./node_modules/$ANGULAR_FILE/$ANGULAR_FILE.min.js"

rm $NODE_LIB_FILE
cp $REPLACEMENT_FILE $NODE_LIB_FILE
echo "[copy] copied over $REPLACEMENT_FILE to $NODE_LIB_FILE"

if [ -e $MIN_NODE_LIB_FILE ]; then
rm $MIN_NODE_LIB_FILE
fi

if [ -e $MIN_REPLACEMENT_FILE ]; then
cp $MIN_REPLACEMENT_FILE $MIN_NODE_LIB_FILE
fi
echo "[copy] copied over $MIN_REPLACEMENT_FILE to $MIN_NODE_LIB_FILE"
done

echo "\n"
node ./node_modules/gulp/bin/gulp.js karma --reporters='dots'
LAST_EXIT_CODE=$?

echo "\n\n--- Finished Testing AngularMaterial against AngularJS (${VERSION}) ---"

if [ $LAST_EXIT_CODE == "1" ]; then
echo "STATUS: FAILED"
FAILED=true
else
echo "STATUS: SUCCESS"
fi

echo "\n\n"
done

if [ $FAILED == true ]; then
echo "Error: One or more of the karma tests have failed..."
exit 1
else
echo "All tests have passed successfully..."
fi

0 comments on commit 1a0fc6b

Please sign in to comment.