forked from middlewarehq/middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.sh
executable file
·48 lines (39 loc) · 1.13 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
#!/bin/bash
[ ! -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 ..