forked from DefiLlama/defillama-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·68 lines (57 loc) · 1.92 KB
/
build.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
#!/bin/bash
# source .env if it exists
set -a
[ -f .env ] && . .env
# find the last commit hash and commit comment and author
COMMIT_AUTHOR=$(git log -1 --pretty=%an)
COMMIT_HASH=$(git rev-parse HEAD)
COMMIT_COMMENT=$(git log -1 --pretty=%B)
# starting time in UTC string and timestamp (for calculating build duration)
START_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
START_TIME_TS=$(date -u +"%s")
echo ""
echo "======================="
echo "🔨 New build started"
echo "💬 $COMMIT_COMMENT"
echo "🦙 $COMMIT_AUTHOR"
echo "📸 $COMMIT_HASH"
echo "======================="
echo ""
next build 2>&1 | tee build.log
BUILD_STATUS=${PIPESTATUS[0]}
BUILD_TIME_SEC=$(($(date -u +"%s") - $START_TIME_TS))
BUILD_TIME_MIN=$(($BUILD_TIME_SEC / 60))
BUILD_TIME_STR=$(printf "%ss" $(($BUILD_TIME_SEC % 60)))
if [ $BUILD_TIME_MIN -gt 0 ]; then
BUILD_TIME_STR=$(printf "%sm %s" $BUILD_TIME_MIN $BUILD_TIME_STR)
fi
# find the parent directory name of the file _buildManifest.js within the .next/static directory
BUILD_ID=$(find .next -name _buildManifest.js | sed 's/\/_buildManifest.js//g' | sed 's/\.next\/static\///g')
echo ""
echo "======================="
if [ $BUILD_STATUS -eq 0 ]; then
echo "🎉 Build succeeded in $BUILD_TIME_STR"
else
echo "🚨 Build failed in $BUILD_TIME_STR"
fi
echo "📅 Build started at: $START_TIME"
if [ -n "$BUILD_ID" ]; then
echo "📦 Build ID: $BUILD_ID"
fi
echo "======================="
echo "💬 [$COMMIT_COMMENT]"
echo "🦙 $COMMIT_AUTHOR"
echo "📸 $COMMIT_HASH"
echo "======================="
echo ""
if [ -z "$NOT_VERCEL" ]; then
echo "NOT_VERCEL is not set, skipping discord notification"
exit $BUILD_STATUS
fi
if [ -n "$IS_BACKUP" ]; then
echo "IS_BACKUP is set, skipping discord notification"
exit $BUILD_STATUS
fi
node ./scripts/build-msg.js $BUILD_STATUS "$BUILD_TIME_STR" "$START_TIME" "$BUILD_ID" "$COMMIT_COMMENT" "$COMMIT_AUTHOR" "$COMMIT_HASH"
# exit with the build status
exit $BUILD_STATUS