name: GUI Version Release on: push: branches: [ master, develop ] # 临时添加 develop 用于测试 jobs: gui-version-release: runs-on: windows steps: # Step 1: Checkout repository (使用 Gitea 自动检出,适配所有路径) - name: Checkout repository uses: actions/checkout@v3 with: ref: ${{ github.ref_name }} # 动态分支(master 或 develop) fetch-depth: 0 # 获取完整历史(用于版本号计算) # Step 1.5: Verify checkout - name: Verify checkout shell: powershell run: | Write-Host "==========================================" Write-Host "Repository Information" Write-Host "==========================================" Write-Host "Current directory: $(Get-Location)" Write-Host "Branch: ${{ github.ref_name }}" Write-Host "Commit: ${{ github.sha }}" Write-Host "Author: ${{ github.actor }}" Write-Host "" Write-Host "Git status:" git status 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 5: Commit changes back to repository - name: Commit version changes if: success() shell: powershell run: | Write-Host "Committing version changes..." # Read version from config.py $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 用户(自动化提交) git config user.name "Gitea Actions Bot" git config user.email "bot@gitea.local" # 添加修改的文件 git add config.py git add version_history.json # 检查是否有变更 $hasChanges = git diff --staged --quiet if ($LASTEXITCODE -ne 0) { # 动态获取当前分支名(兼容 master 和 develop) $BRANCH = "${{ github.ref_name }}" Write-Host "Committing to branch: $BRANCH" git commit -m "[skip ci] Update version to v$VERSION" git push origin $BRANCH Write-Host "Version changes committed and pushed to $BRANCH" } else { Write-Host "No changes to commit" } # Step 6: Display summary - name: Display summary if: always() shell: powershell run: | # Read version from config.py $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 "=========================================="