-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·146 lines (125 loc) · 2.92 KB
/
deploy.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
######################################################
# CanAirIO deploy release utility
#
# Author: @hpsaturn
# 2021 - 2024
######################################################
NAME=`cat platformio.ini | grep 'name =' | awk '{print $3}'`
if [[ -z "$NAME" ]]; then
NAME=`basename "$PWD"`
else
NAME=`echo "$NAME" | dos2unix`
fi
SRC_VER="${2}"
BUILD_DIR=.pio/build
DATE=`date +%Y%m%d`
RELDIR="releases"
RELNAME="${NAME}-v${SRC_VER}.zip"
OUTPUT="${RELDIR}/${RELNAME}"
showHelp () {
echo ""
echo "************************************************"
echo "** Build and deploy tag and release **"
echo "************************************************"
echo ""
echo "Usage alternatives:"
echo ""
echo "./deploy clean"
echo "./deploy build 0.1.0"
echo "./deploy github 0.1.0"
echo ""
}
validate_branch () {
current_branch=`git rev-parse --abbrev-ref HEAD`
if [ ${current_branch} != "master" ]; then
echo ""
echo "Error: you are in ${current_branch} branch please change to master branch."
echo ""
exit 1
fi
}
clean () {
rm -rf .pio
rm -f $OUTPUT
}
build () {
echo ""
echo "***********************************************"
echo "** Building v${SRC_VER}"
echo "***********************************************"
echo ""
cd $BUILD_DIR
array=(*/)
mkdir "tmp"
for dir in "${array[@]}"; do
flavor=`basename "${dir}"`
cp $dir/firmware.bin "tmp/${flavor}_firmware.bin"
cp $dir/partitions.bin "tmp/${flavor}_partitions.bin"
done
cd tmp
zip -r ../../../${OUTPUT} *.bin
cd ../../..
rm -r $BUILD_DIR/tmp
echo ""
echo "***********************************************"
echo "************** Build done *********************"
echo "***********************************************"
echo ""
md5sum $OUTPUT
du -hs $OUTPUT
echo ""
}
publish_release () {
echo ""
echo "***********************************************"
echo "********** Publishing release *****************"
echo "***********************************************"
echo ""
echo "Publishing release: v${SRC_VER}"
echo "uploading: ${OUTPUT}"
COMMIT_LOG=`git log -1 --format='%ci %H %s'`
git tag -a "${SRC_VER}" -m "release v${SRC_VER}"
git push origin "${SRC_VER}"
git log -n 10 --pretty=format:"%h %s" | gh release create "${SRC_VER}" -F - -t "v${SRC_VER}" -p ${OUTPUT}
echo ""
echo "***********************************************"
echo "************* done *********************"
echo "***********************************************"
echo ""
}
publish_pio () {
pio package publish
}
if [ "$1" = "" ]; then
showHelp
else
validate_branch
case "$1" in
clean)
clean
;;
help)
showHelp
;;
--help)
showHelp
;;
-help)
showHelp
;;
-h)
showHelp
;;
print)
printOutput
;;
github)
publish_release
;;
*)
build $1
;;
esac
fi
exit 0