Migrate to GitHub CI workflow #8
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: CI | |
| on: | |
| push: | |
| branches: [ master ] | |
| tags: [ 'v*' ] | |
| paths-ignore: | |
| - '*.md' | |
| - '*.txt' | |
| - '.git*' | |
| pull_request: | |
| branches: [ master ] | |
| paths-ignore: | |
| - '*.md' | |
| - '*.txt' | |
| - '.git*' | |
| env: | |
| CONFIGURATION: Release | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| jobs: | |
| build: | |
| strategy: | |
| matrix: | |
| os: [windows-2022, ubuntu-22.04] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: global.json | |
| dotnet-version: '6.0.x' | |
| - name: Display .NET info | |
| run: dotnet --info | |
| - name: Restore tools | |
| run: dotnet tool restore | |
| - name: Build | |
| run: dotnet build --configuration ${{ env.CONFIGURATION }} | |
| - name: Pack (Windows only) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| $commitTimestamp = git log -1 --format=%cI | |
| if ($LASTEXITCODE) { throw "Failed to get commit timestamp" } | |
| $versionSuffix = ([datetimeoffset]$commitTimestamp).ToUniversalTime().ToString('yyyyMMdd''t''HHmm') | |
| $releaseNotesFile = [System.IO.Path]::GetTempFileName() | |
| $tag = '${{ github.ref_name }}' | |
| $isTag = '${{ github.ref_type }}' -eq 'tag' | |
| # if the tag starts with "v", as in "v1.0.0", assume it's a release | |
| if ($isTag -and $tag -clike 'v*') { | |
| $url = '${{ github.server_url }}/${{ github.repository }}' | |
| Add-Content $releaseNotesFile -Encoding UTF8 "See: ${url}/releases/tag/$tag" | |
| Add-Content $releaseNotesFile -Encoding UTF8 '' | |
| # if tag ends in "-" followed by dot-separated identifiers... | |
| if ($tag -match '(?<=-)[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$') { | |
| $versionSuffix = $matches[0] # ...then use as suffix for pre-release | |
| } else { | |
| $versionSuffix = $null # ... else use no suffix for a release | |
| } | |
| } | |
| Add-Content $releaseNotesFile -Encoding UTF8 "Commit @ ${{ github.sha }}" | |
| $packArgs = @() | |
| if ($versionSuffix) { | |
| $packArgs += @('--version-suffix', $versionSuffix) | |
| } | |
| dotnet pack --no-build --configuration ${{ env.CONFIGURATION }} @packArgs "-p:PackageReleaseNotesFile=$releaseNotesFile" | |
| if ($LASTEXITCODE) { throw "Pack failed" } | |
| Get-ChildItem -File -Filter docopt.net.*.nupkg dist | | |
| Select-Object -ExpandProperty FullName | | |
| ForEach-Object { dotnet sourcelink test $_; if ($LASTEXITCODE) { throw "SourceLink test failed for $_" } } | |
| - name: Test | |
| run: dotnet test --no-build --configuration ${{ env.CONFIGURATION }} | |
| - name: Integration Tests (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: ./tests/Integration/run.ps1 -NoPack | |
| - name: Integration Tests (Linux) | |
| if: runner.os == 'Linux' | |
| shell: pwsh | |
| run: ./tests/Integration/run.ps1 | |
| - name: Upload NuGet packages | |
| if: runner.os == 'Windows' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: NuGet | |
| path: dist/*.nupkg |