Repository navigation
feat: add automatic update downloads #11
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: ci | |
| on: | |
| push: | |
| branches: | |
| - master | |
| tags: | |
| - v*.*.* | |
| pull_request: | |
| permissions: | |
| contents: read | |
| jobs: | |
| verify: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: 10.0.203 | |
| cache: true | |
| cache-dependency-path: | | |
| global.json | |
| Directory.Packages.props | |
| CodexSwitch/CodexSwitch.csproj | |
| CodexSwitch.Tests/CodexSwitch.Tests.csproj | |
| - name: Validate changelog | |
| shell: pwsh | |
| run: ./build/Validate-Changelog.ps1 | |
| - name: Restore | |
| run: dotnet restore CodexSwitch.Tests/CodexSwitch.Tests.csproj | |
| - name: Build | |
| run: dotnet build CodexSwitch.Tests/CodexSwitch.Tests.csproj -c Release --no-restore | |
| - name: Test | |
| run: dotnet test CodexSwitch.Tests/CodexSwitch.Tests.csproj -c Release --no-build --no-restore --verbosity normal | |
| publish: | |
| needs: verify | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - runner: windows-latest | |
| rid: win-x64 | |
| - runner: ubuntu-latest | |
| rid: linux-x64 | |
| - runner: macos-14 | |
| rid: osx-arm64 | |
| - runner: macos-15-intel | |
| rid: osx-x64 | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: 10.0.203 | |
| cache: true | |
| cache-dependency-path: | | |
| global.json | |
| Directory.Packages.props | |
| CodexSwitch/CodexSwitch.csproj | |
| CodexSwitch.Tests/CodexSwitch.Tests.csproj | |
| - name: Read version | |
| id: version | |
| shell: pwsh | |
| run: | | |
| [xml]$props = Get-Content -LiteralPath "Directory.Build.props" | |
| $version = $props.Project.PropertyGroup.Version | |
| "value=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| - name: Publish ${{ matrix.rid }} | |
| run: > | |
| dotnet publish CodexSwitch/CodexSwitch.csproj | |
| -c Release | |
| -r ${{ matrix.rid }} | |
| --self-contained true | |
| -p:PublishAot=true | |
| -p:SelfContained=true | |
| -p:DebugType=none | |
| -p:DebugSymbols=false | |
| -o artifacts/publish/${{ matrix.rid }} | |
| - name: Install Windows packaging tools | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: choco install innosetup --yes --no-progress | |
| - name: Package installer | |
| id: package | |
| shell: pwsh | |
| run: | | |
| $version = "${{ steps.version.outputs.value }}" | |
| ./build/Package-ReleaseArtifact.ps1 ` | |
| -Version $version ` | |
| -RuntimeIdentifier "${{ matrix.rid }}" ` | |
| -PublishDirectory "artifacts/publish/${{ matrix.rid }}" ` | |
| -OutputDirectory "artifacts/package" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.package.outputs.name }} | |
| path: ${{ steps.package.outputs.path }} | |
| if-no-files-found: error | |
| release: | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: publish | |
| runs-on: windows-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Read version | |
| id: version | |
| shell: pwsh | |
| run: | | |
| [xml]$props = Get-Content -LiteralPath "Directory.Build.props" | |
| $version = $props.Project.PropertyGroup.Version | |
| $expectedTag = "v$version" | |
| if ($expectedTag -ne "${{ github.ref_name }}") { | |
| throw "Release tag '${{ github.ref_name }}' does not match Directory.Build.props version '$expectedTag'." | |
| } | |
| "value=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| - name: Download release artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: CodexSwitch-v${{ steps.version.outputs.value }}-* | |
| path: artifacts/release | |
| merge-multiple: true | |
| - name: Build release notes | |
| shell: pwsh | |
| run: | | |
| $version = "v${{ steps.version.outputs.value }}" | |
| $content = Get-Content -LiteralPath "CHANGELOG.md" -Raw | |
| $pattern = "(?s)## \[$([regex]::Escape($version))\].*?(?=\r?\n## \[v\d+\.\d+\.\d+\]|\z)" | |
| $match = [regex]::Match($content, $pattern) | |
| if (-not $match.Success) { | |
| throw "Unable to find changelog section for $version." | |
| } | |
| $match.Value | Out-File -LiteralPath "release-notes.md" -Encoding utf8 | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: ${{ github.ref_name }} | |
| body_path: release-notes.md | |
| files: artifacts/release/* | |
| fail_on_unmatched_files: true |