-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.sh
executable file
·136 lines (104 loc) · 2.69 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
130
131
132
133
134
135
136
#!/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/publish
mkdir -p ${RUN_PATH}/target/release
}
################################################################################
_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}"
echo "${VERSION}" > ${RUN_PATH}/target/publish/VERSION
# publish sh
_package_sh ${RUN_PATH} ${RUN_PATH}/target/publish
# release
cp -rf ${RUN_PATH}/aliases.sh ${RUN_PATH}/target/release/aliases
cp -rf ${RUN_PATH}/toaster.sh ${RUN_PATH}/target/release/toaster
cp -rf ${RUN_PATH}/vimrc.sh ${RUN_PATH}/target/release/vimrc
# replace
_replace "s/THIS_VERSION=.*/THIS_VERSION=${VERSION}/g" ${RUN_PATH}/target/release/toaster
_replace "s/THIS_VERSION=.*/THIS_VERSION=${VERSION}/g" ${RUN_PATH}/target/publish/toaster
# # tar toaster
# pushd ${RUN_PATH}/target/release
# tar cvzpf aliases-${VERSION}.tar.gz ./aliases
# tar cvzpf toaster-${VERSION}.tar.gz ./toaster
# tar cvzpf vimrc-${VERSION}.tar.gz ./vimrc
# popd
ls -al ${RUN_PATH}/target/publish
ls -al ${RUN_PATH}/target/release
}
_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