Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / build-scripts / jenkins-build.sh
blob35786f96d0d60a0d74a675344316406851f46cce
1 #!/bin/bash
3 ###############################################################################
4 # Taken from Jenkins config
5 # The goal here is to chip away at this file and slowly move everything into
6 # gulp so that we're able to switch CI tools easier.
7 ###############################################################################
9 set -euo pipefail
10 IFS=$'\n\t'
12 set -e
13 set -x
15 if [[ "${FORCE_CLEAN_WORKSPACE:-}" == "true" ]]; then
16 git clean -xfd
19 GIT_BRANCH_SHORT=${GIT_BRANCH##origin/}
21 secrets_dir=""
22 trap clean_up EXIT
24 function clean_up {
25 if [[ -n "${secrets_dir}" ]]; then
26 rm -rf "${secrets_dir}"
29 if [[ -n "${secrets_file}" ]]; then
30 rm -rf "${secrets_file}"
34 function load_secrets {
35 secrets_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
36 secrets_file=$(mktemp)
37 git clone -b develop --depth 1 git@gitlab.com:gl-gitter/secrets.git ${secrets_dir}
38 pushd ${secrets_dir}
39 ${secrets_dir}/webapp/env-file test > ${secrets_file}
40 chmod 400 "${secrets_file}"
41 GITTER_SECRETS_ENV_FILE="${secrets_file}"
42 export GITTER_SECRETS_ENV_FILE
43 popd
46 load_secrets
48 function get_pr {
49 curl -s --fail -u "${GITHUB_API_CREDENTIALS_USERNAME}:${GITHUB_API_CREDENTIALS_PASSWORD}" \
50 "https://api.github.com/repos/troupe/gitter-webapp/pulls?state=all&head=troupe:${GIT_BRANCH_SHORT}" | \
51 python -c 'import sys, json; j=json.load(sys.stdin); print (j[0]["number"] if len(j) > 0 else "")'
55 function get_pr_labels {
56 curl -s --fail -u "${GITHUB_API_CREDENTIALS_USERNAME}:${GITHUB_API_CREDENTIALS_PASSWORD}" \
57 "https://api.github.com/repos/troupe/gitter-webapp/issues/${ghprbPullId}/labels" | \
58 python -c 'import sys, json; j=json.load(sys.stdin); print "\n".join(map(lambda x: x["name"], j))'
61 if [[ -z "${ghprbPullId:-}" ]] && [[ -n "${GIT_BRANCH_SHORT:-}" ]] && [[ "${GIT_BRANCH_SHORT:-}" != "develop" ]] && [[ "${GIT_BRANCH_SHORT:-}" != "master" ]] ; then
62 export ghprbPullId=$(get_pr || "")
63 echo "Pull Request found: ${ghprbPullId:-}"
66 export TEST_REDIS_HOST=${TEST_REDIS_HOST:-}
67 export FAST_UGLIFY=${FAST_UGLIFY:-}
68 export SENTRY_API_KEY=${SENTRY_API_KEY:-}
69 export SENTRY_DOMAIN=${SENTRY_DOMAIN:-}
70 export SENTRY_SLUG=${SENTRY_SLUG:-}
72 # test if the selected git tag is actually the checked out branch.
73 # a prod build checked out a feature branch once, and we have no idea why.
74 # better to be safe than have premature builds on prod.
75 test ${SELECTED_GIT_TAG:-} = ${GIT_BRANCH:-}
77 if [ ${STAGED_ENVIRONMENT:-} = true ]; then
78 make continuous-integration ASSET_TAG_PREFIX=S GIT_BRANCH=${GIT_BRANCH:-} GIT_COMMIT=${GIT_COMMIT:-}
79 else
80 make continuous-integration GIT_BRANCH=${GIT_BRANCH:-} GIT_COMMIT=${GIT_COMMIT:-}
83 mkdir -p output/meta/
85 ### Write pull-request labels to file for later
86 if [[ -n ${ghprbPullId:-} ]]; then
87 get_pr_labels > output/meta/pr-labels.txt
88 echo "${ghprbPullId:-}" > output/meta/pr-number.txt
91 ### Build Reports for Jenkins plot plugin
92 #mkdir -p output/plot-reports/
94 #PROD_DEPS_ALL_COUNT=$(npm --parseable --loglevel error ls --production |wc -l)
95 #echo "YVALUE=${PROD_DEPS_ALL_COUNT}" > output/plot-reports/production-dependencies-all-count.properties
97 #PROD_DEPS_DIRECT_COUNT=$(npm --parseable --loglevel error ls --production --depth 0 |wc -l)
98 #echo "YVALUE=${PROD_DEPS_DIRECT_COUNT}" > output/plot-reports/production-dependencies-direct-count.properties
101 #for i in router-app router-chat; do
102 # SIZE=$(stat --printf="%s" "output/assets/styles/${i}.css.gz")
103 # echo "YVALUE=${SIZE}" > output/plot-reports/css-size-${i}.properties
104 #done
106 #for i in vendor router-app router-chat; do
107 # SIZE=$(stat --printf="%s" "output/assets/js/${i}.js.gz")
108 # echo "YVALUE=${SIZE}" > output/plot-reports/js-size-${i}.properties
109 #done
111 if [[ "${FORCE_AUTO_DEPLOY:-}" != true ]] && [[ "${ENVIRONMENT:-}" = beta ]] && [[ "${STAGED_ENVIRONMENT:-}" = true ]]; then
112 echo "Should we do an auto-deploy?"
113 if [[ -f "output/meta/pr-labels.txt" ]]; then
114 if grep -q 'auto-deploy' output/meta/pr-labels.txt; then
115 touch output/meta/auto-deploy
119 else
120 touch output/meta/auto-deploy