-
Notifications
You must be signed in to change notification settings - Fork 105
/
dev.sh
executable file
·104 lines (85 loc) · 2.85 KB
/
dev.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
#!/bin/bash
MINIMUM_NODE_VERSION=22.0.0
MINIMUM_YARN_VERSION=1.22.22
MINIMUM_DOCKER_VERSION=24.0.0
# Function to compare versions correctly
version_at_least() {
printf '%s\n%s\n' "$1" "$2" | sort -V | head -n 1 | grep -qx "$1"
}
check_versions() {
local node_version yarn_version docker_version
local errors=()
# Check Node.js version
if ! command -v node &> /dev/null; then
errors+=("Node.js is not installed. Please install Node.js v$MINIMUM_NODE_VERSION or higher.")
else
node_version=$(node -v | sed 's/^v//')
if ! version_at_least "$MINIMUM_NODE_VERSION" "$node_version"; then
errors+=("Current Node.js version ($node_version) is incompatible. Please install v$MINIMUM_NODE_VERSION or higher.")
fi
fi
# Check Yarn version
if ! command -v yarn &> /dev/null; then
errors+=("Yarn is not installed. Please install Yarn v$MINIMUM_YARN_VERSION or higher.")
else
yarn_version=$(yarn -v)
if ! version_at_least "$MINIMUM_YARN_VERSION" "$yarn_version"; then
errors+=("Current Yarn version ($yarn_version) is incompatible. Please install v$MINIMUM_YARN_VERSION or higher.")
fi
fi
# Check Docker version
if ! command -v docker &> /dev/null; then
errors+=("Docker is not installed. Please install Docker v$MINIMUM_DOCKER_VERSION or higher.")
else
docker_version=$(docker --version | awk '{print $3}' | sed 's/,//')
if ! version_at_least "$MINIMUM_DOCKER_VERSION" "$docker_version"; then
errors+=("Current Docker version ($docker_version) is incompatible. Please install v$MINIMUM_DOCKER_VERSION or higher.")
fi
fi
# Display errors, if any
if [ ${#errors[@]} -ne 0 ]; then
for error in "${errors[@]}"; do
echo "$error"
done
exit 1
fi
}
check_versions
[ ! -f .env ] && cp env.example .env
check_internet_connection() {
curl -s https://www.google.com > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "No internet connection. Cannot fetch latest commits."
return 1
fi
return 0
}
if ! check_internet_connection; then
BEHIND_COMMITS_COUNT=0
else
git fetch origin
BEHIND_COMMITS_COUNT=$(git rev-list --count main..origin/main)
fi
GIT_COMMIT_HASH=$(git rev-parse main)
GIT_COMMIT_DATE=$(git show -s --format=%cI $MERGE_COMMIT_SHA)
update_or_add_env_var() {
local var_name=$1
local var_value=$2
if grep -q "^$var_name=" .env; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/^$var_name=.*/$var_name=$var_value/" .env
else
sed -i "s/^$var_name=.*/$var_name=$var_value/" .env
fi
else
echo "$var_name=$var_value" >> .env
fi
}
update_or_add_env_var "BUILD_DATE" "$GIT_COMMIT_DATE"
update_or_add_env_var "MERGE_COMMIT_SHA" "$GIT_COMMIT_HASH"
update_or_add_env_var "BEHIND_COMMITS_COUNT" "$BEHIND_COMMITS_COUNT"
set -o allexport; source .env; set +o allexport
cd ./cli || exit
{ yarn && yarn build; } > /dev/null 2>&1
yarn start
cd ..