-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.sh
executable file
·133 lines (105 loc) · 3.5 KB
/
bot.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
#!/bin/bash
if [[ -f ".env" ]]; then
source .env
else
echo "Erro: Arquivo .env não encontrado."
exit 1
fi
export CHAT_ID="${CHAT_ID:-}"
export API_ID="${API_ID:-}"
export API_HASH="${API_HASH:-}"
export BOT_TOKEN="${BOT_TOKEN:-}"
if [[ -z "$CHAT_ID" || -z "$API_ID" || -z "$API_HASH" || -z "$BOT_TOKEN" ]]; then
echo "Erro: Variáveis de ambiente não foram definidas corretamente."
exit 1
fi
if [[ -f "build_count.txt" ]]; then
build_count=$(cat build_count.txt)
else
build_count=0
fi
build_count=$((build_count + 1))
echo $build_count > build_count.txt
commit_head=$(git log --oneline -1 --pretty=format:'%h - %an')
commit_id=$(git log --oneline -1 --pretty=format:'%h')
author_name=$(echo $commit_head | cut -d ' ' -f 3-)
commit_hash=$(echo $commit_head | cut -d ' ' -f 1)
kernel_version=$(make kernelversion 2>/dev/null)
build_type="release"
tag="ginkgo_${commit_hash:0:7}_$(date +%Y%m%d)"
start_message=$(curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d chat_id=$CHAT_ID \
-d text="*Compilation started... please wait.*" \
-d parse_mode="Markdown")
start_time=$(date +%s)
./ksu_update.sh -t stable
./moe.sh
if [[ $? -eq 0 ]]; then
commit_head=$(git log --oneline -1 --pretty=format:'%h - %an')
commit_id=$(git log --oneline -1 --pretty=format:'%h')
author_name=$(echo $commit_head | cut -d ' ' -f 3-)
commit_hash=$(echo $commit_head | cut -d ' ' -f 1)
message_commit=$(git log --oneline -1 | cut -d ' ' -f 2-)
commit_text=$message_commit
commit_link=$(cat <<EOF
[${commit_text}](https://github.com/MoeKernel/android_kernel_xiaomi_ginkgo/commit/${commit_hash})
EOF
)
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
elapsed_minutes=$((elapsed_time / 60))
elapsed_seconds=$((elapsed_time % 60))
elapsed_minutes_formatted=$(printf "%.2f" $(echo "$elapsed_minutes + $elapsed_seconds / 60" | bc -l))
completion_message=$(cat <<EOF
Completed in ${elapsed_minutes_formatted} minute(s) and ${elapsed_seconds} second(s)!"
EOF
)
completed_compile_text=$(cat <<EOF
*Compilation completed!*
Commit: ${commit_link}
${completion_message}
EOF
)
build_info=$(cat <<EOF
*ginkgo build (#${build_count}) has succeeded*
*Kernel Version*: ${kernel_version}
*Build Type*: \`${build_type}\` *(KSU/Fourteen)*
*Tag*: \`${tag}\`
*Duration*: ${elapsed_minutes} Minutes ${elapsed_seconds} Seconds
@MoeKernel #ginkgo #ksu
EOF
)
zip_file=$(ls *.zip | head -n 1)
if [[ -n "$zip_file" ]]; then
caption=$(cat <<EOF
*Build Info*
• *Commit*: \`${commit_id}\`
• *Message*: \`${commit_text}\`
• *Author*: \`${author_name}\`
EOF
)
curl -s -F chat_id=$CHAT_ID \
-F document=@"$zip_file" \
-F caption="$caption" \
-F parse_mode="Markdown" \
"https://api.telegram.org/bot$BOT_TOKEN/sendDocument"
fi
message_id=$(echo $start_message | jq .result.message_id)
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/editMessageText" \
-d chat_id=$CHAT_ID \
-d message_id=$message_id \
-d text="$completed_compile_text" \
-d parse_mode="Markdown"
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d chat_id="@MoeNyanCI" \
-d text="$build_info" \
-d parse_mode="Markdown"
exit 0
else
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d chat_id=$CHAT_ID \
-d text="Compilation failed." \
-d parse_mode="Markdown"
exit 1
fi
echo "bot is running..."