-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (135 loc) · 6.65 KB
/
daily-hiddify.yml
File metadata and controls
164 lines (135 loc) · 6.65 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
# .github/workflows/daily-hiddify.yml
name: Daily HiddifyConfigsCLI
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
run:
runs-on: windows-latest
timeout-minutes: 80
steps:
# -------------------------------------------------
- name: 1. 拉取仓库
uses: actions/checkout@v4
# -------------------------------------------------
- name: 2. 运行 CLI(强检路径 + 验证输出)
id: run_exe
shell: pwsh
timeout-minutes: 70
run: |
# --- 明确 EXE 完整路径(基于 workspace) ---
$exeDir = Join-Path $env:GITHUB_WORKSPACE "HiddifyConfigsCLI/bin/Debug/net9.0"
$exe = Join-Path $exeDir "HiddifyConfigsCLI.exe"
Write-Host "预期 EXE Dir = $exeDir"
Write-Host "预期 EXE Path = $exe"
# --- 明确 valid_links 完整路径(基于 workspace) ---
$valid_linksDir = Join-Path $env:GITHUB_WORKSPACE "HiddifyConfigsCLI/valid_links"
Write-Host "预期 valid_links Dir = $valid_linksDir"
if (!(Test-Path $exe)) {
Write-Error "EXE 不存在: $exe"
exit 1
}
# 输入 URL(可按需替换)
# $input = "https://raw.githubusercontent.com/shinexus/LearnToProgram/refs/heads/master/HiddifyConfigsCLI/config/test_url.txt"
$input = "https://raw.githubusercontent.com/shinexus/LearnToProgram/refs/heads/master/HiddifyConfigsCLI/config/urls.txt"
# 输出 绝对路径
# $outputFile = Join-Path $exeDir "_test.txt"
# $outputFile = Join-Path $exeDir "valid_links.txt"
$outputFile = Join-Path $valid_linksDir "valid_links.txt"
# 参数数组
$params = @(
"--input", $input,
"--output", $outputFile,
"--max-lines", "100",
"--max-parts", "2",
"--timeout", "6",
"--parallel", "128",
"--http-timeout", "5"
)
# 显示运行前目录与 EXE 目录下文件(便于对比)
Write-Host "运行前当前目录: $(Get-Location)"
Write-Host "运行前列出 EXE 目录文件(省略):"
# Get-ChildItem -Path $exeDir -Force -ErrorAction SilentlyContinue | Select-Object Name, FullName, Length | Format-Table
# --- 用 Start-Process 确保 WorkingDirectory 不被重置,拿到进程对象以读取 ExitCode ---
Write-Host "使用 Start-Process 启动 EXE..."
$proc = Start-Process -FilePath $exe -WorkingDirectory $exeDir -ArgumentList $params -Wait -NoNewWindow -PassThru
Write-Host "Start-Process 返回 ExitCode: $($proc.ExitCode)"
if ($proc.ExitCode -ne 0) {
Write-Error "CLI 退出码非0: $($proc.ExitCode)"
exit $proc.ExitCode
}
# --- 运行后马上列出 workspace 与 exeDir 下的 valid_links* 并打印基本信息 ---
Write-Host "运行后当前目录: $(Get-Location)"
Write-Host "运行后:搜索 workspace 下所有 valid_links* 文件(FullName + Length)"
Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -Filter "valid_links*" -ErrorAction SilentlyContinue |
Select-Object FullName, Length | Format-Table
Write-Host "运行后:列出 valid_linksDir 目录下 valid_links*:"
Get-ChildItem -Path $valid_linksDir -Filter "valid_links*" -ErrorAction SilentlyContinue |
Select-Object Name, FullName, Length | Format-Table
# --- 如果找到了主文件,打印前 50 行和文件字节数以供核验 ---
$mainCandidates = Get-ChildItem -Path $valid_linksDir -Filter "valid_links_*.txt" -ErrorAction SilentlyContinue
if ($mainCandidates) {
foreach ($f in $mainCandidates) {
Write-Host "---- file: $($f.FullName) (Length=$($f.Length) bytes) ----"
Write-Host "前 50 行内容预览(省略):"
# Get-Content -Path $f.FullName -TotalCount 50 | ForEach-Object { Write-Host $_ }
Write-Host "---- End of preview ----"
}
} else {
Write-Host "未在 valid_linksDir 目录发现 valid_links 文件,尝试在 workspace 全局搜索。"
$global = Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -Filter "valid_links*" -ErrorAction SilentlyContinue
foreach ($g in $global) {
Write-Host "---- file: $($g.FullName) (Length=$($g.Length) bytes) ----"
Get-Content -Path $g.FullName -TotalCount 50 | ForEach-Object { Write-Host $_ }
Write-Host "---- End of preview ----"
}
}
Write-Host "Step 2 完成"
# -------------------------------------------------
- name: 调试:搜索 valid_links*
shell: pwsh
run: |
Write-Host "当前目录: $(Get-Location)"
Write-Host "workspace 搜索 valid_links*:"
Get-ChildItem -Recurse -Filter "valid_links*" |
Format-Table FullName, Length
# -------------------------------------------------
- name: 3. 上传产物
uses: actions/upload-artifact@v4
if: always()
with:
name: valid-links
path: HiddifyConfigsCLI/valid_links/valid_links*
retention-days: 7
if-no-files-found: warn
# -------------------------------------------------
- name: 4. 提交结果(自动 rebase)
if: always() && steps.run_exe.outcome == 'success'
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Set-Location $env:GITHUB_WORKSPACE
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
# 添加生成的文件
git add "HiddifyConfigsCLI/valid_links/valid_links*"
# 若无变化则退出
git diff --cached --quiet
if ($LASTEXITCODE -eq 0) {
Write-Host "文件无变化,跳过 commit"
exit 0
}
# 提交本地更改
git commit -m "Update valid_links"
# 获取远程分支名
$branch = "${{ github.ref }}" -replace '^refs/heads/',''
# 拉取远程更新并 rebase
git fetch origin
git rebase origin/$branch || git rebase --abort
# 推送到远程,安全覆盖本地 rebase 提交
git push origin HEAD:$branch --force-with-lease