Files
shuidrop_gui/.gitea/workflows/gui-version-release.yml
2025-10-11 16:30:01 +08:00

433 lines
14 KiB
YAML

name: GUI Version Release
on:
push:
branches: [ master, develop ] # 临时添加 develop 用于测试
jobs:
gui-version-release:
runs-on: windows
defaults:
run:
working-directory: E:\shuidrop_gui
steps:
# Step 1: Pull latest code
- name: Pull latest code
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Pulling latest code";
Write-Host "==========================================";
Write-Host "Working directory: $(Get-Location)";
Write-Host "Branch: ${{ github.ref_name }}";
Write-Host "Commit: ${{ github.sha }}";
Write-Host "";
git config core.autocrlf false;
git config core.longpaths true;
Write-Host "Fetching from origin...";
git fetch origin;
Write-Host "Checking out branch: ${{ github.ref_name }}";
git checkout ${{ github.ref_name }};
Write-Host "Pulling latest changes...";
git reset --hard origin/${{ github.ref_name }};
Write-Host "";
Write-Host "Current status:";
git log -1 --oneline;
Write-Host "==========================================";
# Step 2: Check Python environment
- name: Check Python environment
shell: powershell
run: |
Write-Host "Python version:"
try {
python --version
} catch {
Write-Host "Python not installed"
}
Write-Host "Pip version:"
try {
pip --version
} catch {
Write-Host "Pip not installed"
}
# Step 3: Install dependencies
- name: Install dependencies
shell: powershell
run: |
Write-Host "Installing psycopg2-binary..."
python -m pip install --upgrade pip
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to upgrade pip"
exit 1
}
pip install psycopg2-binary
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to install psycopg2-binary"
exit 1
}
Write-Host "Dependencies installed successfully"
# Step 4: Create GUI version record
- name: Create version record
id: create_version
shell: powershell
run: |
Write-Host "Starting GUI version release process..."
Write-Host "Commit hash: ${{ github.sha }}"
Write-Host "Commit author: ${{ github.actor }}"
Write-Host "Branch: ${{ github.ref_name }}"
# Retry mechanism: maximum 3 attempts
$SUCCESS = $false
for ($i = 1; $i -le 3; $i++) {
Write-Host "Attempt $i to create version record..."
python .gitea/scripts/gui_version_creator.py
if ($LASTEXITCODE -eq 0) {
Write-Host "Version record created successfully"
$SUCCESS = $true
break
} else {
Write-Host "Attempt $i failed"
if ($i -eq 3) {
Write-Host "All 3 attempts failed"
} else {
Write-Host "Waiting 5 seconds before retry..."
Start-Sleep -Seconds 5
}
}
}
if (-not $SUCCESS) {
Write-Host "Version creation failed"
exit 1
}
# Verify version was updated
if (Test-Path "config.py") {
$configContent = Get-Content "config.py" -Raw
if ($configContent -match 'APP_VERSION\s*=\s*"([\d.]+)"') {
$VERSION = $matches[1]
Write-Host "Version updated successfully: $VERSION"
}
}
env:
DB_HOST: 8.155.9.53
DB_NAME: ai_web
DB_USER: user_emKCAb
DB_PASSWORD: password_ee2iQ3
DB_PORT: 5400
# Step 4.5: Build production executable
- name: Build production executable
if: success()
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Step 4.5: Build production executable";
Write-Host "==========================================";
# Install Pillow for icon conversion
Write-Host "Installing Pillow for icon conversion...";
python -m pip install --upgrade pip;
python -m pip install Pillow;
# Verify Pillow installation
Write-Host "Verifying Pillow installation...";
python -c "from PIL import Image; print('Pillow version:', Image.__version__)";
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Pillow installation verification failed";
exit 1;
}
Write-Host "Pillow installed successfully";
Write-Host "";
python build_production.py;
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed";
exit 1;
}
Write-Host "Production build completed successfully";
Write-Host "";
# Step 4.6: Check or Install NSIS
- name: Check or Install NSIS
if: success()
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Step 4.6: Check or Install NSIS";
Write-Host "==========================================";
# Step 1: Check if NSIS is already installed
Write-Host "Checking if NSIS is already installed...";
$nsisPaths = @(
"C:\Program Files (x86)\NSIS",
"C:\Program Files\NSIS",
"C:\Tools\NSIS",
"$env:ProgramFiles\NSIS",
"$env:ProgramFiles(x86)\NSIS"
);
$nsisFound = $false;
$nsisPath = "";
foreach ($path in $nsisPaths) {
if (Test-Path $path) {
$makensisPath = Join-Path $path "makensis.exe";
if (Test-Path $makensisPath) {
$nsisPath = $path;
$nsisFound = $true;
Write-Host "Found NSIS at: $nsisPath";
break;
}
}
}
# Also check if makensis is in PATH
if (-not $nsisFound) {
$makensisInPath = Get-Command makensis -ErrorAction SilentlyContinue;
if ($makensisInPath) {
$nsisPath = Split-Path $makensisInPath.Source;
$nsisFound = $true;
Write-Host "Found makensis in PATH: $nsisPath";
}
}
if ($nsisFound) {
$env:Path = "$nsisPath;$env:Path";
Write-Host "Using existing NSIS installation";
& makensis /VERSION;
Write-Host "";
exit 0;
}
Write-Host "NSIS not found, attempting installation...";
Write-Host "";
# Step 2: Try Chocolatey
Write-Host "Method 1: Trying Chocolatey...";
$chocoInstalled = Get-Command choco -ErrorAction SilentlyContinue;
if ($chocoInstalled) {
try {
choco install nsis -y --no-progress --limit-output;
if ($LASTEXITCODE -eq 0) {
Start-Sleep -Seconds 3;
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User");
$nsisPath = "C:\Program Files (x86)\NSIS";
if (-not (Test-Path $nsisPath)) {
$nsisPath = "C:\Program Files\NSIS";
}
if (Test-Path (Join-Path $nsisPath "makensis.exe")) {
$env:Path = "$nsisPath;$env:Path";
& makensis /VERSION;
Write-Host "NSIS installed via Chocolatey";
Write-Host "";
exit 0;
}
}
} catch {
Write-Host "Chocolatey installation failed: $_";
}
} else {
Write-Host "Chocolatey not available";
}
# Step 3: Try winget (Windows Package Manager)
Write-Host "";
Write-Host "Method 2: Trying winget...";
$wingetInstalled = Get-Command winget -ErrorAction SilentlyContinue;
if ($wingetInstalled) {
try {
winget install --id=NSIS.NSIS -e --silent --accept-package-agreements --accept-source-agreements;
if ($LASTEXITCODE -eq 0) {
Start-Sleep -Seconds 3;
$nsisPath = "C:\Program Files (x86)\NSIS";
if (-not (Test-Path $nsisPath)) {
$nsisPath = "C:\Program Files\NSIS";
}
if (Test-Path (Join-Path $nsisPath "makensis.exe")) {
$env:Path = "$nsisPath;$env:Path";
& makensis /VERSION;
Write-Host "NSIS installed via winget";
Write-Host "";
exit 0;
}
}
} catch {
Write-Host "winget installation failed: $_";
}
} else {
Write-Host "winget not available";
}
# Step 4: Manual installation is not possible due to network restrictions
Write-Host "";
Write-Host "========================================";
Write-Host "ERROR: NSIS is not installed and automatic installation failed";
Write-Host "";
Write-Host "Please install NSIS manually on the CI/CD runner:";
Write-Host "1. Download from: https://nsis.sourceforge.io/Download";
Write-Host "2. Install to: C:\Program Files (x86)\NSIS";
Write-Host "3. Or use: choco install nsis";
Write-Host "4. Or use: winget install NSIS.NSIS";
Write-Host "========================================";
exit 1;
# Step 4.7: Build NSIS installer
- name: Build NSIS installer
if: success()
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Step 4.7: Build NSIS installer";
Write-Host "==========================================";
# Ensure NSIS is in PATH
$nsisPath = "C:\Program Files (x86)\NSIS";
if (-not (Test-Path $nsisPath)) {
$nsisPath = "C:\Program Files\NSIS";
}
$env:Path = "$nsisPath;$env:Path";
Write-Host "Using NSIS from: $nsisPath";
cd installer;
python build_installer.py;
if ($LASTEXITCODE -ne 0) {
Write-Host "Installer build failed";
exit 1;
}
$installers = Get-ChildItem -Path "output" -Filter "*.exe" -ErrorAction SilentlyContinue;
if (-not $installers -or $installers.Count -eq 0) {
Write-Host "No installer file found";
exit 1;
}
$installerName = $installers[0].Name;
$installerSize = [math]::Round($installers[0].Length / 1MB, 2);
Write-Host "Installer built successfully";
Write-Host " Filename: $installerName";
Write-Host " Size: $installerSize MB";
Write-Host "";
# Step 4.8: Upload installer to KS3
- name: Upload installer to KS3
if: success()
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Step 4.8: Upload installer to KS3";
Write-Host "==========================================";
pip install ks3 2>$null;
python .gitea/scripts/upload_installer_to_ks3.py;
if ($LASTEXITCODE -ne 0) {
Write-Host "KS3 upload failed, but version release continues";
Write-Host " You can manually upload the installer later";
} else {
Write-Host "Installer uploaded to KS3 successfully";
}
Write-Host "";
# Step 5: Commit version changes
- name: Commit version changes
if: success()
shell: powershell
run: |
Write-Host "Committing version changes...";
$VERSION = "";
if (Test-Path "config.py") {
$configContent = Get-Content "config.py" -Raw;
if ($configContent -match 'APP_VERSION\s*=\s*"([\d.]+)"') {
$VERSION = $matches[1];
Write-Host "New version: $VERSION";
}
}
git config user.name "Gitea Actions Bot";
git config user.email "bot@gitea.local";
Write-Host "Adding files...";
git add config.py;
git add version_history.json;
Write-Host "Checking changes...";
git status;
$hasChanges = git diff --staged --quiet;
if ($LASTEXITCODE -ne 0) {
$BRANCH = "${{ github.ref_name }}";
Write-Host "Committing to branch: $BRANCH";
git commit -m "[skip ci] Update version to v$VERSION";
Write-Host "Pulling latest changes before push...";
git pull --rebase origin $BRANCH;
if ($LASTEXITCODE -eq 0) {
Write-Host "Pushing changes...";
git push origin $BRANCH;
Write-Host "Changes committed and pushed";
} else {
Write-Host "Pull failed, trying force push...";
git push origin $BRANCH;
}
} else {
Write-Host "No changes to commit";
}
# Step 6: Display summary
- name: Display summary
if: always()
shell: powershell
run: |
$VERSION = "Unknown";
if (Test-Path "config.py") {
$configContent = Get-Content "config.py" -Raw;
if ($configContent -match 'APP_VERSION\s*=\s*"([\d.]+)"') {
$VERSION = $matches[1];
}
}
Write-Host "==========================================";
Write-Host "GUI Version Release Summary";
Write-Host "==========================================";
Write-Host "Author: ${{ github.actor }}";
Write-Host "Branch: ${{ github.ref_name }}";
Write-Host "Version: $VERSION";
Write-Host "Time: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')";
Write-Host "Commit: ${{ github.sha }}";
Write-Host "==========================================";