diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2acca9d6ed..ba89f9e58e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -159,3 +159,11 @@ stages: displayName: Build / Test env: TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) + +#---------------------------------------------------------------------------------------------------------------------# +# Package upload # +#---------------------------------------------------------------------------------------------------------------------# +- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - template: eng/upload/upload-packages.yml + parameters: + branchToUpload: refs/heads/master diff --git a/eng/upload/scripts/UploadPackages.ps1 b/eng/upload/scripts/UploadPackages.ps1 new file mode 100644 index 0000000000..727596867f --- /dev/null +++ b/eng/upload/scripts/UploadPackages.ps1 @@ -0,0 +1,41 @@ +[CmdletBinding(PositionalBinding=$false)] +param ( + [string]$apiKey, + [string]$feedUrl, + [string]$packagesDir +) + +Set-StrictMode -version 2.0 +$ErrorActionPreference = "Stop" + +try { + $packagePatterns = @( + "Microsoft.dotnet-interactive.*.nupkg", + "Microsoft.DotNet.Interactive.*.nupkg" # note that this also matches Microsoft.DotNet.Interactive.Formatting + ) + + $errors = 0 + foreach ($pattern in $packagePatterns) { + foreach ($packageName in (Get-Item "$packagesDir\$pattern")) { + $fullPath = $packageName.ToString() + Write-Host "Uploading package $fullPath." + $response = Invoke-WebRequest -Uri $feedUrl -Headers @{"X-NuGet-ApiKey"=$apiKey} -ContentType "multipart/form-data" -InFile "$fullPath" -Method Post -UseBasicParsing + if ($response.StatusCode -ne 201) { + Write-Host "Failed to upload package. Status code: $response.StatusCode." + $errors++ + } + else { + Write-Host "Done." + } + } + } + + exit $errors + +} +catch { + Write-Host $_ + Write-Host $_.Exception + Write-Host $_.ScriptStackTrace + exit 1 +} diff --git a/eng/upload/upload-packages.yml b/eng/upload/upload-packages.yml new file mode 100644 index 0000000000..d09e7000e6 --- /dev/null +++ b/eng/upload/upload-packages.yml @@ -0,0 +1,27 @@ +parameters: + branchToUpload: '' + +stages: +- stage: upload + dependsOn: build + displayName: Upload packages to MyGet + jobs: + - job: Upload_Packages + pool: + vmImage: windows-2019 + variables: + - group: dotnet-try-myget-api-keys + - name: FeedUrl + value: 'https://dotnet.myget.org/F/dotnet-try/api/v2/package' + steps: + - task: DownloadBuildArtifacts@0 + displayName: Download package artifacts + inputs: + buildType: current + artifactName: packages + - task: PowerShell@2 + displayName: Upload packages to MyGet + inputs: + filePath: $(Build.SourcesDirectory)/eng/upload/scripts/UploadPackages.ps1 + arguments: -apiKey $(MyGetAPIKey) -feedUrl $(FeedUrl) -packagesDir $(Build.ArtifactStagingDirectory)\packages\Shipping + condition: and(succeeded(), eq(variables['Build.SourceBranch'], '${{ parameters.branchToUpload }}'))