forked from V5-Client/V5
-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (206 loc) · 9.3 KB
/
Copy pathdiscord-commit.yml
File metadata and controls
242 lines (206 loc) · 9.3 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: Send Commit Message to Discord
on:
push:
branches:
- '**'
workflow_dispatch:
inputs:
sha:
description: 'Commit SHA to run against (optional).'
required: false
type: string
jobs:
notify-discord:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.sha || github.sha }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Cache global npm
uses: actions/cache@v4
with:
path: ~/.npm
key: npm-global-${{ runner.os }}
restore-keys: |
npm-global-${{ runner.os }}
- name: Install latest Wrangler
run: npm install -g wrangler@latest --prefer-offline
- name: Prepare Data
shell: bash
run: |
set -euo pipefail
HEAD_SHA="$(git rev-parse HEAD)"
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
echo "COMMIT_URL=https://github.com/${GITHUB_REPOSITORY}/commit/${HEAD_SHA}" >> "$GITHUB_ENV"
echo "TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_ENV"
echo "BRANCH=${GITHUB_REF#refs/heads/}" >> "$GITHUB_ENV"
echo "REPO_FULL=${GITHUB_REPOSITORY}" >> "$GITHUB_ENV"
echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> "$GITHUB_ENV"
declare -A USERS=(
["EpsilonPhoenix"]="<@1491118400385060925>"
["qxionr"]="<@790294721943699477>"
["quiteboring"]="<@1441859003708866601>"
["rdbtCVS"]="<@777346923232886784>"
["IcyHenryT"]="<@1160548899711356958>"
["oblongboot"]="<@768481984242253904>"
["axlecoffee"]="<@790736254714642453>"
)
ACTOR="$(git log -1 --pretty=%an)"
echo "DISCORD_AUTHOR=${USERS[$ACTOR]:-$ACTOR}" >> "$GITHUB_ENV"
BASE_SHA="$(git rev-parse "${HEAD_SHA}^" 2>/dev/null || echo "4b825dc642cb6eb9a060e54bf8d69288fbee4904")"
STATS="$(git diff --shortstat "$BASE_SHA" "$HEAD_SHA" || echo "0 files changed")"
echo "STATS_TEXT=$STATS" >> "$GITHUB_ENV"
EXT_LIST="$(
git diff --name-only "$BASE_SHA" "$HEAD_SHA" | awk '
{
f=$0
n=split(f,a,"/")
b=a[n]
if (index(b,".")==0) ext="noext"
else { ext=b; sub(/^.*\./,"",ext) }
print ext
}
' | sort | uniq -c | sort -nr | head -n 10 \
| awk '{print $2 " (" $1 ")"}' \
| paste -sd ", " -
)"
[[ -z "${EXT_LIST:-}" ]] && EXT_LIST="No specific types"
EXT_LIST="${EXT_LIST:0:1024}"
echo "FILE_TYPES=$EXT_LIST" >> "$GITHUB_ENV"
- name: Build Release ZIP
if: ${{ endsWith(github.repository, '/V5') }}
shell: bash
run: |
set -euo pipefail
workdir="$(mktemp -d)"
trap 'rm -rf "$workdir"' EXIT
source_dir="$workdir/source"
mkdir -p "$source_dir"
cp -a . "$source_dir"/
rm -rf "$source_dir/.git" "$source_dir/.github" "$source_dir/.vscode"
rm -f \
"$source_dir/.gitignore" \
"$source_dir/.prettierrc.json" \
"$source_dir/jsconfig.json" \
"$source_dir/typings.d.ts"
(
cd "$source_dir"
zip -qr "$GITHUB_WORKSPACE/V5-Mojmap.zip" .
)
- name: Upload Release zip to R2
if: ${{ endsWith(github.repository, '/V5') && github.ref == 'refs/heads/main' }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
wrangler r2 object put v5-builds/V5-Mojmap.zip --file V5-Mojmap.zip --remote
- name: Send to Discord
env:
WEBHOOK: ${{ secrets.PUSH_NOTIFIER }}
shell: bash
run: |
set -euo pipefail
COMMIT_MSG="$(git log -1 --pretty=%B)"
export CHUNK_LIMIT=3500
export COMMIT_MSG
mapfile -d '' MSG_CHUNKS < <(
python3 - << 'PY'
import os
import sys
s = os.environ.get("COMMIT_MSG", "")
limit = int(os.environ.get("CHUNK_LIMIT", "3500"))
if not s:
sys.stdout.write("No commit message.\0")
sys.exit(0)
start = 0
s_len = len(s)
while start < s_len:
end = start + limit
if end >= s_len:
sys.stdout.write(s[start:] + '\0')
break
chunk = s[start:end]
last_newline = chunk.rfind('\n')
if last_newline != -1:
cut_point = last_newline + 1
else:
cut_point = limit
sys.stdout.write(chunk[:cut_point] + '\0')
start += cut_point
PY
)
if [[ "${#MSG_CHUNKS[@]}" -eq 0 ]]; then
MSG_CHUNKS=("No commit message.")
fi
TOTAL="${#MSG_CHUNKS[@]}"
FIRST_MSG="${MSG_CHUNKS[0]}"
PAYLOAD="$(jq -cn \
--arg msg "$FIRST_MSG" \
--arg url "$COMMIT_URL" \
--arg author "$DISCORD_AUTHOR" \
--arg branch "$BRANCH" \
--arg time "$TIMESTAMP" \
--arg stats "$STATS_TEXT" \
--arg types "$FILE_TYPES" \
--arg repo "$REPO_NAME" \
--arg repofull "$REPO_FULL" \
--arg idx "1" \
--arg total "$TOTAL" \
'{
username: ($repo + " Commits"),
avatar_url: "https://p7.hiclipart.com/preview/227/12/28/catgirl-anime-kawaii-manga-cat.jpg",
embeds: [{
title: ("[" + $repo + "] New Commit" + (if ($total|tonumber) > 1 then " (" + $idx + "/" + $total + ")" else "" end)),
description: ("📝 **Summary**\n" + $msg + "\n\n[View Commit](" + $url + ")"),
color: 3447003,
timestamp: $time,
fields: [
{name: "Repository", value: $repofull, inline: true},
{name: "Author", value: $author, inline: true},
{name: "Branch", value: $branch, inline: true},
{name: "📊 Changes", value: $stats, inline: false},
{name: "📂 File Types", value: $types, inline: false}
]
}]
}'
)"
curl -sS --fail-with-body \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$WEBHOOK"
for ((i = 1; i < TOTAL; i++)); do
PART="${MSG_CHUNKS[$i]}"
IDX="$((i+1))"
CONT_PAYLOAD="$(jq -cn \
--arg msg "$PART" \
--arg url "$COMMIT_URL" \
--arg time "$TIMESTAMP" \
--arg repo "$REPO_NAME" \
--arg repofull "$REPO_FULL" \
--arg idx "$IDX" \
--arg total "$TOTAL" \
'{
username: ($repo + " Commits"),
avatar_url: "https://p7.hiclipart.com/preview/227/12/28/catgirl-anime-kawaii-manga-cat.jpg",
embeds: [{
title: ("[" + $repo + "] New Commit (continued " + $idx + "/" + $total + ")"),
description: ($msg + "\n\n[View Commit](" + $url + ")"),
color: 3447003,
timestamp: $time,
fields: [
{name: "Repository", value: $repofull, inline: true}
]
}]
}'
)"
curl -sS --fail-with-body \
-H "Content-Type: application/json" \
-d "$CONT_PAYLOAD" \
"$WEBHOOK"
done