Skip to content

Commit 2c44bf2

Browse files
committed
workflow: trim history commits
workflow: trim history commits workflow: trim history commits workflow: keep files change after trim
1 parent 5e283c3 commit 2c44bf2

File tree

6 files changed

+153
-24
lines changed

6 files changed

+153
-24
lines changed

.github/workflows/clear_cache.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
sudo apt-get update
2424
sudo apt-get -y install jq
2525
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v6
2727

2828
# https://github.com/marketplace/actions/git-changesets
2929
- id: changed_files

.github/workflows/compile_meta_core.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
sudo apt-get -y install git
2323
2424
- name: Clone OpenClash Repository
25-
uses: actions/checkout@v4
25+
uses: actions/checkout@v6
2626
with:
2727
ref: core
2828

@@ -61,7 +61,7 @@ jobs:
6161
arch: [normal, loongarch_abi1]
6262
steps:
6363
- name: Checkout OpenClash Repository
64-
uses: actions/checkout@v4
64+
uses: actions/checkout@v6
6565
with:
6666
ref: core
6767

@@ -111,7 +111,7 @@ jobs:
111111
go-loongarch-abi1-1.24.0-
112112
113113
- name: Clone MetaCubeX/mihomo source
114-
uses: actions/checkout@v4
114+
uses: actions/checkout@v6
115115
with:
116116
repository: MetaCubeX/mihomo
117117
ref: Alpha
@@ -163,7 +163,7 @@ jobs:
163163
arch: [normal, loongarch_abi1]
164164
steps:
165165
- name: Checkout OpenClash Repository
166-
uses: actions/checkout@v4
166+
uses: actions/checkout@v6
167167
with:
168168
ref: core
169169

@@ -215,7 +215,7 @@ jobs:
215215
go-loongarch-abi1-1.24.0-
216216
217217
- name: Clone vernesong/mihomo source
218-
uses: actions/checkout@v4
218+
uses: actions/checkout@v6
219219
with:
220220
repository: vernesong/mihomo
221221
ref: Alpha
@@ -266,7 +266,7 @@ jobs:
266266
if: always() && (needs.Get-Commit-id.outputs.current_id != needs.Get-Commit-id.outputs.upstream_id || needs.Get-Commit-id.outputs.current_smart_id != needs.Get-Commit-id.outputs.upstream_smart_id)
267267
steps:
268268
- name: Checkout OpenClash Repository
269-
uses: actions/checkout@v4
269+
uses: actions/checkout@v6
270270
with:
271271
ref: core
272272

@@ -390,4 +390,4 @@ jobs:
390390
git push
391391
else
392392
echo "No changes to commit."
393-
fi
393+
fi

.github/workflows/compile_new_ipk.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
current_version: ${{ steps.current_version.outputs.version }}
1717
steps:
1818
- name: Clone Repository
19-
uses: actions/checkout@v4
19+
uses: actions/checkout@v6
2020
with:
2121
ref: ${{ github.ref_name }}
2222

@@ -26,7 +26,7 @@ jobs:
2626
echo "version=$(grep 'PKG_VERSION:=' ./luci-app-openclash/Makefile |awk -F '=' '{print $2}')" >> $GITHUB_OUTPUT
2727
2828
- name: Clone Repository
29-
uses: actions/checkout@v4
29+
uses: actions/checkout@v6
3030
with:
3131
ref: package
3232

@@ -46,7 +46,7 @@ jobs:
4646
- { name: apk, sdk_url: "snapshot", sdk_tar: "SNAPSDK.tar.zst", sdk_backup_tar: "SNAPSDK.tar.zst", sdk_dir: "SNAPSDK", artifact_pattern: "luci-app-openclash-*.apk" }
4747
steps:
4848
- name: Checkout OpenClash Source
49-
uses: actions/checkout@v4
49+
uses: actions/checkout@v6
5050
with:
5151
ref: ${{ github.ref_name }}
5252

@@ -166,7 +166,7 @@ jobs:
166166
needs: [Compile, Get-Version]
167167
steps:
168168
- name: Checkout package branch
169-
uses: actions/checkout@v4
169+
uses: actions/checkout@v6
170170
with:
171171
ref: package
172172

