-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage.sh
executable file
·129 lines (98 loc) · 2.44 KB
/
package.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
#!/bin/bash
OS_NAME="$(uname | awk '{print tolower($0)}')"
SHELL_DIR=$(dirname $0)
RUN_PATH=${SHELL_DIR}
REPOSITORY=${GITHUB_REPOSITORY}
USERNAME=${GITHUB_ACTOR}
REPONAME=$(echo "${REPOSITORY}" | cut -d'/' -f2)
################################################################################
# command -v tput > /dev/null && TPUT=true
TPUT=
_echo() {
if [ "${TPUT}" != "" ] && [ "$2" != "" ]; then
echo -e "$(tput setaf $2)$1$(tput sgr0)"
else
echo -e "$1"
fi
}
_result() {
echo
_echo "# $@" 4
}
_command() {
echo
_echo "$ $@" 3
}
_success() {
echo
_echo "+ $@" 2
exit 0
}
_error() {
echo
_echo "- $@" 1
exit 1
}
_replace() {
if [ "${OS_NAME}" == "darwin" ]; then
sed -i "" -e "$1" $2
else
sed -i -e "$1" $2
fi
}
_prepare() {
# chmod 755
find ./** | grep [.]sh | xargs chmod 755
# mkdir target
mkdir -p ${RUN_PATH}/target/build
mkdir -p ${RUN_PATH}/target/dist
}
################################################################################
_package_sh() {
FROM_PATH=$1
DEST_PATH=$2
LIST=/tmp/list
ls ${FROM_PATH} | grep '[.]sh' | sort > ${LIST}
while read FILENAME; do
DESTNAME=$(echo "${FILENAME}" | cut -d'.' -f1)
cp ${FROM_PATH}/${FILENAME} ${DEST_PATH}/${DESTNAME}
done < ${LIST}
}
_package() {
if [ ! -f ${RUN_PATH}/VERSION ]; then
_error
fi
VERSION=$(cat ${RUN_PATH}/VERSION | xargs)
_result "VERSION=${VERSION}"
# build
cp ${RUN_PATH}/README.md ${RUN_PATH}/target/build/README.md
cp ${RUN_PATH}/install.sh ${RUN_PATH}/target/build/install
cp ${RUN_PATH}/toast.sh ${RUN_PATH}/target/build/toast
# dist
cp ${RUN_PATH}/toast.sh ${RUN_PATH}/target/dist/toast
# version
echo "${VERSION}" > ${RUN_PATH}/target/build/VERSION
_replace "s/TOAST_VERSION=.*/TOAST_VERSION=${VERSION}/g" ${RUN_PATH}/target/build/toast
_replace "s/TOAST_VERSION=.*/TOAST_VERSION=${VERSION}/g" ${RUN_PATH}/target/dist/toast
ls -al ${RUN_PATH}/target/build
ls -al ${RUN_PATH}/target/dist
}
_message() {
cat <<EOF > ${RUN_PATH}/target/slack_message.json
{
"username": "${USERNAME}",
"attachments": [{
"color": "good",
"footer": "<https://github.com/${REPOSITORY}/releases/tag/${VERSION}|${REPOSITORY}>",
"footer_icon": "https://opspresso.github.io/tools/favicon/github.png",
"title": "${REPONAME}",
"text": "\`${VERSION}\`"
}]
}
EOF
}
################################################################################
_prepare
_package
_message
_success