-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.sh
More file actions
93 lines (86 loc) · 3.11 KB
/
build.sh
File metadata and controls
93 lines (86 loc) · 3.11 KB
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
#!/bin/bash
set -e
source .env
REPO=medianexapp/plugins
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
function upload_plugin_file() {
release=$1
upload_file=$2
RESULT=$(curl -s -X 'GET' \
"https://api.cnb.cool/$REPO/-/releases/tags/$release" \
-H 'accept: application/json' \
-H "Authorization: $CNB_TOKEN")
if echo $RESULT | grep -q errcode; then
commitID=$(git log --oneline | head -1| awk '{print $1}')
curl -s -X 'POST' \
"https://api.cnb.cool/$REPO/-/releases" \
-H 'accept: application/json' \
-H "Authorization: $CNB_TOKEN" \
-H 'Content-Type: application/json' \
-d "{\"name\": \"$release\",\"tag_name\": \"$release\",\"target_commitish\": \"$commitID\"}"
echo "Release $release created"
fi
docker run --rm \
-e TZ=Asia/Shanghai \
-e CNB_TOKEN=$CNB_TOKEN \
-e CNB_API_ENDPOINT='https://api.cnb.cool' \
-e CNB_WEB_ENDPOINT='https://cnb.cool' \
-e CNB_REPO_SLUG=$REPO \
-e PLUGIN_TAG=$release \
-e PLUGIN_ATTACHMENTS=$upload_file \
-v $(pwd):$(pwd) \
-w $(pwd) \
cnbcool/attachments:latest
}
function build() {
dir=$1
version=`grep ^version $dir/plugin.toml|awk -F'"' '{print $2}'`
echo "$dir current version: "$version
res=`curl -s -w "CODE:%{http_code}\n" ${SERVER_ADDR}/api/get_plugin_version/$dir`
code=$(echo $res | grep CODE|awk -F':' '{print $2}')
remoteVersion=""
if [[ $code -eq 200 ]]; then
remoteVersion=$(echo $res | grep -v CODE| tr -d '[:space:]')
fi
echo "$dir remote version: "$remoteVersion
needUpload=0
if [[ -z $remoteVersion ]];then
echo "$dir remote version is empty"
needUpload=1
else
if version_gt $version $remoteVersion; then
echo "$dir $version is greater than $remoteVersion"
needUpload=1
else
echo "$dir version not change"
needUpload=0
fi
fi
if [[ $needUpload -eq 1 ]];then
echo "start build plugin $dir"
make -C $dir
iconFile=$(grep icon ${dir}/plugin.toml|awk -F'"' '{print $2}')
id=$(grep "id =" ${dir}/plugin.toml|awk -F'"' '{print $2}')
upload_plugin_file $version $dir/dist/${id}.zip
upload_plugin_file $version $dir/$iconFile
plugin_file_url="https://cnb.cool/$REPO/-/releases/download/$version/$id.zip"
icon_url="https://cnb.cool/$REPO/-/releases/download/$version/$iconFile"
# cat $dir/plugin.toml
tomlConfig=`cat $dir/plugin.toml`
tomlConfig=$tomlConfig"\nplugin_file_url = \"$plugin_file_url\""
tomlConfig=$tomlConfig"\nicon_url = \"$icon_url\""
tomlData=$(echo -e "$tomlConfig")
curl -X POST "${SERVER_ADDR}/api/release_plugin_version" \
-H 'Content-Type: application/toml' \
-H "SecretKey: ${SECRET_KEY}" \
-d "$tomlData"
fi
}
if [[ -z $SECRET_KEY ]];then
echo "vars SECRET_KEY is empty"
exit 1
fi
for id in `ls -d */ | grep -v 'util' |sed 's/\///g'`
do
build $id
done