@@ -191,12 +191,8 @@ jobs:
191191
cp ./luci-app-openclash-*.apk "./${{ github.ref_name }}/"
192192
rm -f ./luci-app-openclash_*.ipk
193193
rm -f ./luci-app-openclash-*.apk
194-
sed -i -E "s/OpenClash\/tree\/v(.*)/OpenClash\/tree\/v${{ needs.Get-Version.outputs.version }}/g" ./${{ github.ref_name }}/README.md
195-
sed -i -E "s/OpenClash\/releases\/tag\/v(.*)/OpenClash\/releases\/tag\/v${{ needs.Get-Version.outputs.version }}/g" ./${{ github.ref_name }}/README.md
196-
sed -i -E "s/source code-v(.*)-green/source code-v${{ needs.Get-Version.outputs.version }}-green/g" ./${{ github.ref_name }}/README.md
197-
sed -i -E "s/New Release-v(.*)-orange/New Release-v${{ needs.Get-Version.outputs.version }}-orange/g" ./${{ github.ref_name }}/README.md
198194
git config user.name 'github-actions[bot]'
199195
git config user.email 'github-actions[bot]@users.noreply.github.com'
200196
git add .
201197
git commit -m "Auto Release: v${{ needs.Get-Version.outputs.version }}"
202-
git push
198+
git push

.github/workflows/master_release_sync.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
sudo apt-get -y install git
1818
1919
- name: Clone OpenClash Repository
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@v6
2121
with:
2222
ref: core
2323

@@ -40,7 +40,7 @@ jobs:
4040
fi
4141
4242
- name: Clone OpenClash Repository
43-
uses: actions/checkout@v4
43+
uses: actions/checkout@v6
4444
with:
4545
ref: package
4646

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Trim Core and Package History
2+
3+
on:
4+
schedule:
5+
- cron: "0 18 * * 3"
6+
workflow_dispatch:
7+
8+
jobs:
9+
trim:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
branch: [core, package]
14+
steps:
15+
- name: Apt Update
16+
env:
17+
DEBIAN_FRONTEND: noninteractive
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get -y install git
21+
22+
- name: Trim History
23+
env:
24+
REPO_URL: https://github.com/vernesong/OpenClash.git
25+
BRANCH: ${{ matrix.branch }}
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
run: |
28+
set -euo pipefail
29+
30+
if [ "${BRANCH}" = "core" ]; then
31+
MAX_COMMITS=20
32+
LIMIT_COMMITS=10
33+
else
34+
MAX_COMMITS=50
35+
LIMIT_COMMITS=30
36+
fi
37+
38+
echo "Start full clone for history check (branch: ${BRANCH})..."
39+
mkdir -p ../full_clone_tmp
40+
cd ../full_clone_tmp
41+
git clone --branch "${BRANCH}" --single-branch --no-tags --progress --depth=1 "$REPO_URL" .
42+
43+
MAX_FETCH_RETRIES=3
44+
FETCH_OK=false
45+
for i in $(seq 1 $MAX_FETCH_RETRIES); do
46+
if git fetch --unshallow; then
47+
FETCH_OK=true
48+
break
49+
else
50+
echo "git fetch --unshallow failed (attempt $i/$MAX_FETCH_RETRIES), retrying..." >&2
51+
sleep 2
52+
fi
53+
done
54+
if [ "$FETCH_OK" = false ]; then
55+
echo "Warning: git fetch --unshallow failed after $MAX_FETCH_RETRIES attempts, proceeding with available history." >&2
56+
fi
57+
58+
count=$(git rev-list --count HEAD 2>/dev/null || echo 0)
59+
echo "Current commit count on ${BRANCH} branch: $count"
60+
if [ "$count" -le "$MAX_COMMITS" ]; then
61+
echo "No trimming needed (commit count: $count <= $MAX_COMMITS)."
62+
cd ..
63+
rm -rf full_clone_tmp
64+
exit 0
65+
fi
66+
67+
git config user.name 'github-actions[bot]'
68+
git config user.email 'github-actions[bot]@users.noreply.github.com'
69+
70+
echo "Collecting recent commits..."
71+
mapfile -t recent_commits < <(git rev-list --max-count=$LIMIT_COMMITS HEAD)
72+
73+
echo "Looking for sync commit (grep 'Release: Auto sync')..."
74+
sync_commit=$(git log --grep='Release: Auto sync' --format='%H' | tail -n 1 || true)
75+
76+
keep_commits=("${recent_commits[@]}")
77+
if [ -n "$sync_commit" ]; then
78+
found=false
79+
for c in "${recent_commits[@]}"; do
80+
if [ "$c" = "$sync_commit" ]; then
81+
found=true
82+
break
83+
fi
84+
done
85+
if [ "$found" = false ]; then
86+
keep_commits+=("$sync_commit")
87+
fi
88+
fi
89+
90+
echo "Rebuilding trimmed branch from kept commits (no extra commits)..."
91+
ORIG_HEAD=$(git rev-parse HEAD)
92+
LAST_COMMIT=""
93+
for c in $(printf "%s\n" "${keep_commits[@]}" | tac); do
94+
echo "Processing commit $c ..."
95+
git checkout -- . || true
96+
git checkout "$c" -- . || true
97+
git add -A || true
98+
TREE_ID=$(git write-tree)
99+
AUTHOR_NAME=$(git show -s --format='%an' $c)
100+
AUTHOR_EMAIL=$(git show -s --format='%ae' $c)
101+
COMMIT_DATE=$(git show -s --format='%ad' --date=iso-strict $c)
102+
COMMIT_MSG=$(git log --format=%B -n 1 $c)
103+
echo "Commit message for $c:"
104+
printf "%s\n" "$COMMIT_MSG"
105+
106+
MSG_FILE=$(mktemp)
107+
printf "%s\n" "$COMMIT_MSG" > "$MSG_FILE"
108+
109+
if [ -z "$LAST_COMMIT" ]; then
110+
NEW_COMMIT=$(GIT_AUTHOR_NAME="$AUTHOR_NAME" GIT_AUTHOR_EMAIL="$AUTHOR_EMAIL" GIT_AUTHOR_DATE="$COMMIT_DATE" git commit-tree $TREE_ID -F "$MSG_FILE")
111+
else
112+
NEW_COMMIT=$(GIT_AUTHOR_NAME="$AUTHOR_NAME" GIT_AUTHOR_EMAIL="$AUTHOR_EMAIL" GIT_AUTHOR_DATE="$COMMIT_DATE" git commit-tree $TREE_ID -p "$LAST_COMMIT" -F "$MSG_FILE")
113+
fi
114+
rm -f "$MSG_FILE"
115+
LAST_COMMIT=$NEW_COMMIT
116+
done
117+
118+
if [ -n "$LAST_COMMIT" ]; then
119+
git update-ref refs/heads/__tmp_history_trim $LAST_COMMIT
120+
echo "Built commit: $LAST_COMMIT"
121+
122+
if [ -n "${GITHUB_TOKEN:-}" ]; then
123+
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/vernesong/OpenClash.git"
124+
fi
125+
126+
git push --force --quiet origin "$LAST_COMMIT:refs/heads/${BRANCH}" || true
127+
echo "Trim complete. New commit count (remote unchanged locally until fetched): $(git rev-list --count HEAD)"
128+
else
129+
echo "No kept commits; skipping trim." >&2
130+
fi
131+
132+
cd ..
133+
rm -rf full_clone_tmp

