Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/preview/workflow/lib/common.sh
2500 views
1
#!/bin/bash
2
3
# this script is meant to be sourced
4
5
FILE_PATH=$(dirname "${BASH_SOURCE[0]}")
6
7
# predefined exit codes for checks
8
export ERROR_WRONG_WORKSPACE=30
9
export ERROR_CHANGE_DIR=31
10
export ERROR_NO_WORKSPACE=32
11
export ERROR_NO_DIR=33
12
export ERROR_NO_PLAN=34
13
export ERROR_PLAN_FAIL=35
14
15
function import() {
16
local file="${FILE_PATH}/${1}"
17
if [ -f "${file}" ]; then
18
# shellcheck disable=SC1090
19
source "${file}"
20
else
21
echo "Error: Cannot find library at: ${file}"
22
exit 1
23
fi
24
}
25
26
# define some colors for our helper log function
27
BLUE='\033[0;34m'
28
RED='\033[0;31m'
29
GREEN='\033[0;32m'
30
YELLOW='\033[0;33m'
31
# NC=no color
32
NC='\033[0m'
33
34
function log_error() {
35
local text=$1
36
echo -e "${RED}ERROR: ${NC}${text}" 1>&2
37
}
38
39
function log_warn() {
40
local text="$1"
41
echo -e "${YELLOW}WARN: ${NC}${text}"
42
}
43
44
function log_success() {
45
local text=$1
46
echo -e "${GREEN}SUCCESS: ${NC}${text}"
47
}
48
49
function log_info() {
50
local text=$1
51
echo -e "${BLUE}INFO: ${NC}${text}"
52
}
53
54
function ask() {
55
while true; do
56
# shellcheck disable=SC2162
57
read -p "$* [y/n]: " yn
58
case $yn in
59
[Yy]*) return 0 ;;
60
[Nn]*) echo "Aborted" ; return 1 ;;
61
esac
62
done
63
}
64
65
function choose() {
66
local text=$1
67
shift
68
local choices=("$@")
69
70
echo -e "${text}" 1>&2
71
select choice in "${choices[@]}"; do
72
case $choice in
73
*) echo "${choice}"
74
break ;;
75
esac
76
done
77
}
78
79