Skip to content

feat: 添加播放历史同步功能及相关描述 #88

feat: 添加播放历史同步功能及相关描述

feat: 添加播放历史同步功能及相关描述 #88

name: Build Backend EXE and Release
on:
push:
branches:
- main
tags:
- 'v*.*.*'
workflow_dispatch:
permissions:
contents: write
jobs:
build-and-release:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Resolve release tag and message
id: version
shell: pwsh
run: |
git fetch --tags --force
$latestMsg = git log -1 --pretty=%B | Out-String
$latestMsg = $latestMsg.TrimEnd()
if (-not $latestMsg) {
$latestMsg = "No commit message"
}
$releaseBody = "HKLHaoBin`n$latestMsg"
if ("${{ github.ref_type }}" -eq "tag") {
$tag = "${{ github.ref_name }}"
Write-Host "Tag trigger detected, use existing tag: $tag"
} else {
$tags = git tag --list "v*.*.*"
$versionTags = @()
foreach ($t in $tags) {
if ($t -match '^v(\d+)\.(\d+)\.(\d+)$') {
$versionTags += [PSCustomObject]@{
Tag = $t
Major = [int]$matches[1]
Minor = [int]$matches[2]
Patch = [int]$matches[3]
}
}
}
if ($versionTags.Count -eq 0) {
$tag = "v1.0.0"
} else {
$latest = $versionTags |
Sort-Object -Property @{Expression = 'Major'; Descending = $true}, @{Expression = 'Minor'; Descending = $true}, @{Expression = 'Patch'; Descending = $true} |
Select-Object -First 1
if ($latest.Minor -ge 9) {
$tag = "v$($latest.Major + 1).0.0"
} else {
$nextMinor = $latest.Minor + 1
$tag = "v$($latest.Major).$nextMinor.0"
}
}
Write-Host "Create and push new tag: $tag"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag $tag
git push origin $tag
}
"tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$delimiter = [guid]::NewGuid().ToString()
"release_body<<$delimiter" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$releaseBody | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$delimiter | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Inject version into backend.py and updater.py
shell: pwsh
run: |
$version = "${{ steps.version.outputs.tag }}".TrimStart('v')
$placeholder = 'APP_VERSION = "0.0.0-dev"'
$newLine = "APP_VERSION = ""$version"""
foreach ($target in @('.\backend.py', '.\updater.py')) {
$content = Get-Content $target -Raw
if (-not $content.Contains($placeholder)) {
Write-Error "Placeholder for version not found in $target"
exit 1
}
$content = $content.Replace($placeholder, $newLine)
Set-Content -Path $target -Value $content -Encoding UTF8
}
- name: Verify injected version in backend.py and updater.py
shell: pwsh
run: |
$version = "${{ steps.version.outputs.tag }}".TrimStart('v')
foreach ($target in @('.\backend.py', '.\updater.py')) {
$matches = Select-String -Path $target -Pattern '^APP_VERSION = "([^"]+)"' -AllMatches
if ($matches.Count -ne 1) {
Write-Error "Expected exactly one APP_VERSION assignment in $target, found $($matches.Count)"
exit 1
}
$value = $matches[0].Matches[0].Groups[1].Value
if ($value -ne $version) {
Write-Error "Injected version mismatch in $target. Expected $version, found $value"
exit 1
}
}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-backend.txt
pip install pyinstaller
- name: Build backend.exe
shell: pwsh
run: |
pyinstaller --noconfirm backend.spec
- name: Build updater.exe
shell: pwsh
run: |
pyinstaller --noconfirm --onefile --console ".\updater.py"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: backend-and-updater.exe
path: |
dist/backend.exe
dist/updater.exe
if-no-files-found: error
- name: Prepare release zip
shell: pwsh
run: |
New-Item -ItemType Directory -Path release -Force | Out-Null
New-Item -ItemType Directory -Path release/LyricSphere.exe -Force | Out-Null
Copy-Item dist/backend.exe release/LyricSphere.exe/backend.exe -Force
Copy-Item dist/updater.exe release/LyricSphere.exe/updater.exe -Force
Copy-Item templates release/LyricSphere.exe/templates -Recurse -Force
$staticDest = "release/LyricSphere.exe/static"
New-Item -ItemType Directory -Path $staticDest -Force | Out-Null
foreach ($dir in @('assets','public','icons','monaco')) {
if (Test-Path "static/$dir") {
Copy-Item "static/$dir" "$staticDest/$dir" -Recurse -Force
}
}
if (Test-Path LyricSphere.exe.zip) {
Remove-Item LyricSphere.exe.zip -Force
}
Compress-Archive -Path release/LyricSphere.exe/* -DestinationPath LyricSphere.exe.zip -Force
$hash = Get-FileHash -Algorithm SHA256 -Path LyricSphere.exe.zip
$hash.Hash | Out-File -FilePath LyricSphere.exe.zip.sha256 -Encoding ascii
- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: LyricSphere.exe
body: ${{ steps.version.outputs.release_body }}
files: |
LyricSphere.exe.zip
LyricSphere.exe.zip.sha256
fail_on_unmatched_files: true