-
Notifications
You must be signed in to change notification settings - Fork 8
379 lines (322 loc) · 15.8 KB
/
ci.yml
File metadata and controls
379 lines (322 loc) · 15.8 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
name: CI
on:
schedule:
- cron: "20 2,6,10,14,18,22 * * *" # Every 4 hours
workflow_dispatch:
concurrency:
group: ci
cancel-in-progress: false
jobs:
check_patch:
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
trigger_stable: ${{ steps.effective_triggers.outputs.TRIGGER_STABLE }}
trigger_prerelease: ${{ steps.effective_triggers.outputs.TRIGGER_PRERELEASE }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 1
- name: Ensure patch_sources.json exists
id: ensure_patch_sources
run: |
set -euo pipefail
mkdir -p .github/build
PATCH_FILE=".github/build/patch_sources.json"
if [ ! -f "$PATCH_FILE" ]; then
cat > "$PATCH_FILE" << 'EOF'
{
"dummy_patch": { "enabled": false, "repo": "" }
}
EOF
echo "created=true" >> "$GITHUB_OUTPUT"
else
echo "created=false" >> "$GITHUB_OUTPUT"
fi
- name: Commit dummy patch_sources.json if created
if: steps.ensure_patch_sources.outputs.created == 'true'
uses: stefanzweifel/git-auto-commit-action@v7
with:
branch: main
skip_checkout: true
file_pattern: .github/build/patch_sources.json
commit_message: "Create dummy patch_sources.json"
- name: Fetch latest tags
if: steps.ensure_patch_sources.outputs.created == 'false'
id: fetch_tags
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
PATCH_FILE=".github/build/patch_sources.json"
BASE_JSON=$(cat "$PATCH_FILE")
if echo "$BASE_JSON" | jq -e 'length == 0' >/dev/null; then
DELIM="$(openssl rand -hex 8)"
echo "latest<<${DELIM}" >> "$GITHUB_OUTPUT"
echo "$BASE_JSON" >> "$GITHUB_OUTPUT"
echo "${DELIM}" >> "$GITHUB_OUTPUT"
exit 0
fi
> updates.jsonl
while read -r id repo enabled enabledStable enabledDev; do
if [ "$enabled" == "false" ]; then continue; fi
api_response=$(gh api "repos/$repo/releases?per_page=100" 2>&1 || true)
if echo "$api_response" | grep -qi '"message".*Repository access blocked'; then
jq -n --arg id "$id" '{($id): {"blocked": true}}' >> updates.jsonl
elif echo "$api_response" | jq -e 'type == "array"' >/dev/null 2>&1; then
stable=$(echo "$api_response" | jq -r '(map(select(.prerelease == false and .tag_name != null and .tag_name != "")) | sort_by(.published_at) | reverse | .[0].tag_name // "")')
pre=$(echo "$api_response" | jq -r '(map(select(.prerelease == true and .tag_name != null and .tag_name != "")) | sort_by(.published_at) | reverse | .[0].tag_name // "")')
jq -n --arg id "$id" --arg stable "$stable" --arg pre "$pre" \
'{($id): {"stable": $stable, "prerelease": $pre, "blocked": false}}' >> updates.jsonl
else
echo "::warning::API error or rate limit for $repo. Retaining previous state."
old_stable=$(echo "$BASE_JSON" | jq -r ".\"$id\".stable // \"\"")
old_pre=$(echo "$BASE_JSON" | jq -r ".\"$id\".prerelease // \"\"")
old_blocked=$(echo "$BASE_JSON" | jq -r ".\"$id\".blocked // false")
jq -n --arg id "$id" --arg stable "$old_stable" --arg pre "$old_pre" --argjson blocked "$old_blocked" \
'{($id): {"stable": $stable, "prerelease": $pre, "blocked": $blocked}}' >> updates.jsonl
fi
done < <(echo "$BASE_JSON" | jq -r 'to_entries[] | select(.value.repo != "") | "\(.key) \(.value.repo) \(if .value.enabled == false then false else true end) \(if .value.enabledStable == false then false else true end) \(if .value.enabledDev == false then false else true end)"')
if [ -s updates.jsonl ]; then
NEW_JSON=$(jq -s --argjson base "$BASE_JSON" 'reduce .[] as $item ($base; . * $item)' updates.jsonl)
else
NEW_JSON="$BASE_JSON"
fi
DELIM="$(openssl rand -hex 8)"
echo "latest<<${DELIM}" >> "$GITHUB_OUTPUT"
echo "$NEW_JSON" >> "$GITHUB_OUTPUT"
echo "${DELIM}" >> "$GITHUB_OUTPUT"
- name: Compare latest vs stored tags
if: steps.ensure_patch_sources.outputs.created == 'false'
id: compare
run: |
set -euo pipefail
PATCH_FILE=".github/build/patch_sources.json"
OLD_JSON=$(cat "$PATCH_FILE")
NEW_JSON='${{ steps.fetch_tags.outputs.latest }}'
if [ -z "$NEW_JSON" ]; then
NEW_JSON="{}"
fi
TRIGGER_STABLE=$(jq -n --argjson old "$OLD_JSON" --argjson new "$NEW_JSON" '
[ $new | to_entries[] | . as $e
| ($old[$e.key] // {}) as $o
| select($e.value.stable != "" and $e.value.stable != ($o.stable // ""))
] | if length > 0 then 1 else 0 end
')
TRIGGER_PRERELEASE=$(jq -n --argjson old "$OLD_JSON" --argjson new "$NEW_JSON" '
[ $new | to_entries[] | . as $e
| ($old[$e.key] // {}) as $o
| select($e.value.prerelease != "" and $e.value.prerelease != ($o.prerelease // ""))
] | if length > 0 then 1 else 0 end
')
TRIGGER_BLOCKED=$(jq -n --argjson old "$OLD_JSON" --argjson new "$NEW_JSON" '
[ $new | to_entries[] | . as $e
| ($old[$e.key] // {}) as $o
| select($e.value.blocked == true and $o.blocked != true)
] | if length > 0 then 1 else 0 end
')
echo "$NEW_JSON" > "$PATCH_FILE"
echo "TRIGGER_STABLE=$TRIGGER_STABLE" >> "$GITHUB_OUTPUT"
echo "TRIGGER_PRERELEASE=$TRIGGER_PRERELEASE" >> "$GITHUB_OUTPUT"
echo "TRIGGER_BLOCKED=$TRIGGER_BLOCKED" >> "$GITHUB_OUTPUT"
DELIM1="$(openssl rand -hex 8)"
echo "tags_old<<${DELIM1}" >> "$GITHUB_OUTPUT"
echo "$OLD_JSON" >> "$GITHUB_OUTPUT"
echo "${DELIM1}" >> "$GITHUB_OUTPUT"
DELIM2="$(openssl rand -hex 8)"
echo "tags_new<<${DELIM2}" >> "$GITHUB_OUTPUT"
echo "$NEW_JSON" >> "$GITHUB_OUTPUT"
echo "${DELIM2}" >> "$GITHUB_OUTPUT"
- name: Generate configs (JSON)
if: steps.compare.outputs.TRIGGER_STABLE == '1' || steps.compare.outputs.TRIGGER_PRERELEASE == '1'
id: generate_configs
env:
TAGS_OLD: ${{ steps.compare.outputs.tags_old }}
TAGS_NEW: ${{ steps.compare.outputs.tags_new }}
run: |
set -euo pipefail
BASE_CONFIG="config.toml"
BASE_CONFIG_STABLE=".github/build/config.stable.toml"
BASE_CONFIG_DEV=".github/build/config.dev.toml"
[ -n "${TAGS_OLD:-}" ] || TAGS_OLD='{}'
[ -n "${TAGS_NEW:-}" ] || TAGS_NEW='{}'
jq -rn --argjson new "$TAGS_NEW" --argjson old "$TAGS_OLD" '
[ $new | to_entries[] | . as $e
| ($old[$e.key] // {}) as $o
| select($e.value.stable != "" and $e.value.stable != ($o.stable // ""))
| select($e.value.enabled != false and $e.value.enabledStable != false)
| $e.value.repo | ascii_downcase
]
' > active.stable.json
jq -rn --argjson new "$TAGS_NEW" --argjson old "$TAGS_OLD" '
[ $new | to_entries[] | . as $e
| ($old[$e.key] // {}) as $o
| select($e.value.prerelease != "" and $e.value.prerelease != ($o.prerelease // ""))
| select($e.value.enabled != false and $e.value.enabledDev != false)
| $e.value.repo | ascii_downcase
]
' > active.prerelease.json
yq -o=json '.' "$BASE_CONFIG" > base.json
if [ "${{ steps.compare.outputs.TRIGGER_STABLE }}" = "1" ]; then
if [ -f "$BASE_CONFIG_STABLE" ]; then
yq -o=json '.' "$BASE_CONFIG_STABLE" > stable_overrides.json
jq -s '.[0] * .[1]' base.json stable_overrides.json > config.stable.json
else
cp base.json config.stable.json
fi
jq --slurpfile active active.stable.json '
{ "parallel-jobs": 1, "enable-module-update": true } as $force |
($force + . + $force) |
map_values(
if type == "object" then
. as $app |
(($app["patches-source"] // "ReVanced/revanced-patches") | ascii_downcase) as $src |
if ($active[0] | index($src)) then $app else ($app | .enabled = false) end
else . end
)
' config.stable.json > .github/build/config.stable.updated.json
fi
if [ "${{ steps.compare.outputs.TRIGGER_PRERELEASE }}" = "1" ]; then
if [ -f "$BASE_CONFIG_DEV" ]; then
yq -o=json '.' "$BASE_CONFIG_DEV" > dev_overrides.json
jq -s '.[0] * .[1]' base.json dev_overrides.json > config.dev.json
else
cp base.json config.dev.json
fi
jq --slurpfile active active.prerelease.json '
{ "parallel-jobs": 1, "patches-version": "dev", "enable-module-update": false } as $force |
($force + . + $force) |
map_values(
if type == "object" then
. as $app |
(($app["patches-source"] // "ReVanced/revanced-patches") | ascii_downcase) as $src |
if ($active[0] | index($src)) then $app else ($app | .enabled = false) end
else . end
)
' config.dev.json > .github/build/config.dev.updated.json
fi
- name: Resolve effective triggers
id: effective_triggers
env:
CREATED: ${{ steps.ensure_patch_sources.outputs.created }}
RAW_TRIGGER_STABLE: ${{ steps.compare.outputs.TRIGGER_STABLE }}
RAW_TRIGGER_PRERELEASE: ${{ steps.compare.outputs.TRIGGER_PRERELEASE }}
run: |
set -euo pipefail
if [ "${CREATED:-false}" = "true" ]; then
echo "TRIGGER_STABLE=0" >> "$GITHUB_OUTPUT"
echo "TRIGGER_PRERELEASE=0" >> "$GITHUB_OUTPUT"
exit 0
fi
RAW_TRIGGER_STABLE=${RAW_TRIGGER_STABLE:-0}
RAW_TRIGGER_PRERELEASE=${RAW_TRIGGER_PRERELEASE:-0}
TRIGGER_STABLE=0
TRIGGER_PRERELEASE=0
if [ "$RAW_TRIGGER_STABLE" = "1" ]; then
CFG=".github/build/config.stable.updated.json"
ENABLED_COUNT=$(jq '[.[] | objects | select(.enabled != false)] | length' "$CFG" || echo 0)
if [ "${ENABLED_COUNT:-0}" -gt 0 ]; then
TRIGGER_STABLE=1
else
echo "::notice::Skipping stable build trigger: no enabled apps in $CFG"
fi
fi
if [ "$RAW_TRIGGER_PRERELEASE" = "1" ]; then
CFG=".github/build/config.dev.updated.json"
ENABLED_COUNT=$(jq '[.[] | objects | select(.enabled != false)] | length' "$CFG" || echo 0)
if [ "${ENABLED_COUNT:-0}" -gt 0 ]; then
TRIGGER_PRERELEASE=1
else
echo "::notice::Skipping dev build trigger: no enabled apps in $CFG"
fi
fi
echo "TRIGGER_STABLE=$TRIGGER_STABLE" >> "$GITHUB_OUTPUT"
echo "TRIGGER_PRERELEASE=$TRIGGER_PRERELEASE" >> "$GITHUB_OUTPUT"
- name: Notify telegram
if: steps.ensure_patch_sources.outputs.created == 'false' && (steps.compare.outputs.TRIGGER_STABLE == '1' || steps.compare.outputs.TRIGGER_PRERELEASE == '1' || steps.compare.outputs.TRIGGER_BLOCKED == '1')
env:
TG_TOKEN: ${{ secrets.TG_TOKEN }}
TAGS_OLD: ${{ steps.compare.outputs.tags_old }}
TAGS_NEW: ${{ steps.compare.outputs.tags_new }}
run: |
set -euo pipefail
[ -n "${TAGS_OLD:-}" ] || TAGS_OLD='{}'
[ -n "${TAGS_NEW:-}" ] || TAGS_NEW='{}'
MSG_BODY=$(jq -rn --argjson new "$TAGS_NEW" --argjson old "$TAGS_OLD" '
[ $new | to_entries[] | . as $e
| ($old[$e.key] // {}) as $o
| select(($e.value.stable != "" and $e.value.stable != ($o.stable // "")) or ($e.value.prerelease != "" and $e.value.prerelease != ($o.prerelease // "")) or ($e.value.blocked == true and $o.blocked != true))
| "📦 [\($e.value.repo)](https://github.com/\($e.value.repo))" +
(if ($e.value.blocked == true and $o.blocked != true) then "\n ╰ 🚫 Repository access blocked." else "" end) +
(if ($e.value.blocked != true and $e.value.stable != "" and $e.value.stable != ($o.stable // "")) then "\n ╰ Stable: [\($e.value.stable)](https://github.com/\($e.value.repo)/releases/tag/\($e.value.stable))" else "" end) +
(if ($e.value.blocked != true and $e.value.prerelease != "" and $e.value.prerelease != ($o.prerelease // "")) then "\n ╰ Pre-release: [\($e.value.prerelease)](https://github.com/\($e.value.repo)/releases/tag/\($e.value.prerelease))" else "" end)
] | join("\n\n")
')
if [ -z "$MSG_BODY" ]; then
echo "::notice::No actual updates to format for Telegram."
exit 0
fi
NL=$'\n'
if [ "${{ steps.compare.outputs.TRIGGER_STABLE }}" = "0" ] && [ "${{ steps.compare.outputs.TRIGGER_PRERELEASE }}" = "0" ]; then
FULL_MSG="*⚠️ Repository Status Update!*${NL}${NL}${MSG_BODY}"
else
FULL_MSG="*🚨 New Patch(es) Detected!*${NL}${NL}${MSG_BODY}"
fi
curl -s -X POST \
--data-urlencode "parse_mode=Markdown" \
--data-urlencode "disable_web_page_preview=true" \
--data-urlencode "text=${FULL_MSG}" \
--data-urlencode "chat_id=@rvb27" \
--data-urlencode "message_thread_id=2747" \
"https://api.telegram.org/bot${TG_TOKEN}/sendMessage" > /dev/null
- name: Commit updated patch sources and configs
if: steps.ensure_patch_sources.outputs.created == 'false' && (steps.compare.outputs.TRIGGER_STABLE == '1' || steps.compare.outputs.TRIGGER_PRERELEASE == '1' || steps.compare.outputs.TRIGGER_BLOCKED == '1')
uses: stefanzweifel/git-auto-commit-action@v7
with:
branch: main
skip_checkout: true
file_pattern: .github/build/*.json
commit_message: "Update patch sources and generated configs [skip ci]"
build_dev:
needs: check_patch
if: needs.check_patch.outputs.trigger_prerelease == '1'
uses: ./.github/workflows/build.yml
with:
config_file: ".github/build/config.dev.updated.json"
secrets: inherit
build_stable:
needs: [check_patch, build_dev]
if: |
always() &&
needs.check_patch.outputs.trigger_stable == '1' &&
needs.check_patch.result == 'success' &&
needs.build_dev.result != 'cancelled'
uses: ./.github/workflows/build.yml
with:
config_file: ".github/build/config.stable.updated.json"
secrets: inherit
trigger_website_update:
needs: [build_dev, build_stable]
if: |
always() &&
(needs.build_dev.result == 'success' || needs.build_stable.result == 'success')
uses: ./.github/workflows/update-website.yml
secrets: inherit
trigger_deploy_pages:
needs: [build_dev, build_stable]
if: |
always() &&
(needs.build_dev.result == 'success' || needs.build_stable.result == 'success')
uses: ./.github/workflows/deploy-pages.yml
secrets: inherit
trigger_cleanup:
needs: [build_dev, build_stable]
if: |
always() &&
(needs.build_dev.result == 'success' || needs.build_stable.result == 'success')
uses: ./.github/workflows/cleanup.yml
secrets: inherit