|
| 1 | +name: Package Unsigned Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - v* |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: package-unsigned-${{ github.ref }} |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +env: |
| 17 | + BUILD_CONFIGURATION: Release |
| 18 | + |
| 19 | +jobs: |
| 20 | + package: |
| 21 | + runs-on: windows-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Setup .NET SDK |
| 28 | + uses: actions/setup-dotnet@v4 |
| 29 | + with: |
| 30 | + global-json-file: global.json |
| 31 | + cache: true |
| 32 | + cache-dependency-path: | |
| 33 | + global.json |
| 34 | + Directory.Packages.props |
| 35 | + **/*.csproj |
| 36 | +
|
| 37 | + - name: Compute version properties |
| 38 | + id: version |
| 39 | + shell: pwsh |
| 40 | + run: | |
| 41 | + $version = "1.0.${{ github.run_number }}" |
| 42 | + if ("${{ github.ref_type }}" -eq "tag") { |
| 43 | + $version = "${{ github.ref_name }}" |
| 44 | + if ($version.StartsWith('v')) { |
| 45 | + $version = $version.Substring(1) |
| 46 | + } |
| 47 | + } |
| 48 | +
|
| 49 | + $parts = $version.Split('.') |
| 50 | + if ($parts.Count -eq 2) { |
| 51 | + $fileVersion = "$version.${{ github.run_number }}.0" |
| 52 | + } elseif ($parts.Count -eq 3) { |
| 53 | + $fileVersion = "$version.${{ github.run_number }}" |
| 54 | + } elseif ($parts.Count -ge 4) { |
| 55 | + $fileVersion = ($parts[0..3] -join '.') |
| 56 | + } else { |
| 57 | + $fileVersion = "1.0.${{ github.run_number }}.0" |
| 58 | + } |
| 59 | +
|
| 60 | + $infoVersion = "$version+${{ github.sha }}" |
| 61 | +
|
| 62 | + "package_version=$version" >> $env:GITHUB_OUTPUT |
| 63 | + "file_version=$fileVersion" >> $env:GITHUB_OUTPUT |
| 64 | + "informational_version=$infoVersion" >> $env:GITHUB_OUTPUT |
| 65 | +
|
| 66 | + - name: Restore |
| 67 | + run: dotnet restore CosmosDBShell.sln |
| 68 | + |
| 69 | + - name: Build solution |
| 70 | + run: dotnet build CosmosDBShell.sln --configuration $env:BUILD_CONFIGURATION --no-restore |
| 71 | + shell: pwsh |
| 72 | + |
| 73 | + - name: Test solution |
| 74 | + run: >- |
| 75 | + dotnet test CosmosDBShell.sln |
| 76 | + --configuration $env:BUILD_CONFIGURATION |
| 77 | + --no-build |
| 78 | + --no-restore |
| 79 | + --logger "trx;LogFileName=test-results.trx" |
| 80 | + --results-directory TestResults |
| 81 | + --collect "Code coverage" |
| 82 | + shell: pwsh |
| 83 | + |
| 84 | + - name: Publish runtime artifacts |
| 85 | + shell: pwsh |
| 86 | + run: | |
| 87 | + $rids = @('win-x64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64') |
| 88 | + foreach ($rid in $rids) { |
| 89 | + dotnet publish CosmosDBShell/CosmosDBShell.csproj ` |
| 90 | + --configuration $env:BUILD_CONFIGURATION ` |
| 91 | + --no-restore ` |
| 92 | + -r $rid ` |
| 93 | + --output "out/$rid" ` |
| 94 | + /p:Version=${{ steps.version.outputs.package_version }} ` |
| 95 | + /p:FileVersion=${{ steps.version.outputs.file_version }} ` |
| 96 | + /p:InformationalVersion=${{ steps.version.outputs.informational_version }} |
| 97 | + } |
| 98 | +
|
| 99 | + - name: Pack unsigned NuGet artifacts |
| 100 | + shell: pwsh |
| 101 | + run: | |
| 102 | + New-Item -ItemType Directory -Path out/nupkg -Force | Out-Null |
| 103 | + dotnet pack CosmosDBShell/CosmosDBShell.csproj ` |
| 104 | + --configuration $env:BUILD_CONFIGURATION ` |
| 105 | + --no-build ` |
| 106 | + --no-restore ` |
| 107 | + --output out/nupkg ` |
| 108 | + /p:PackageVersion=${{ steps.version.outputs.package_version }} ` |
| 109 | + /p:ContinuousIntegrationBuild=true |
| 110 | +
|
| 111 | + - name: Validate NuGet package set |
| 112 | + shell: pwsh |
| 113 | + run: | |
| 114 | + $pkgDir = Join-Path $pwd 'out/nupkg' |
| 115 | + $ridPatterns = @( |
| 116 | + 'CosmosDBShell.win-x64.*.nupkg', |
| 117 | + 'CosmosDBShell.linux-x64.*.nupkg', |
| 118 | + 'CosmosDBShell.linux-arm64.*.nupkg', |
| 119 | + 'CosmosDBShell.osx-x64.*.nupkg', |
| 120 | + 'CosmosDBShell.osx-arm64.*.nupkg' |
| 121 | + ) |
| 122 | +
|
| 123 | + foreach ($pattern in $ridPatterns) { |
| 124 | + $matches = Get-ChildItem -Path (Join-Path $pkgDir $pattern) -ErrorAction SilentlyContinue |
| 125 | + if (-not $matches -or $matches.Count -eq 0) { |
| 126 | + Write-Error "Expected package was not generated: $pattern" |
| 127 | + exit 1 |
| 128 | + } |
| 129 | + } |
| 130 | +
|
| 131 | + $allPackages = Get-ChildItem -Path (Join-Path $pkgDir 'CosmosDBShell.*.nupkg') -ErrorAction SilentlyContinue |
| 132 | + $pointerPackages = $allPackages | Where-Object { |
| 133 | + $_.Name -notmatch '^CosmosDBShell\.(win-x64|linux-x64|linux-arm64|osx-x64|osx-arm64)\..+\.nupkg$' |
| 134 | + } |
| 135 | +
|
| 136 | + if (-not $pointerPackages -or $pointerPackages.Count -ne 1) { |
| 137 | + $names = @($pointerPackages | ForEach-Object { $_.Name }) |
| 138 | + Write-Error "Expected exactly one pointer package (non-RID). Found: $($names -join ', ')" |
| 139 | + exit 1 |
| 140 | + } |
| 141 | +
|
| 142 | + - name: Upload unsigned artifacts |
| 143 | + uses: actions/upload-artifact@v4 |
| 144 | + with: |
| 145 | + name: unsigned-build-artifacts |
| 146 | + path: | |
| 147 | + out |
| 148 | + TestResults |
| 149 | + if-no-files-found: error |
0 commit comments