diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..54f8524 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + pull_request: + branches: [main] + +# 同一个 PR 的新提交会取消上一次还在跑的检查。 +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + check: + name: Check (tests and release build) + runs-on: windows-latest + timeout-minutes: 60 + steps: + - name: Checkout repository + uses: actions/checkout@v7 + + - name: Set up Temurin JDK 21 + uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: '21' + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + + # 与 scripts/release.ps1 的测试范围一致(桌面 + Android 单元测试), + # 并额外构建一次 Release APK,提前暴露 R8/资源收缩问题。 + # PR 环境没有签名 Secrets,这里只验证能否构建(产物为未签名 APK)。 + - name: Run tests and build release APK + shell: pwsh + run: | + .\gradlew.bat --console=plain --stacktrace :composeApp:desktopTest :composeApp:testDebugUnitTest :composeApp:assembleRelease + exit $LASTEXITCODE diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d41fce8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,330 @@ +name: Release + +# 推送 vX.Y.Z tag 时自动打包并发布 GitHub Release。 +# 流程与 scripts/release.ps1 保持一致:单元测试 -> 签名 APK -> Compose 发布目录 -> Inno Setup 安装包。 +on: + push: + tags: ['v*'] + workflow_dispatch: + inputs: + tag: + description: 'Existing tag to package and publish, e.g. v2.1.1' + required: true + type: string + prerelease: + description: 'Mark the GitHub release as a pre-release' + required: false + type: boolean + default: false + model: + description: 'Model for the AI release-notes draft (defaults to repository variable RELEASE_NOTES_MODEL or deepseek-flash)' + required: false + type: string + effort: + description: 'Thinking effort for the AI draft: none/low/high/max (defaults to repository variable RELEASE_NOTES_EFFORT or high)' + required: false + type: string + +# 同一个版本不并发打包;失败后可以直接重跑整个工作流。 +concurrency: + group: release-${{ inputs.tag || github.ref_name }} + cancel-in-progress: false + +permissions: + contents: write + +jobs: + package: + name: Package and publish + runs-on: windows-latest + timeout-minutes: 120 + env: + RELEASE_TAG: ${{ inputs.tag || github.ref_name }} + PRERELEASE: ${{ inputs.prerelease }} + AI_MODEL: ${{ inputs.model || vars.RELEASE_NOTES_MODEL || 'deepseek-flash' }} + AI_EFFORT: ${{ inputs.effort || vars.RELEASE_NOTES_EFFORT || 'high' }} + NOTES_OUTPUT: release-notes-body.md + steps: + - name: Checkout repository + uses: actions/checkout@v7 + with: + ref: ${{ inputs.tag || github.ref }} + fetch-depth: 0 + + - name: Set up Temurin JDK 21 + uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: '21' + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + + # tag 必须是 vX.Y.Z,并且与 release.ps1 维护的三处版本声明完全一致。 + - name: Verify version metadata + shell: pwsh + run: | + $tag = $env:RELEASE_TAG + if ($tag -notmatch '^v(?\d+\.\d+\.\d+)$') { + throw "Release tag '$tag' must look like v..." + } + $version = $Matches.version + $targets = @( + @{ File = 'gradle/libs.versions.toml'; Pattern = '(?m)^app-version\s*=\s*"([^"]+)"\s*$' }, + @{ File = 'installer/VRCMC.iss'; Pattern = '(?m)^#define AppVersion\s+"([^"]+)"\s*$' }, + @{ File = 'composeApp/src/commonMain/kotlin/com/vrcmc/app/update/AppUpdate.kt'; Pattern = '(?m)^\s*const val VERSION\s*=\s*"([^"]+)"\s*$' } + ) + foreach ($target in $targets) { + $match = [regex]::Match((Get-Content -Raw -LiteralPath $target.File), $target.Pattern) + if (-not $match.Success) { throw "Version declaration not found in $($target.File)." } + if ($match.Groups[1].Value -ne $version) { + throw "$($target.File) declares $($match.Groups[1].Value), but the tag is $tag." + } + } + Add-Content -Path $env:GITHUB_ENV -Value "VERSION=$version" + Write-Host "Version metadata matches $tag." + + # 签名材料从仓库 Secrets 注入,工作区内不留任何已提交的密钥。 + - name: Prepare Android signing + shell: pwsh + env: + ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} + ANDROID_STORE_PASSWORD: ${{ secrets.ANDROID_STORE_PASSWORD }} + ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} + ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }} + run: | + $missing = @('ANDROID_KEYSTORE_BASE64', 'ANDROID_STORE_PASSWORD', 'ANDROID_KEY_ALIAS', 'ANDROID_KEY_PASSWORD') | + Where-Object { [string]::IsNullOrWhiteSpace([Environment]::GetEnvironmentVariable($_)) } + if ($missing) { + throw "Missing repository secrets: $($missing -join ', '). Configure them under Settings -> Secrets and variables -> Actions." + } + [IO.File]::WriteAllBytes('vrcmc-release.jks', [Convert]::FromBase64String($env:ANDROID_KEYSTORE_BASE64)) + [IO.File]::WriteAllLines('local.properties', @( + 'store_file=vrcmc-release.jks' + "store_pass=$env:ANDROID_STORE_PASSWORD" + "key_alias=$env:ANDROID_KEY_ALIAS" + "key_pass=$env:ANDROID_KEY_PASSWORD" + )) + Write-Host 'Android signing configuration prepared.' + + - name: Run unit tests + shell: pwsh + run: | + .\gradlew.bat --console=plain --stacktrace :composeApp:desktopTest :composeApp:testDebugUnitTest + exit $LASTEXITCODE + + - name: Build signed release APK + shell: pwsh + run: | + .\gradlew.bat --console=plain --stacktrace :composeApp:assembleRelease + exit $LASTEXITCODE + + - name: Build Windows application directory + shell: pwsh + run: | + .\gradlew.bat --console=plain --stacktrace :composeApp:createReleaseDistributable + exit $LASTEXITCODE + + # windows-latest 镜像自带 Inno Setup 6;若将来镜像移除则回退到 Chocolatey 安装。 + - name: Locate Inno Setup compiler + shell: pwsh + run: | + $candidates = @( + (Get-Command ISCC.exe -ErrorAction SilentlyContinue).Source + "$env:ProgramFiles\Inno Setup 6\ISCC.exe" + "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe" + "$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe" + ) + $iscc = $candidates | Where-Object { $_ -and (Test-Path -LiteralPath $_) } | Select-Object -First 1 + if (-not $iscc) { + Write-Host 'ISCC.exe not found; installing Inno Setup with Chocolatey...' + choco install innosetup --yes --no-progress + $iscc = @( + "$env:ProgramFiles\Inno Setup 6\ISCC.exe" + "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe" + ) | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1 + } + if (-not $iscc) { throw 'ISCC.exe could not be located.' } + Add-Content -Path $env:GITHUB_ENV -Value "ISCC=$iscc" + Write-Host "Using Inno Setup compiler: $iscc" + + - name: Build Windows installer + shell: pwsh + run: | + & $env:ISCC 'installer\VRCMC.iss' + exit $LASTEXITCODE + + - name: Verify artifacts + shell: pwsh + run: | + $version = $env:VERSION + $artifacts = @( + "composeApp/build/outputs/apk/release/VRCMC-v$version.apk" + "composeApp/build/installer/VRCMC-v$version-setup.exe" + ) + foreach ($artifact in $artifacts) { + if (-not (Test-Path -LiteralPath $artifact)) { throw "Missing expected artifact: $artifact" } + $item = Get-Item -LiteralPath $artifact + $hash = (Get-FileHash -Algorithm SHA256 -LiteralPath $artifact).Hash + Write-Host ("{0} {1:N1} MB SHA256 {2}" -f $item.Name, ($item.Length / 1MB), $hash) + Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "- $($item.Name): $([math]::Round($item.Length / 1MB, 1)) MB, SHA256 $hash" + } + + # 公告优先级:release-notes/.md(完全手写)→ AI 双语草稿 → GitHub 自动汇总。 + - name: Prepare release notes + shell: pwsh + env: + GH_TOKEN: ${{ github.token }} + DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} + run: | + $ErrorActionPreference = 'Stop' + $tag = $env:RELEASE_TAG + $version = $env:VERSION + $output = $env:NOTES_OUTPUT + + $describe = git describe --tags --abbrev=0 "$tag^" 2>$null + $previousTag = '' + if ($LASTEXITCODE -eq 0 -and $describe) { $previousTag = (($describe | Select-Object -First 1)).Trim() } + + $manualFile = "release-notes/$tag.md" + if (Test-Path -LiteralPath $manualFile) { + Copy-Item -LiteralPath $manualFile -Destination $output -Force + Add-Content -Path $env:GITHUB_ENV -Value 'NOTES_MODE=manual' + Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "Release notes mode: **manual** (``$manualFile``)" + Write-Host "Using manual release notes from $manualFile." + exit 0 + } + + $draft = '' + if ($env:DEEPSEEK_API_KEY) { + if ($previousTag) { + $range = "$previousTag..$tag" + $commitLog = (git log --no-merges --pretty=format:'%h %s%n%b' $range) -join "`n" + $diffStat = (git diff --stat $range) -join "`n" + } else { + $commitLog = (git log -n 100 --no-merges --pretty=format:'%h %s%n%b' $tag) -join "`n" + $diffStat = '(no previous release tag)' + } + if ($commitLog.Length -gt 24000) { $commitLog = $commitLog.Substring(0, 24000) + "`n...(truncated)" } + if ($diffStat.Length -gt 8000) { $diffStat = $diffStat.Substring(0, 8000) + "`n...(truncated)" } + + $systemPrompt = @( + 'You are the release-notes writer for VRCMC, an open-source VRChat chatbox assistant built with Kotlin Multiplatform and Compose for Windows, Android and iOS.' + 'You write the update announcement that users see in the in-app update dialog and on the GitHub release page.' + 'Format rules:' + '- Write bilingually: Simplified Chinese first, then English.' + '- Use Markdown headings. Only if there are breaking changes, removed features or important user actions, open with "## 重要更新" followed by "## Important Update" (both kept short).' + '- Then write "## 更新内容" (Chinese) and "## What''s Changed" (English).' + '- Present user-visible changes, most important first: breaking changes, new features, behavior changes, notable fixes and performance improvements.' + '- Do not invent information. Do not mention internal refactors, CI, tests or dependency updates unless they have user-visible impact.' + '- Do not add download links, changelog links or a Downloads section; they are appended automatically.' + '- Keep each language under roughly 350 words unless the changes clearly need more.' + '- Tone: clear, calm product announcement.' + ) -join "`n" + + $previousLabel = if ($previousTag) { $previousTag } else { 'none' } + $userPrompt = @( + "Project: VRCMC. Release tag: $tag. Previous release tag: $previousLabel." + '' + 'Commit log since the previous release:' + $commitLog + '' + 'Diff stat:' + $diffStat + '' + 'Write the bilingual release announcement now, following the format rules.' + ) -join "`n" + + # DeepSeek:默认开启思考(high 档)提升公告质量;RELEASE_NOTES_EFFORT 可覆盖(none 关闭思考)。 + $effort = $env:AI_EFFORT + if ([string]::IsNullOrWhiteSpace($effort)) { $effort = 'high' } + $thinkingType = if ($effort -eq 'none') { 'disabled' } else { 'enabled' } + $payload = @{ + model = $env:AI_MODEL + thinking = @{ type = $thinkingType } + reasoning_effort = $effort + messages = @( + @{ role = 'system'; content = $systemPrompt } + @{ role = 'user'; content = $userPrompt } + ) + } | ConvertTo-Json -Depth 8 -Compress + $payloadBytes = [Text.Encoding]::UTF8.GetBytes($payload) + $headers = @{ Authorization = "Bearer $($env:DEEPSEEK_API_KEY)" } + + $base = if ($env:DEEPSEEK_API_BASE) { $env:DEEPSEEK_API_BASE.TrimEnd('/') } else { 'https://api.deepseek.com' } + $endpoints = @("$base/chat/completions") + if ($base -notmatch '/v1$') { $endpoints += "$base/v1/chat/completions" } + foreach ($endpoint in $endpoints) { + try { + $response = Invoke-RestMethod -Method Post -Uri $endpoint -Headers $headers -ContentType 'application/json' -Body $payloadBytes -TimeoutSec 300 + $draft = [string]$response.choices[0].message.content + if ($draft) { + Write-Host "AI release notes draft received from $endpoint." + break + } + Write-Warning "AI endpoint $endpoint returned an empty draft." + } catch { + Write-Warning "AI request to $endpoint failed: $($_.Exception.Message)" + } + } + } else { + Write-Host 'DEEPSEEK_API_KEY is not configured; skipping the AI draft.' + } + + if ($draft) { + $footer = @( + '## 下载 / Downloads' + "- Windows: ``VRCMC-v$version-setup.exe``" + "- Android: ``VRCMC-v$version.apk``" + ) + if ($previousTag) { + $footer += "[查看完整变更 / Full Changelog](https://github.com/$($env:GITHUB_REPOSITORY)/compare/$previousTag...$tag)" + } + $body = $draft.Trim() + "`n`n" + ($footer -join "`n") + "`n" + $mode = 'ai' + } else { + Write-Warning 'AI draft unavailable; falling back to GitHub generated notes.' + $arguments = @('api', "repos/$($env:GITHUB_REPOSITORY)/releases/generate-notes", '-f', "tag_name=$tag") + if ($previousTag) { $arguments += @('-f', "previous_tag_name=$previousTag") } + $body = (gh @arguments --jq .body) -join "`n" + if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($body)) { throw 'Failed to generate release notes.' } + $mode = 'generated' + } + + [IO.File]::WriteAllText($output, $body, (New-Object Text.UTF8Encoding($false))) + Add-Content -Path $env:GITHUB_ENV -Value "NOTES_MODE=$mode" + Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "Release notes mode: **$mode**" + Write-Host "Release notes prepared with mode '$mode' ($($body.Length) chars)." + + - name: Upload workflow artifacts + uses: actions/upload-artifact@v7 + with: + name: release-artifacts + path: | + composeApp/build/outputs/apk/release/*.apk + composeApp/build/installer/VRCMC-v*-setup.exe + release-notes-body.md + if-no-files-found: error + + # 已存在同名 Release(例如本地 release.ps1 已发布)时只更新附件,否则新建。 + - name: Publish GitHub release + shell: pwsh + env: + GH_TOKEN: ${{ github.token }} + run: | + $tag = $env:RELEASE_TAG + $assets = @( + "composeApp/build/outputs/apk/release/VRCMC-v$($env:VERSION).apk" + "composeApp/build/installer/VRCMC-v$($env:VERSION)-setup.exe" + ) + gh release view $tag *> $null + if ($LASTEXITCODE -eq 0) { + Write-Host "Release $tag already exists; updating assets." + gh release upload $tag $assets --clobber + if ($LASTEXITCODE -ne 0) { throw 'gh release upload failed.' } + } else { + $arguments = @('release', 'create', $tag, $assets, '--title', $tag, '--notes-file', $env:NOTES_OUTPUT, '--verify-tag') + if ($env:PRERELEASE -eq 'true') { $arguments += '--prerelease' } + gh @arguments + if ($LASTEXITCODE -ne 0) { throw 'gh release create failed.' } + } diff --git a/composeApp/src/desktopTest/kotlin/com/vrcmc/app/audio/SteamVrOverlayTextureTest.kt b/composeApp/src/desktopTest/kotlin/com/vrcmc/app/audio/SteamVrOverlayTextureTest.kt index 0e70c9a..97f9556 100644 --- a/composeApp/src/desktopTest/kotlin/com/vrcmc/app/audio/SteamVrOverlayTextureTest.kt +++ b/composeApp/src/desktopTest/kotlin/com/vrcmc/app/audio/SteamVrOverlayTextureTest.kt @@ -21,6 +21,11 @@ class SteamVrOverlayTextureTest { assumeTrue(Platform.isWindows()) val width = 16 val height = 12 + // GitHub-hosted runners have no GPU/OpenGL driver; skip there instead of failing. + assumeTrue( + "Requires a working OpenGL context", + runCatching { SteamVrOverlayTexture(width, height).use { } }.isSuccess, + ) val pixels = memAlloc(width * height * 4) val readback = memAlloc(pixels.capacity()) try {