@@ -11,34 +11,84 @@ jobs:
1111 steps :
1212 - name : Checkout code
1313 uses : actions/checkout@v4
14+ with :
15+ fetch-depth : 2 # Fetch previous commit for hash comparison
1416
17+ # Calculate SHA256 and check if build is needed
18+ - name : Check if build is needed
19+ id : sha256
20+ run : |
21+ $sha256 = (Get-FileHash -Path src/python/rag.py -Algorithm SHA256).Hash
22+ echo "Current SHA256: $sha256"
23+ $previous_sha256 = "${{ github.event.before }}"
24+ if ($previous_sha256) {
25+ $previous_content = git show $previous_sha256:src/python/rag.py 2>$null
26+ if ($?) {
27+ echo $previous_content | Out-File temp_rag.py
28+ $previous_hash = (Get-FileHash -Path temp_rag.py -Algorithm SHA256).Hash
29+ if ($previous_hash -eq $sha256) {
30+ echo "No changes detected in rag.py, skipping build and release."
31+ exit 0
32+ }
33+ }
34+ }
35+ echo "Building new rag.exe due to changes or no previous commit."
36+
37+ # Set up Python
1538 - name : Set up Python
1639 uses : actions/setup-python@v4
1740 with :
1841 python-version : ' 3.10'
1942
43+ # Install PyInstaller
2044 - name : Install PyInstaller
2145 run : pip install pyinstaller
2246
47+ # Install Python dependencies
2348 - name : Install Python dependencies
2449 run : pip install -r src/python/requirements.txt
2550
51+ # Build EXE to a temporary directory
2652 - name : Build EXE
27- run : pyinstaller --onefile --clean --distpath dist src/python/rag.py
53+ run : |
54+ mkdir temp_dist
55+ pyinstaller --onefile --clean --distpath temp_dist src/python/rag.py
56+ if ($LASTEXITCODE -ne 0) { throw "PyInstaller build failed" }
2857
58+ # Compress EXE with UPX
2959 - name : Compress EXE with UPX
3060 uses : crazy-max/ghaction-upx@v3
3161 with :
3262 version : latest
3363 files : |
34- dist /rag.exe
64+ temp_dist /rag.exe
3565 args : -fq --best
3666
37- - name : Upload EXE artifact
38- uses : actions/upload-artifact@v4
67+ # Create GitHub Release
68+ - name : Create GitHub Release
69+ uses : softprops/action-gh-release@v1
3970 with :
40- name : rag.exe
41- path : dist/rag.exe
71+ files : |
72+ temp_dist/rag.exe
73+ tag_name : v${{ github.run_number }}
74+ name : Release v${{ github.run_number }}
75+ draft : false
76+ prerelease : false
77+ env :
78+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
79+
80+ # Delete old releases
81+ - name : Delete old releases
82+ uses :
dev-drprasad/[email protected] 83+ with :
84+ keep_latest : 5
85+ env :
86+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
87+
88+ # Clean up temporary directory
89+ - name : Clean up temporary directory
90+ if : always()
91+ run : Remove-Item -Path temp_dist -Recurse -Force -ErrorAction SilentlyContinue
4292
4393 build-and-publish :
4494 runs-on : ubuntu-latest
0 commit comments