-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·56 lines (47 loc) · 1.25 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
if [ $# -lt 1 ] || [ $# -gt 2 ] || ([ $# -eq 2 ] && [ "$2" != "--publish" ]); then
echo "Usage: ./build.sh --list"
echo " ./build.sh <version> [--publish]"
exit 1
fi
if [ "$1" == "--list" ]; then
git tag | tac
exit 0
fi
if [ -n "$(git tag | grep "$1")" ]; then
echo -n "Version $1 already exists, overwrite? (y/n): "
read resp
if [ "$resp" != "y" ]; then
echo "Aborted. The most recent version is $(git tag | tac | head -n 1)."
exit 1
fi
overwrite=1
else
overwrite=0
fi
echo "Building frontend..."
cd frontend || exit 1
npm run build
if [ $? -ne 0 ]; then
echo "An error occurred while building the frontend. The build was aborted."
exit 1
fi
echo "Building image..."
cd ..
docker build . -t "jl58261/minicms:$1"
if [ $? -ne 0 ]; then
echo "An error occurred while building the image. The build was aborted."
exit 1
fi
if [ "$2" == "--publish" ]; then
if [ "$overwrite" == "1" ]; then
echo "Removing previous commit tag..."
git tag -d "$1"
fi
echo "Tagging commit..."
git tag "$1"
echo "Publishing to GitHub..."
git push --tags --force-with-lease
echo "Publishing to Docker Hub..."
docker push "jl58261/minicms:$1"
fi
echo "Done."