Added github workflows. #50
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: Validate And Package | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - "**" | |
| workflow_dispatch: | |
| concurrency: | |
| group: ci-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| env: | |
| BUILD_CONFIGURATION: Release | |
| jobs: | |
| build-test-package: | |
| if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/heads/') || github.event_name == 'workflow_dispatch' | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: global.json | |
| cache: true | |
| cache-dependency-path: | | |
| global.json | |
| Directory.Packages.props | |
| **/*.csproj | |
| - name: Restore | |
| run: dotnet restore CosmosDBShell.sln --configfile .github/nuget.github.config | |
| - name: Build solution | |
| run: dotnet build CosmosDBShell.sln --configuration $env:BUILD_CONFIGURATION --no-restore | |
| shell: pwsh | |
| - name: Test solution | |
| run: >- | |
| dotnet test CosmosDBShell.sln | |
| --configuration $env:BUILD_CONFIGURATION | |
| --no-build | |
| --no-restore | |
| --logger "trx;LogFileName=test-results.trx" | |
| --results-directory TestResults | |
| --collect "Code coverage" | |
| shell: pwsh | |
| - name: Run fuzzer smoke test | |
| working-directory: CosmosDBShell.Fuzzer | |
| run: dotnet run --configuration $env:BUILD_CONFIGURATION --no-build --no-restore -- --all | |
| shell: pwsh | |
| - name: Fail if fuzzer crash findings exist | |
| shell: pwsh | |
| run: | | |
| $crashes = Get-ChildItem -Path CosmosDBShell.Fuzzer/findings -Filter 'crash_*.txt' -ErrorAction SilentlyContinue | |
| if ($crashes -and $crashes.Count -gt 0) { | |
| Write-Error "Fuzzer recorded $($crashes.Count) crash(es). See the 'fuzz-findings' artifact for details." | |
| exit 1 | |
| } | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: TestResults | |
| if-no-files-found: ignore | |
| - name: Upload fuzzer findings | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: fuzz-findings | |
| path: CosmosDBShell.Fuzzer/findings | |
| if-no-files-found: ignore | |
| - name: Compute version properties | |
| if: github.event_name != 'pull_request' | |
| id: version | |
| shell: pwsh | |
| run: | | |
| $runNumber = [int]"${{ github.run_number }}" | |
| $assemblyVersion = "1.0.$runNumber" | |
| $branchName = "${{ github.ref_name }}" | |
| $branchLabel = $branchName.ToLowerInvariant() | |
| $branchLabel = $branchLabel -replace '[^0-9a-z-]', '-' | |
| $branchLabel = $branchLabel -replace '-+', '-' | |
| $branchLabel = $branchLabel.Trim('-') | |
| if ([string]::IsNullOrWhiteSpace($branchLabel)) { | |
| $branchLabel = 'branch' | |
| } | |
| if ($branchLabel.Length -gt 40) { | |
| $branchLabel = $branchLabel.Substring(0, 40).Trim('-') | |
| } | |
| $packageVersion = "$assemblyVersion-preview.$branchLabel" | |
| $fileVersion = "1.0.$runNumber.0" | |
| $infoVersion = "$packageVersion+${{ github.sha }}" | |
| "assembly_version=$assemblyVersion" >> $env:GITHUB_OUTPUT | |
| "package_version=$packageVersion" >> $env:GITHUB_OUTPUT | |
| "file_version=$fileVersion" >> $env:GITHUB_OUTPUT | |
| "informational_version=$infoVersion" >> $env:GITHUB_OUTPUT | |
| "branch_label=$branchLabel" >> $env:GITHUB_OUTPUT | |
| "artifact_suffix=$branchLabel-${{ github.run_number }}" >> $env:GITHUB_OUTPUT | |
| - name: Publish runtime artifacts | |
| if: github.event_name != 'pull_request' | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| $rids = @('win-x64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64') | |
| foreach ($rid in $rids) { | |
| dotnet restore CosmosDBShell/CosmosDBShell.csproj ` | |
| --configfile .github/nuget.github.config ` | |
| -r $rid | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "RID restore failed for $rid with exit code $LASTEXITCODE." | |
| } | |
| dotnet publish CosmosDBShell/CosmosDBShell.csproj ` | |
| --configuration $env:BUILD_CONFIGURATION ` | |
| --no-restore ` | |
| -r $rid ` | |
| --output "out/$rid" ` | |
| /p:Version=${{ steps.version.outputs.assembly_version }} ` | |
| /p:FileVersion=${{ steps.version.outputs.file_version }} ` | |
| /p:InformationalVersion=${{ steps.version.outputs.informational_version }} | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "RID publish failed for $rid with exit code $LASTEXITCODE." | |
| } | |
| } | |
| - name: Pack NuGet artifacts | |
| if: github.event_name != 'pull_request' | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Path out/nupkg -Force | Out-Null | |
| # Restore for all RIDs so pack can build packages for each | |
| dotnet restore CosmosDBShell/CosmosDBShell.csproj ` | |
| --configfile .github/nuget.github.config | |
| dotnet pack CosmosDBShell/CosmosDBShell.csproj ` | |
| --configuration $env:BUILD_CONFIGURATION ` | |
| --no-restore ` | |
| --output out/nupkg ` | |
| /p:PackageVersion=${{ steps.version.outputs.package_version }} ` | |
| /p:Version=${{ steps.version.outputs.assembly_version }} ` | |
| /p:FileVersion=${{ steps.version.outputs.file_version }} ` | |
| /p:InformationalVersion=${{ steps.version.outputs.informational_version }} ` | |
| /p:ContinuousIntegrationBuild=true | |
| - name: Validate NuGet package set | |
| if: github.event_name != 'pull_request' | |
| shell: pwsh | |
| run: | | |
| $pkgDir = Join-Path $pwd 'out/nupkg' | |
| $ridPatterns = @( | |
| 'CosmosDBShell.win-x64.*.nupkg', | |
| 'CosmosDBShell.linux-x64.*.nupkg', | |
| 'CosmosDBShell.linux-arm64.*.nupkg', | |
| 'CosmosDBShell.osx-x64.*.nupkg', | |
| 'CosmosDBShell.osx-arm64.*.nupkg' | |
| ) | |
| foreach ($pattern in $ridPatterns) { | |
| $matches = Get-ChildItem -Path (Join-Path $pkgDir $pattern) -ErrorAction SilentlyContinue | |
| if (-not $matches -or $matches.Count -eq 0) { | |
| Write-Error "Expected package was not generated: $pattern" | |
| exit 1 | |
| } | |
| } | |
| $allPackages = Get-ChildItem -Path (Join-Path $pkgDir 'CosmosDBShell.*.nupkg') -ErrorAction SilentlyContinue | |
| $pointerPackages = $allPackages | Where-Object { | |
| $_.Name -notmatch '^CosmosDBShell\.(win-x64|linux-x64|linux-arm64|osx-x64|osx-arm64)\..+\.nupkg$' | |
| } | |
| if (-not $pointerPackages -or $pointerPackages.Count -ne 1) { | |
| $names = @($pointerPackages | ForEach-Object { $_.Name }) | |
| Write-Error "Expected exactly one pointer package (non-RID). Found: $($names -join ', ')" | |
| exit 1 | |
| } | |
| $anyMatches = Get-ChildItem -Path (Join-Path $pkgDir 'CosmosDBShell.any.*.nupkg') -ErrorAction SilentlyContinue | |
| if ($anyMatches -and $anyMatches.Count -gt 0) { | |
| $names = $anyMatches | ForEach-Object { $_.Name } | Sort-Object | |
| Write-Error "Unexpected any-RID package(s) found: $($names -join ', ')" | |
| exit 1 | |
| } | |
| - name: List packaged NuGet files | |
| if: github.event_name != 'pull_request' | |
| shell: pwsh | |
| run: | | |
| Get-ChildItem -Path out/nupkg -Filter *.nupkg -File | Sort-Object Name | ForEach-Object { | |
| Write-Host " - $($_.Name) [$($_.Length) bytes]" | |
| } | |
| - name: Write package install summary | |
| if: github.event_name != 'pull_request' | |
| shell: pwsh | |
| run: | | |
| $summary = $env:GITHUB_STEP_SUMMARY | |
| $version = '${{ steps.version.outputs.package_version }}' | |
| $artifactSuffix = '${{ steps.version.outputs.artifact_suffix }}' | |
| $branchName = '${{ github.ref_name }}' | |
| $lines = @( | |
| '## NuGet packages', | |
| '', | |
| ('- Branch: `' + $branchName + '`'), | |
| ('- Preview version: `' + $version + '`'), | |
| '', | |
| 'Artifacts:', | |
| ('- `CosmosDBShell-pointer-' + $artifactSuffix + '`'), | |
| ('- `CosmosDBShell-win-x64-' + $artifactSuffix + '`'), | |
| ('- `CosmosDBShell-linux-x64-' + $artifactSuffix + '`'), | |
| ('- `CosmosDBShell-linux-arm64-' + $artifactSuffix + '`'), | |
| ('- `CosmosDBShell-osx-x64-' + $artifactSuffix + '`'), | |
| ('- `CosmosDBShell-osx-arm64-' + $artifactSuffix + '`'), | |
| '', | |
| 'Download the pointer package artifact and the artifact for your runtime, extract both `.nupkg` files to the same local folder, then install the base package:', | |
| '', | |
| '```powershell', | |
| 'dotnet tool install --global CosmosDBShell --add-source C:\path\to\nupkgs --version ' + $version, | |
| '```' | |
| ) | |
| $lines -join "`n" | Out-File -FilePath $summary -Encoding utf8 -Append | |
| - name: Upload pointer package | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: CosmosDBShell-pointer-${{ steps.version.outputs.artifact_suffix }} | |
| path: out/nupkg/CosmosDBShell.${{ steps.version.outputs.package_version }}.nupkg | |
| if-no-files-found: error | |
| - name: Upload win-x64 package | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: CosmosDBShell-win-x64-${{ steps.version.outputs.artifact_suffix }} | |
| path: out/nupkg/CosmosDBShell.win-x64.${{ steps.version.outputs.package_version }}.nupkg | |
| if-no-files-found: error | |
| - name: Upload linux-x64 package | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: CosmosDBShell-linux-x64-${{ steps.version.outputs.artifact_suffix }} | |
| path: out/nupkg/CosmosDBShell.linux-x64.${{ steps.version.outputs.package_version }}.nupkg | |
| if-no-files-found: error | |
| - name: Upload linux-arm64 package | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: CosmosDBShell-linux-arm64-${{ steps.version.outputs.artifact_suffix }} | |
| path: out/nupkg/CosmosDBShell.linux-arm64.${{ steps.version.outputs.package_version }}.nupkg | |
| if-no-files-found: error | |
| - name: Upload osx-x64 package | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: CosmosDBShell-osx-x64-${{ steps.version.outputs.artifact_suffix }} | |
| path: out/nupkg/CosmosDBShell.osx-x64.${{ steps.version.outputs.package_version }}.nupkg | |
| if-no-files-found: error | |
| - name: Upload osx-arm64 package | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: CosmosDBShell-osx-arm64-${{ steps.version.outputs.artifact_suffix }} | |
| path: out/nupkg/CosmosDBShell.osx-arm64.${{ steps.version.outputs.package_version }}.nupkg | |
| if-no-files-found: error |