forked from alphagov/whitehall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins.sh
executable file
·73 lines (60 loc) · 2.22 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
70
71
72
73
#!/bin/bash -xe
export DISPLAY=:99
env
function github_status {
STATUS="$1"
MESSAGE="$2"
if [ "$GIT_BRANCH" != "origin/master" ]; then
gh-status alphagov/whitehall "$GIT_COMMIT" "$STATUS" -d "Build #${BUILD_NUMBER} ${MESSAGE}" -u "$BUILD_URL" >/dev/null
fi
}
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 failure "failed on Jenkins"
exit "${code}"
}
trap "error_handler ${LINENO}" ERR
github_status pending "is running on Jenkins"
# Ensure there are no artefacts left over from previous builds
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
# Generate directories for upload tests
mkdir -p ./incoming-uploads
mkdir -p ./clean-uploads
mkdir -p ./infected-uploads
mkdir -p ./attachment-cache
# Clone govuk-content-schemas depedency for contract tests
rm -rf tmp/govuk-content-schemas
git clone [email protected]:alphagov/govuk-content-schemas.git tmp/govuk-content-schemas
time bundle install --path "${HOME}/bundles/${JOB_NAME}" --deployment
# 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 test lib
fi
RAILS_ENV=test bundle exec rake db:drop db:create db:schema:load
RAILS_ENV=test GOVUK_CONTENT_SCHEMAS_PATH=tmp/govuk-content-schemas time bundle exec rake ci:setup:minitest test:in_parallel --trace
RAILS_ENV=production GOVUK_ASSET_ROOT=http://static.test.alphagov.co.uk time bundle exec rake assets:precompile --trace
EXIT_STATUS=$?
echo "EXIT STATUS: $EXIT_STATUS"
if [ "$EXIT_STATUS" == "0" ]; then
github_status success "succeeded on Jenkins"
else
github_status failure "failed on Jenkins"
fi
exit $EXIT_STATUS