From d07553deb649202ff468bce7500223bb0fe8b60c Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Thu, 21 Dec 2023 19:54:53 +0800 Subject: [PATCH 1/2] CI,build.fsx: move some GitHubActions logic to FAKE logic This might be seen as illogical, because it is visibly much more code than before; however it has some added benefits: * It has a log that explains when a nuget push doesn't happen. * It avoids using GitHubActions specific syntax, which sometimes is tricky to get right (and so, less maintainable). * It improves a helper func to check for whitespace too. --- .github/workflows/build+test+publish.yml | 1 - build.fsx | 35 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build+test+publish.yml b/.github/workflows/build+test+publish.yml index 151df9f0c..bdf303999 100644 --- a/.github/workflows/build+test+publish.yml +++ b/.github/workflows/build+test+publish.yml @@ -64,7 +64,6 @@ jobs: env: nuget-key: ${{ secrets.NUGET_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: github.event_name == 'push' && env.nuget-key != null run: dotnet fake build -t Push - name: Create Release (if tag) if: startsWith(github.ref, 'refs/tags/') diff --git a/build.fsx b/build.fsx index 24916f262..bdb17c19a 100644 --- a/build.fsx +++ b/build.fsx @@ -45,7 +45,12 @@ let exec cmd args dir = |> Proc.run |> ignore -let getBuildParam = Environment.environVar +let getBuildParam var = + let value = Environment.environVar var + if String.IsNullOrWhiteSpace value then + None + else + Some value let DoNothing = ignore // -------------------------------------------------------------------------------------- @@ -163,11 +168,29 @@ Target.create "Pack" (fun _ -> ) Target.create "Push" (fun _ -> - let key = - match getBuildParam "nuget-key" with - | s when not (isNullOrWhiteSpace s) -> s - | _ -> UserInput.getUserPassword "NuGet Key: " - Paket.push (fun p -> { p with WorkingDir = nugetDir; ApiKey = key; ToolType = ToolType.CreateLocalTool() })) + let push key = + Paket.push (fun p -> { p with WorkingDir = nugetDir; ApiKey = key; ToolType = ToolType.CreateLocalTool() }) + + let key = getBuildParam "nuget-key" + match getBuildParam "GITHUB_EVENT_NAME" with + | None -> + match key with + | None -> + let key = UserInput.getUserPassword "NuGet Key: " + push key + | Some key -> + push key + + | Some "push" -> + match key with + | None -> + Console.WriteLine "No nuget-key env var found, skipping..." + | Some key -> + push key + | _ -> + Console.WriteLine "Github event name not 'push', skipping..." + +) Target.create "SelfCheck" (fun _ -> From fa788dbdeddb2984503a24565547f72d93ef4311 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 22 Dec 2023 16:45:32 +0800 Subject: [PATCH 2/2] build.fsx,RELEASE.md: don't push prereleases for relNotes commits The way we had setup the prerelease push was making unnecessary prerelease packages for the same commit that ends up being mapped to a release. But if we push the tag and the branch at the same time, and check the commit with 'git describe' then we can detect the situation and avert it. --- build.fsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/build.fsx b/build.fsx index bdb17c19a..719c7bee0 100644 --- a/build.fsx +++ b/build.fsx @@ -186,7 +186,22 @@ Target.create "Push" (fun _ -> | None -> Console.WriteLine "No nuget-key env var found, skipping..." | Some key -> - push key + if isTag then + push key + else + match getBuildParam "GITHUB_SHA" with + | None -> + failwith "GITHUB_SHA should have been populated" + | Some commitHash -> + let gitArgs = sprintf "describe --exact-match --tags %s" commitHash + let proc = + CreateProcess.fromRawCommandLine "git" gitArgs + |> Proc.run + if proc.ExitCode <> 0 then + // commit is not a tag, so go ahead pushing a prerelease + push key + else + Console.WriteLine "Commit mapped to a tag, skipping pushing prerelease..." | _ -> Console.WriteLine "Github event name not 'push', skipping..."