提交 0cb730dd 编写于 作者: M Mislav Marohnić

Merge pull request #220 from github/sauce-fix

Run Sauce Labs CI for pull requests
.env
bower_components/
node_modules/
sauce_connect/
sauce_connect.log
......@@ -12,8 +12,6 @@ env:
- SAUCE_PLATFORM="Windows 7" SAUCE_BROWSER="internet explorer" SAUCE_VERSION="11"
- SAUCE_PLATFORM="Windows 7" SAUCE_BROWSER="internet explorer" SAUCE_VERSION="10"
- SAUCE_PLATFORM="Windows 7" SAUCE_BROWSER="internet explorer" SAUCE_VERSION="9"
addons:
sauce_connect: true
deploy:
provider: npm
email: mislav.marohnic@gmail.com
......
......@@ -15,4 +15,16 @@ node_modules/:
clean:
rm -rf ./bower_components ./node_modules
ifeq ($(shell uname -s),Darwin)
sauce_connect/bin/sc:
wget https://saucelabs.com/downloads/sc-4.3.11-osx.zip
unzip sc-4.3.11-osx.zip
mv sc-4.3.11-osx sauce_connect
rm sc-4.3.11-osx.zip
else
sauce_connect/bin/sc:
mkdir -p sauce_connect
curl -fsSL http://saucelabs.com/downloads/sc-4.3.11-linux.tar.gz | tar xz -C sauce_connect --strip-components 1
endif
.PHONY: build clean lint test saucelabs travis
......@@ -9,16 +9,45 @@ node ./script/server $port &>/dev/null &
server_pid=$!
trap "kill $server_pid" INT EXIT
job=$(./script/saucelabs-start "http://localhost:$port/test/test.html")
make sauce_connect/bin/sc
sauce_ready="${TMPDIR:-/tmp}/sauce-ready.$$"
sauce_connect/bin/sc -u "$SAUCE_USERNAME" -k "$SAUCE_ACCESS_KEY" \
-i "$TRAVIS_JOB_NUMBER" -l sauce_connect.log -f "$sauce_ready" &>/dev/null &
sauce_pid=$!
trap "kill $sauce_pid" INT EXIT
while true
do
result=$(echo "$job" | ./script/saucelabs-status)
[[ $result == *"\"completed\": true"* ]] && break
while [ ! -f "$sauce_ready" ]; do sleep .01; done
rm -f "$sauce_ready"
job="$(./script/saucelabs-api --raw "js-tests" <<JSON
{ "public": "public",
"build": "$TRAVIS_BUILD_NUMBER",
"tags": ["$TRAVIS_PULL_REQUEST", "$TRAVIS_BRANCH"],
"tunnel-identifier": "$TRAVIS_JOB_NUMBER",
"platforms": [["$SAUCE_PLATFORM", "$SAUCE_BROWSER", "$SAUCE_VERSION"]],
"url": "http://localhost:$port/test/test.html",
"framework": "mocha"
}
JSON
)"
while true; do
result=$(./script/saucelabs-api "js-tests/status" <<<"$job")
grep -q "^completed: true" <<<"$result" && break
sleep 1
echo -n "."
done
echo -n ""
echo
echo "$result" | ./script/saucelabs-result
awk '
/result\.tests:/ { tests+=$(NF) }
/result\.passes:/ { passes+=$(NF) }
/result\.pending:/ { pending+=$(NF) }
/result\.failures:/ { failures+=$(NF) }
/\.url:/ { print $(NF) }
END {
printf "%d passed, %d pending, %d failures\n", passes, pending, failures
if (failures > 0 || tests != passes + pending) exit 1
}
' <<<"$result"
#!/bin/bash
set -e
raw=""
if [ "$1" = "--raw" ]; then
raw="1"
shift 1
fi
endpoint="$1"
curl -fs -X POST "https://saucelabs.com/rest/v1/$SAUCE_USERNAME/${endpoint}" \
-u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" \
-H "Content-Type: application/json" -d "@-" | \
{
if [ -n "$raw" ]; then
cat
else
ruby -rjson -e '
dump = lambda do |obj, ns|
case obj
when Array then obj.each_with_index { |v, i| dump.call(v, [ns, i]) }
when Hash then obj.each { |k, v| dump.call(v, [ns, k]) }
else puts "%s: %s" % [ ns.flatten.compact.join("."), obj.to_s ]
end
end
dump.call JSON.parse(STDIN.read), nil
'
fi
}
#!/usr/bin/env ruby
require 'json'
obj = JSON.parse(ARGF.read)
test = obj['js tests'][0]
warn test['url']
warn test['platform']
warn test['result'].inspect
if test['result'] && (test['result']['passes'] + test['result']['pending']) == test['result']['tests']
exit 0
else
exit 1
end
#!/bin/bash
set -e
url="https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests"
auth="$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"
header="Content-Type: application/json"
data=$(cat <<JSON
{
"public": "public",
"build": "$TRAVIS_BUILD_NUMBER",
"tags": ["$TRAVIS_PULL_REQUEST", "$TRAVIS_BRANCH"],
"tunnel-identifier": "$TRAVIS_JOB_NUMBER",
"platforms": [["$SAUCE_PLATFORM", "$SAUCE_BROWSER", "$SAUCE_VERSION"]],
"url": "$1",
"framework": "mocha"
}
JSON
)
curl -fs "$url" -X POST -u "$auth" -H "$header" -d "$data"
#!/bin/bash
set -e
url="https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests/status"
auth="$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"
header="Content-Type: application/json"
curl -fs "$url" -X POST -u "$auth" -H "$header" -d "@-"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册