Skip to content

Commit 9aad4c0

Browse files
committed
fix: 尝试修复重复构建rag.exe, 加快构建速度
1 parent ec9ce68 commit 9aad4c0

File tree

1 file changed

+30
-46
lines changed

1 file changed

+30
-46
lines changed

.github/workflows/release.yml

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,42 @@ jobs:
1616

1717
# Calculate SHA256 and check if build is needed
1818
- name: Check if build is needed
19-
id: sha256
19+
id: check_build
2020
run: |
21-
Set-PSDebug -Trace 1
21+
$sourceFile = "src/python/rag.py"
22+
$md5File = "src.md5"
23+
24+
# 计算当前文件的MD5
25+
$currentMD5 = (Get-FileHash -Path $sourceFile -Algorithm MD5).Hash
26+
echo "Current MD5: $currentMD5"
27+
28+
# 尝试从最新release下载src.md5
2229
try {
23-
$sha256 = (Get-FileHash -Path src/python/rag.py -Algorithm SHA256).Hash
24-
echo "Current SHA256: $sha256"
25-
$previous_sha256 = "${{ github.event.before }}"
26-
echo "Previous SHA256: $previous_sha256"
27-
28-
if ($previous_sha256 -and $previous_sha256 -ne "0000000000000000000000000000000000000000") {
29-
$rag_path = "src/python/rag.py" -replace '\\', '/'
30-
echo "Checking if $rag_path exists in $previous_sha256"
31-
$file_exists = git cat-file -e "${previous_sha256}:$rag_path" 2>$null
32-
$check_exit_code = $LASTEXITCODE
30+
$latestRelease = gh api repos/${{ github.repository }}/releases/latest --jq '.assets[] | select(.name == "src.md5")'
31+
if ($latestRelease) {
32+
$downloadUrl = $latestRelease.browser_download_url
33+
echo "Downloading src.md5 from latest release: $downloadUrl"
34+
Invoke-WebRequest -Uri $downloadUrl -OutFile $md5File -ErrorAction Stop
3335

34-
if ($check_exit_code -eq 0) {
35-
$previous_content = git show "${previous_sha256}:$rag_path" -- 2>&1
36-
$git_exit_code = $LASTEXITCODE
37-
$LASTEXITCODE = 0
38-
echo "Git show exit code: $git_exit_code"
39-
echo "Git show output: $previous_content"
40-
41-
if ($previous_content -and $git_exit_code -eq 0) {
42-
$tempFile = Join-Path $PWD "temp_rag.py"
43-
echo $previous_content | Out-File $tempFile -Encoding utf8NoBOM
44-
if (Test-Path $tempFile) {
45-
$previous_hash = (Get-FileHash -Path $tempFile -Algorithm SHA256).Hash
46-
echo "Previous SHA256: $previous_hash"
47-
if ($previous_hash -eq $sha256) {
48-
echo "No changes detected in rag.py, skipping build and release."
49-
exit 0
50-
} else {
51-
echo "Hash mismatch, proceeding with build."
52-
}
53-
} else {
54-
echo "Failed to create temp_rag.py"
55-
}
56-
} else {
57-
echo "Failed to retrieve previous content, proceeding with build."
58-
}
59-
} else {
60-
echo "src/python/rag.py does not exist in commit $previous_sha256, proceeding with build."
36+
$storedMD5 = Get-Content $md5File -ErrorAction Stop
37+
echo "Stored MD5: $storedMD5"
38+
39+
if ($currentMD5 -eq $storedMD5) {
40+
echo "::notice::Source file unchanged - skipping build"
41+
echo "build_needed=false" >> $env:GITHUB_OUTPUT
42+
exit 0
6143
}
62-
} else {
63-
echo "No valid previous SHA, proceeding with build."
6444
}
65-
echo "Building new rag.exe due to changes or no previous commit."
6645
} catch {
67-
echo "Error in hash comparison: $_"
68-
exit 1
69-
} finally {
70-
Remove-Item -Path temp_rag.py -Force -ErrorAction SilentlyContinue
46+
echo "::warning::Could not retrieve stored MD5 (first build?): $($_.Exception.Message)"
7147
}
48+
49+
echo "::notice::Source file changed or no previous MD5 found - proceeding with build"
50+
echo "build_needed=true" >> $env:GITHUB_OUTPUT
51+
52+
# 生成新的MD5文件供后续使用
53+
echo $currentMD5.ToLower() > $md5File
54+
echo "Generated new MD5 file"
7255
shell: pwsh
7356

7457
# Set up Python
@@ -131,6 +114,7 @@ jobs:
131114
files: |
132115
temp_dist/rag.exe
133116
temp_dist/md5.txt
117+
src.md5
134118
tag_name: latest
135119
name: Latest RAG Executable
136120
draft: false

0 commit comments

Comments
 (0)