Merge branch 'main' of https://github.com/Cosmos-0118/TidyWindow #82
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| defaults: | |
| run: | |
| working-directory: . | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-and-publish: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Derive release version | |
| shell: pwsh | |
| run: | | |
| $refName = $env:GITHUB_REF_NAME | |
| if ([string]::IsNullOrWhiteSpace($refName)) { | |
| throw "GITHUB_REF_NAME is not available." | |
| } | |
| $candidate = $refName.Split('/')[-1] | |
| if ($candidate.StartsWith('v')) { | |
| $candidate = $candidate.Substring(1) | |
| } | |
| if ($candidate -match '(?<version>\d+(?:\.\d+){1,3})') { | |
| $version = $Matches.version | |
| } else { | |
| $version = $candidate | |
| } | |
| Write-Host "Using release version $version" | |
| Add-Content -Path $env:GITHUB_ENV -Value "RELEASE_VERSION=$version" | |
| - name: Install .NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: "8.0.x" | |
| - name: Restore dependencies | |
| run: | | |
| dotnet restore src/TidyWindow.sln | |
| dotnet restore src/TidyWindow.App/TidyWindow.App.csproj --runtime win-x64 -p:PublishReadyToRun=true | |
| - name: Build solution | |
| shell: pwsh | |
| run: | | |
| if (-not $env:RELEASE_VERSION) { | |
| throw "RELEASE_VERSION is not set." | |
| } | |
| dotnet build src/TidyWindow.sln ` | |
| --configuration Release ` | |
| --no-restore ` | |
| /p:Version=$env:RELEASE_VERSION ` | |
| /p:FileVersion=$env:RELEASE_VERSION ` | |
| /p:InformationalVersion=$env:RELEASE_VERSION | |
| - name: Publish self-contained package | |
| shell: pwsh | |
| run: | | |
| if (-not $env:RELEASE_VERSION) { | |
| throw "RELEASE_VERSION is not set." | |
| } | |
| $repoRoot = $env:GITHUB_WORKSPACE | |
| if ([string]::IsNullOrWhiteSpace($repoRoot)) { | |
| throw "GITHUB_WORKSPACE is not available." | |
| } | |
| $publishDir = Join-Path $repoRoot "artifacts/publish/win-x64" | |
| dotnet publish src/TidyWindow.App/TidyWindow.App.csproj ` | |
| --configuration Release ` | |
| --runtime win-x64 ` | |
| --self-contained true ` | |
| --output $publishDir ` | |
| /p:PublishReadyToRun=true ` | |
| /p:DebugType=None ` | |
| /p:DebugSymbols=false ` | |
| --no-build ` | |
| /p:Version=$env:RELEASE_VERSION ` | |
| /p:FileVersion=$env:RELEASE_VERSION ` | |
| /p:InformationalVersion=$env:RELEASE_VERSION | |
| - name: Verify packaged automation assets | |
| shell: pwsh | |
| run: | | |
| $repoRoot = $env:GITHUB_WORKSPACE | |
| if ([string]::IsNullOrWhiteSpace($repoRoot)) { | |
| throw "GITHUB_WORKSPACE is not available." | |
| } | |
| $publishDir = Join-Path $repoRoot "artifacts/publish/win-x64" | |
| if (-not (Test-Path $publishDir)) { | |
| throw "Publish directory not found: $publishDir" | |
| } | |
| $assetRoots = @( | |
| @{ Source = Join-Path $repoRoot "automation"; Target = Join-Path $publishDir "automation"; Label = "automation" }, | |
| @{ Source = Join-Path $repoRoot "data"; Target = Join-Path $publishDir "data"; Label = "data" } | |
| ) | |
| $missing = [System.Collections.Generic.List[string]]::new() | |
| foreach ($spec in $assetRoots) { | |
| if (-not (Test-Path $spec.Source)) { | |
| throw "Source asset root missing: $($spec.Label)" | |
| } | |
| Get-ChildItem -Path $spec.Source -File -Recurse | ForEach-Object { | |
| $relative = [System.IO.Path]::GetRelativePath($spec.Source, $_.FullName) | |
| $targetPath = Join-Path $spec.Target $relative | |
| if (-not (Test-Path $targetPath)) { | |
| $normalized = ($relative -replace '\\', '/') | |
| $missing.Add("$($spec.Label)/$normalized") | Out-Null | |
| } | |
| } | |
| } | |
| if ($missing.Count -gt 0) { | |
| $details = $missing | ForEach-Object { " - $_" } | |
| throw "Missing packaged assets:`n$($details -join [Environment]::NewLine)" | |
| } | |
| - name: Prepare portable bundle | |
| shell: pwsh | |
| run: | | |
| $repoRoot = $env:GITHUB_WORKSPACE | |
| if ([string]::IsNullOrWhiteSpace($repoRoot)) { | |
| throw "GITHUB_WORKSPACE is not available." | |
| } | |
| $publishDir = Join-Path $repoRoot "artifacts/publish/win-x64" | |
| if (-not (Test-Path $publishDir)) { | |
| throw "Publish directory not found: $publishDir" | |
| } | |
| $versionTag = $env:RELEASE_VERSION | |
| $packageName = "TidyWindow-$versionTag-win-x64" | |
| $staging = "artifacts" | |
| New-Item -ItemType Directory -Force -Path $staging | Out-Null | |
| $portableDir = Join-Path $staging $packageName | |
| New-Item -ItemType Directory -Force -Path $portableDir | Out-Null | |
| Copy-Item -Path (Join-Path $publishDir '*') -Destination $portableDir -Recurse -Force | |
| $zipPath = Join-Path $staging "$packageName.zip" | |
| Compress-Archive -Path (Join-Path $portableDir '*') -DestinationPath $zipPath -Force | |
| Remove-Item $portableDir -Recurse -Force | |
| Get-ChildItem $staging | |
| - name: Install Inno Setup | |
| run: choco install innosetup --no-progress -y | |
| - name: Build installer | |
| shell: pwsh | |
| run: | | |
| $repoRoot = $env:GITHUB_WORKSPACE | |
| if ([string]::IsNullOrWhiteSpace($repoRoot)) { | |
| throw "GITHUB_WORKSPACE is not available." | |
| } | |
| $publishDir = (Resolve-Path (Join-Path $repoRoot "artifacts/publish/win-x64")).Path | |
| $version = $env:RELEASE_VERSION | |
| $iscc = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" | |
| if (-not (Test-Path $iscc)) { | |
| throw "ISCC.exe not found at $iscc" | |
| } | |
| & $iscc /Qp "/DMyAppVersion=$version" "/DBuildOutput=$publishDir" "installer\TidyWindowInstaller.iss" | |
| $outputDir = "installer\Output" | |
| if (Test-Path $outputDir) { | |
| Copy-Item "$outputDir\*.exe" "artifacts" -Force | |
| } else { | |
| throw "Installer output not found at $outputDir" | |
| } | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-packages | |
| path: artifacts/* | |
| - name: Publish GitHub release asset | |
| uses: softprops/action-gh-release@v2 | |
| if: startsWith(github.ref, 'refs/tags/') | |
| with: | |
| files: artifacts/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |