diff --git a/Makefile b/Makefile index 688c6c81..af0d9a58 100644 --- a/Makefile +++ b/Makefile @@ -34,4 +34,23 @@ lint:: --path-prefix $(pkg)) \ &&) true +# Publish SDKs to NuGet +publish-sdks:: + @echo "Publishing Pulumi SDKs to NuGet" + @if [ -z "$$NUGET_PUBLISH_KEY" ]; then echo "Missing NUGET_PUBLISH_KEY" && exit 1; fi + @if [ -z "$$PULUMI_VERSION" ]; then echo "Missing PULUMI_VERSION" && exit 1; fi + $(eval SDK_VERSION := $(shell cd pulumi-language-dotnet && grep -oP 'github.com/pulumi/pulumi/sdk/v3 v\K[0-9.]+' go.mod)) + for project in Pulumi Pulumi.Automation Pulumi.FSharp; do \ + PKG_EXISTS=$$(curl -s "https://api.nuget.org/v3-flatcontainer/$$project/index.json" | jq -e ".versions | index(\"$$PULUMI_VERSION\")" > /dev/null 2>&1 && echo yes || echo no); \ + if [ "$$PKG_EXISTS" = "yes" ]; then \ + echo "$$project $$PULUMI_VERSION already published, skipping"; \ + else \ + echo "Publishing $$project $$PULUMI_VERSION"; \ + cd sdk/$$project && dotnet build --configuration Release -p:Version=$$PULUMI_VERSION -p:PulumiSdkVersion=$(SDK_VERSION); \ + PKG_FILE=$$(ls bin/Release/*.nupkg | head -n1); \ + dotnet nuget push $$PKG_FILE -s https://api.nuget.org/v3/index.json -k $$NUGET_PUBLISH_KEY; \ + cd -; \ + fi; \ + done + .PHONY: install build diff --git a/build/Nuget.fs b/build/Nuget.fs deleted file mode 100644 index 7b7aa0f8..00000000 --- a/build/Nuget.fs +++ /dev/null @@ -1,38 +0,0 @@ -module Nuget - -open Newtonsoft.Json.Linq -open System.Net.Http - -let httpClient = new HttpClient() - -let packageDataContainsVersion (packageData: JObject) (version: string) = - if packageData.ContainsKey "versions" && packageData["versions"].Type = JTokenType.Array then - let versions = packageData["versions"] :?> JArray - versions - |> Seq.cast - |> Seq.exists (fun ver -> ver.ContainsKey "version" && ver["version"].ToObject() = version) - else - false - -/// Checks whether a nuget package is already published with the specified version -let exists (package: string) (version: string) = - let searchResults = - httpClient.GetStringAsync($"https://azuresearch-usnc.nuget.org/query?q={package}") - |> Async.AwaitTask - |> Async.RunSynchronously - |> JObject.Parse - - if not (searchResults.ContainsKey "data") || searchResults["data"].Type <> JTokenType.Array then - false - else - - let data = searchResults["data"] :?> JArray - - data - |> Seq.cast - |> Seq.exists (fun packageData -> - if packageData.ContainsKey "id" && packageData["id"].ToObject() = package - then packageDataContainsVersion packageData version - else false - ) - \ No newline at end of file diff --git a/build/Program.fs b/build/Program.fs index a9f9d426..f6043554 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -107,37 +107,11 @@ let buildSdk() = /// When publishing, we check whether the package we are about to publish already exists on Nuget /// and if that is the case, we skip it. let publishSdks() = - // prepare - cleanSdk() - restoreSdk() - let projectDirs = [ - pulumiSdk; - pulumiAutomationSdk; - pulumiFSharp; - ] - // perform the publishing (idempotent) - let publishResults = publishSdks projectDirs pulumiLanguageDotnet - - match publishResults with - | Error errorMsg -> printfn $"{errorMsg}" - | Ok results -> - for result in results do - match result with - | PublishResult.Ok project -> - printfn $"Project '{projectName project}' has been published" - | PublishResult.Failed(project, error) -> - printfn $"Project '{projectName project}' failed to publish the nuget package: {error}" - | PublishResult.AlreadyPublished project -> - printfn $"Project '{projectName project}' has already been published" - - let anyProjectFailed = results |> List.exists (fun result -> result.HasErrored()) - if anyProjectFailed then - let failedProjectsAtPublishing = - results - |> List.where (fun result -> result.HasErrored()) - |> List.map (fun result -> result.ProjectName()) - - failwith $"Some nuget packages were not published: {failedProjectsAtPublishing}" + printfn "Deprecated: calling `make publish-sdks` instead" + let cmd = Cli.Wrap("make").WithArguments("publish-sdks").WithWorkingDirectory(repositoryRoot) + let output = cmd.ExecuteAsync().GetAwaiter().GetResult() + if output.ExitCode <> 0 then + failwith "publish-sdks failed" let cleanLanguagePlugin() = let plugin = Path.Combine(pulumiLanguageDotnet, "pulumi-language-dotnet")