luci-app-openclash/root/usr/share/openclash/yml_rules_change.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ yml_other_set()
272272
begin
273273
provider_configs = {'proxy-providers' => 'proxy_provider', 'rule-providers' => 'rule_provider'};
274274
provider_configs.each do |provider_type, path_prefix|
275-
if Value.key?(provider_type) then
275+
if Value.key?(provider_type) && Value[provider_type].is_a?(Hash) then
276276
Value[provider_type].each{|name, config|
277277
threads << Thread.new {
278278
if config['path'] and not config['path'] =~ /.\/#{path_prefix}\/*/ then
@@ -310,7 +310,7 @@ yml_other_set()
310310
311311
# tolerance
312312
begin
313-
if '$tolerance' != '0' and Value.key?('proxy-groups') then
313+
if '$tolerance' != '0' and Value.key?('proxy-groups') and Value['proxy-groups'].is_a?(Array) then
314314
Value['proxy-groups'].each{|group|
315315
threads << Thread.new {
316316
if group['type'] == 'url-test' then
@@ -326,7 +326,7 @@ yml_other_set()
326326
# URL-Test interval
327327
begin
328328
if '$urltest_interval_mod' != '0' then
329-
if Value.key?('proxy-groups') then
329+
if Value.key?('proxy-groups') and Value['proxy-groups'].is_a?(Array) then
330330
Value['proxy-groups'].each{|group|
331331
threads << Thread.new {
332332
if ['url-test', 'fallback', 'load-balance', 'smart'].include?(group['type']) then
@@ -361,7 +361,7 @@ yml_other_set()
361361
};
362362
};
363363
end;
364-
if Value.key?('proxy-groups') then
364+
if Value.key?('proxy-groups') and Value['proxy-groups'].is_a?(Array) then
365365
Value['proxy-groups'].each{|group|
366366
threads << Thread.new {
367367
if ['url-test', 'fallback', 'load-balance', 'smart'].include?(group['type']) then
@@ -377,7 +377,7 @@ yml_other_set()
377377
378378
# smart auto switch
379379
begin
380-
if ('${8}' == '1' or '${9}' == '1' or '${11}' != '0' or '${12}' != '0' or '${12}' == '1' or '${13}' == '1') and Value.key?('proxy-groups') then
380+
if ('${8}' == '1' or '${9}' == '1' or '${11}' != '0' or '${12}' != '0' or '${12}' == '1' or '${13}' == '1') and Value.key?('proxy-groups') and Value['proxy-groups'].is_a?(Array) then
381381
Value['proxy-groups'].each{|group|
382382
threads << Thread.new {
383383
if '${8}' == '1' and ['url-test', 'load-balance'].include?(group['type']) then

0 commit comments

Comments
 (0)