This repository has been archived by the owner on May 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjenkins.sh
executable file
·69 lines (58 loc) · 2.11 KB
/
jenkins.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
REPO_NAME=${REPO_NAME:-"alphagov/calendars"}
CONTEXT_MESSAGE=${CONTEXT_MESSAGE:-"default"}
GH_STATUS_GIT_COMMIT=${SCHEMA_GIT_COMMIT:-${GIT_COMMIT}}
TEST_TASK="ci:setup:minitest default"
function github_status {
REPO_NAME="$1"
STATUS="$2"
MESSAGE="$3"
gh-status "$REPO_NAME" "$GH_STATUS_GIT_COMMIT" "$STATUS" -d "Build #${BUILD_NUMBER} ${MESSAGE}" -u "$BUILD_URL" -c "$CONTEXT_MESSAGE" >/dev/null
}
function error_handler {
trap - ERR # disable error trap to avoid recursion
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}"
else
echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
fi
github_status "$REPO_NAME" error "errored on Jenkins"
exit "${code}"
}
trap 'error_handler ${LINENO}' ERR
github_status "$REPO_NAME" pending "is running on Jenkins"
# Cleanup anything left from previous test runs
git clean -fdx
# Try to merge master into the current branch, and abort if it doesn't exit
# cleanly (ie there are conflicts). This will be a noop if the current branch
# is master.
git merge --no-commit origin/master || git merge --abort
# Clone govuk-content-schemas depedency for contract tests
rm -rf tmp/govuk-content-schemas
git clone git@github.com:alphagov/govuk-content-schemas.git tmp/govuk-content-schemas
(
cd tmp/govuk-content-schemas
git checkout ${SCHEMA_GIT_COMMIT:-"master"}
)
export GOVUK_CONTENT_SCHEMAS_PATH=tmp/govuk-content-schemas
export RAILS_ENV=test
bundle install --path "${HOME}/bundles/${JOB_NAME}" --deployment --without development
# Lint changes introduced in this branch, but not for master
if [[ ${GIT_BRANCH} != "origin/master" ]]; then
bundle exec govuk-lint-ruby \
--diff \
--cached \
--format html --out rubocop-${GIT_COMMIT}.html \
--format clang \
app spec test
bundle exec govuk-lint-sass app
fi
if bundle exec rake ${TEST_TASK:-"default"}; then
github_status "$REPO_NAME" success "succeeded on Jenkins"
else
github_status "$REPO_NAME" failure "failed on Jenkins"
exit 1
fi