This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbefore-install.inc.sh
132 lines (111 loc) · 4.52 KB
/
before-install.inc.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
function sf_rvm_unfuck() {
# from https://github.com/matthew-brett/multibuild/blob/34b988aab60a93fa3c7bd1eb88dd7c4361ca464f/common_utils.sh#L17
# Work round bug in travis xcode image described at
# https://github.com/direnv/direnv/issues/210
shell_session_update() { :; }
# Workaround for https://github.com/travis-ci/travis-ci/issues/8703
# suggested by Thomas K at
# https://github.com/travis-ci/travis-ci/issues/8703#issuecomment-347881274
unset -f cd
unset -f pushd
unset -f popd
}
sf_rvm_unfuck
# github action checkout
function sf_ga_checkout() {
cd ${GITHUB_WORKSPACE}
GIT_BRANCH=
GIT_CLONE_BRANCH_ARG=
if [[ "${GITHUB_REF:-}" =~ "^refs/heads/" ]]; then
GIT_BRANCH=${GITHUB_REF#refs\/heads\/}
GIT_CLONE_BRANCH_ARG="--branch=${GIT_BRANCH}"
fi
git clone --depth=50 ${GIT_CLONE_BRANCH_ARG} [email protected]:${GITHUB_REPOSITORY}.git
cd $(basename ${GITHUB_REPOSITORY})
[[ -z "${GIT_BRANCH}" ]] || {
git checkout -B ${GIT_BRANCH}
}
git reset --hard ${GITHUB_SHA}
git submodule update --init --recursive
}
function sf_private_submodules() {
[[ -z "${GH_TOKEN:-}" ]] || {
echo_do "Found GH_TOKEN, setting up github.com HTTPS authentication..."
echo -e "machine github.com\n login ${GH_TOKEN}" >> ~/.netrc
# cover git submodules's canonical ssh url
git config --global url.https://github.com/tobiipro/.insteadOf [email protected]:tobiipro/
# cover npm package.json's canonical git+ssh url
git config --global url.https://github.com/tobiipro/.insteadOf ssh://[email protected]/tobiipro/
echo_done
}
}
function sf_transcrypt() {
# de-transcrypt only for non-PRs or for PRs from the same repo
[[ "${CI_IS_PR:-}" != "true" ]] || {
[[ "${CI_PR_SLUG}" = "${CI_REPO_SLUG}" ]] || return 0
}
[[ -x "./transcrypt" ]] || return 0
[[ -n "${TRANSCRYPT_PASSWORD:-}" ]] || return 0
if git config --local transcrypted.version >/dev/null; then
echo_skip "${FUNCNAME[0]}: Repository isn't transcrypted..."
return 0
fi
echo_do "Found TRANSCRYPT_PASSWORD, setting up transcrypt..."
./transcrypt -y -c aes-256-cbc -p "${TRANSCRYPT_PASSWORD}"
unset TRANSCRYPT_PASSWORD
echo_done
}
function sf_os() {
[[ "${SF_FORCE_BOOTSTRAP:-}" = "true" ]] || {
SF_GIT_HASH=$(git -C ${SUPPORT_FIRECLOUD_DIR} rev-parse HEAD)
[[ ! -f /support-firecloud.bootstrapped ]] || {
SF_GIT_HASH_BOOTSTRAPPED=$(cat /support-firecloud.bootstrapped)
echo_info "${FUNCNAME[0]}: /support-firecloud.bootstrapped exists."
echo_info "${FUNCNAME[0]}: /support-firecloud.bootstrapped references ${SF_GIT_HASH_BOOTSTRAPPED}."
echo_info "${FUNCNAME[0]}: ${SUPPORT_FIRECLOUD_DIR} references ${SF_GIT_HASH}."
if [[ "${SF_GIT_HASH}" = "${SF_GIT_HASH_BOOTSTRAPPED}" ]]; then
echo_info "${FUNCNAME[0]}: Match found. Bootstrapping without minimal/common dependencies."
echo_info "${FUNCNAME[0]}: Running with SF_SKIP_COMMON_BOOTSTRAP=true."
export SF_SKIP_COMMON_BOOTSTRAP=true
export SF_LOG_BOOTSTRAP=true
else
echo_info "${FUNCNAME[0]}: Match not found. Bootstrapping from scratch."
fi
}
}
[[ "${CI_DEBUG_MODE:-}" != "true" ]] || {
SF_LOG_BOOTSTRAP=${SF_LOG_BOOTSTRAP:-true}
}
echo_info "${FUNCNAME[0]}: Running with SF_LOG_BOOTSTRAP=${SF_LOG_BOOTSTRAP:-}."
local BOOTSTRAP_SCRIPT="${SUPPORT_FIRECLOUD_DIR}/ci/${OS_SHORT}/bootstrap"
if [[ "${SF_LOG_BOOTSTRAP:-}" = "true" ]]; then
${BOOTSTRAP_SCRIPT}
return 0
fi
local TMP_SF_OS_LOG=$(mktemp)
echo_info "${FUNCNAME[0]}: Redirecting into ${TMP_SF_OS_LOG} to minimize CI log..."
echo " 0 1 2 3 4 5 6 7 8 9101112131415 min"
while :;do echo -n " ."; sleep 60; done &
local WHILE_LOOP_PID=$!
trap "kill ${WHILE_LOOP_PID}" EXIT
${BOOTSTRAP_SCRIPT} >${TMP_SF_OS_LOG} 2>&1 || {
echo
echo_err "${FUNCNAME[0]}: Failed. The latest log tail follows:"
tail -n1000 ${TMP_SF_OS_LOG}
sleep 10 # see https://github.com/travis-ci/travis-ci/issues/6018
return 1
}
echo
kill ${WHILE_LOOP_PID} && trap " " EXIT
}
function sf_ci_run_before_install() {
sf_private_submodules
sf_transcrypt
sf_os
[[ "${CI_DEBUG_MODE:-}" != "true" ]] || {
echo
echo " Please run \`./.ci.sh debug\` to activate your debug session !!!"
echo
}
}