Skip to content

Commit

Permalink
Merge pull request #422 from letsencrypt/419_travis_details
Browse files Browse the repository at this point in the history
Issue #419 - Provide more details from Travis on PRs.
  • Loading branch information
jcjones committed Jul 8, 2015
2 parents 738d959 + d181d98 commit dc7e21b
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bin
# Test files
test/js/node_modules
test/js/*.pem
test/github-secret.json

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ branches:
sudo: required

before_install:
# Github-PR-Status secret
- openssl aes-256-cbc -K $encrypted_53b2630f0fb4_key -iv $encrypted_53b2630f0fb4_iv -in test/github-secret.json.enc -out test/github-secret.json -d

- go get golang.org/x/tools/cmd/vet
- go get golang.org/x/tools/cmd/cover
- go get github.com/golang/lint/golint
- go get github.com/mattn/goveralls
- go get github.com/modocache/gover
- go get github.com/jcjones/github-pr-status

# Boulder consists of multiple Go packages, which
# refer to each other by their absolute GitHub path,
# e.g. github.com/letsencrypt/boulder/analysis. That means, by default, if
Expand Down
148 changes: 131 additions & 17 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,119 @@ TESTDIRS="analysis \
# cmd
# Godeps

# We need to know, for github-pr-status, what the triggering commit is.
# Assume first it's the travis commit (for builds of master), unless we're
# a PR, when it's actually the first parent.
TRIGGER_COMMIT=${TRAVIS_COMMIT}
if [ "${TRAVIS_PULL_REQUEST}" != "false" ] ; then
revs=$(git rev-list --parents -n 1 HEAD)
# The trigger commit is the last ID in the space-delimited rev-list
TRIGGER_COMMIT=${revs##* }
fi

start_context() {
CONTEXT="$1"
printf "[%16s] Starting\n" ${CONTEXT}
}

end_context() {
printf "[%16s] Done\n" ${CONTEXT}
CONTEXT=""
}

update_status() {
if [ "${TRAVIS}" == "true" ] && [ "x${CONTEXT}" != "x" ] ; then
github-pr-status --authfile "$(pwd)/test/github-secret.json" \
--owner "letsencrypt" --repo "boulder" \
status --sha "${TRIGGER_COMMIT}" --context "${CONTEXT}" $*
fi
}

run() {
echo "$*"
if $*; then
echo "success: $*"
$* 2>&1
local status=$?

if [ ${status} -eq 0 ]; then
update_status --state success
echo "Success: $*"
else
FAILURE=1
echo "failure: $*"
update_status --state failure
echo "[!] FAILURE: $*"
fi

return ${status}
}

run_and_comment() {
if [ "x${TRAVIS}" = "x" ] || [ "${TRAVIS_PULL_REQUEST}" == "false" ] ; then
run $*
else
result=$(run $*)
local status=$?
# Only send a comment if exit code > 0
if [ ${status} -ne 0 ] ; then
echo $'```\n'${result}$'\n```' | github-pr-status --authfile "$(pwd)/test/github-secret.json" \
--owner "letsencrypt" --repo "boulder" \
comment --pr ${TRAVIS_PULL_REQUEST}
fi
fi
}

# Path for installed go package binaries. If yours is different, override with
# GOBIN=/my/path/to/bin ./test.sh
GOBIN=${GOBIN:-$HOME/gopath/bin}

# Ask vet to check in on things
run go vet -x ./...
#
# Run Go Vet, a correctness-focused static analysis tool
#

start_context "test/vet"
run_and_comment go vet ./...
end_context #test/vet

#
# Run Go Lint, a style-focused static analysis tool
#

start_context "test/golint"
[ -x "$(which golint)" ] && run golint ./...
end_context #test/golint

#
# Ensure all files are formatted per the `go fmt` tool
#
start_context "test/gofmt"
unformatted=$(find . -name "*.go" -not -path "./Godeps/*" -print | xargs -n1 gofmt -l)
if [ "x${unformatted}" == "x" ] ; then
update_status --state success
else

V="Unformatted files found.
Please run 'go fmt' on each of these files and amend your commit to continue."

[ -e $GOBIN/golint ] && run $GOBIN/golint ./...
for f in ${unformatted}; do
V=$(printf "%s\n - %s" "${V}" "${f}")
done

# Print to stdout
printf "%s\n\n" "${V}"
update_status --state failure --description "${V}"

# Post a comment with the unformatted list
if [ "${TRAVIS_PULL_REQUEST}" != "false" ] ; then
run_and_comment printf "%s\n\n" "${V}"
fi

[ "${TRAVIS}" == "true" ] || exit 1 # Stop here if running locally
fi
end_context #test/gofmt

#
# Unit Tests. These do not receive a context or status updates,
# as they are reflected in our eventual exit code.
#

# Ensure SQLite is installed so we don't recompile it each time
go install ./Godeps/_workspace/src/github.com/mattn/go-sqlite3
Expand Down Expand Up @@ -70,9 +164,21 @@ fi

# If the unittests failed, exit before trying to run the integration test.
if [ ${FAILURE} != 0 ]; then
echo "--------------------------------------------------"
echo "--- A unit test failed. ---"
echo "--- Stopping before running integration tests. ---"
echo "--------------------------------------------------"
exit ${FAILURE}
fi

#
# Integration tests
#

# Set context to integration, and force a pending state
start_context "test/integration"
update_status --state pending --description "Integration Tests in progress"

if [ -z "$LETSENCRYPT_PATH" ]; then
LETSENCRYPT_PATH=$(mktemp -d -t leXXXX)

Expand All @@ -94,16 +200,24 @@ fi
source $LETSENCRYPT_PATH/venv/bin/activate
export LETSENCRYPT_PATH

run python test/amqp-integration-test.py

unformatted=$(find . -name "*.go" -not -path "./Godeps/*" -print | xargs -n1 gofmt -l)
if [ "x${unformatted}" != "x" ] ; then
echo "Unformatted files found; setting failure state."
echo "Please run 'go fmt' on each of these files and amend your commit to continue."
FAILURE=1
for f in ${unformatted}; do
echo "- ${f}"
done
fi
python test/amqp-integration-test.py
case $? in
0) # Success
update_status --state success
;;
1) # Python client failed, but Node client didn't, which does
# not constitute failure
update_status --state success --description "Python integration failed."
;;
2) # Node client failed
update_status --state failure --description "NodeJS integration failed."
FAILURE=1
;;
*) # Error occurred
update_status --state error --description "Unknown error occurred."
FAILURE=1
;;
esac
end_context #test/integration

exit ${FAILURE}
21 changes: 12 additions & 9 deletions test/amqp-integration-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

tempdir = tempfile.mkdtemp()

class ExitStatus:
OK, PythonFailure, NodeFailure, Error = range(4)

exit_status = 0

def die():
def die(status):
global exit_status
exit_status = 1
exit_status = status
sys.exit(1)

processes = []
Expand All @@ -24,7 +27,7 @@ def run(path):
cmd = 'go build -tags pkcs11 -o %s %s' % (binary, path)
print(cmd)
if subprocess.Popen(cmd, shell=True).wait() != 0:
die()
die(ExitStatus.Error)
processes.append(subprocess.Popen('''
exec %s --config test/boulder-test-config.json
''' % binary, shell=True))
Expand All @@ -42,25 +45,25 @@ def run_node_test():
s.connect(('localhost', 4300))
except socket.error, e:
print("Cannot connect to WFE")
die()
die(ExitStatus.Error)

os.chdir('test/js')

if subprocess.Popen('npm install', shell=True).wait() != 0:
print("\n Installing NPM modules failed")
die()
die(ExitStatus.Error)
if subprocess.Popen('''
node test.js --email foo@letsencrypt.org --agree true \
--domains foo.com --new-reg http://localhost:4300/acme/new-reg \
--certKey %s/key.pem --cert %s/cert.der
''' % (tempdir, tempdir), shell=True).wait() != 0:
print("\nIssuing failed")
die()
die(ExitStatus.NodeFailure)
if subprocess.Popen('''
node revoke.js %s/cert.der %s/key.pem http://localhost:4300/acme/revoke-cert
''' % (tempdir, tempdir), shell=True).wait() != 0:
print("\nRevoking failed")
die()
die(ExitStatus.NodeFailure)

return 0

Expand All @@ -72,14 +75,14 @@ def run_client_tests():
os.environ['SERVER'] = 'http://localhost:4300/acme/new-reg'
test_script_path = os.path.join(root, 'tests', 'boulder-integration.sh')
if subprocess.Popen(test_script_path, shell=True, cwd=root).wait() != 0:
die()
die(ExitStatus.PythonFailure)

try:
start()
run_node_test()
run_client_tests()
except Exception as e:
exit_status = 1
exit_status = ExitStatus.Error
print e
finally:
for p in processes:
Expand Down
7 changes: 7 additions & 0 deletions test/github-secret.json.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
C��W{w��C�
���tY���A�� ���R_�q�7�]'|@Sܳ�ic�Cڦ����'�S>��A< J�Z
����
�{ �-J/18���c�z�q=��&�rq
�����
Ѹ� ���@�[
Expand Down

0 comments on commit dc7e21b

Please sign in to comment.