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..719c7bee0 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,44 @@ 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 -> + 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..." + +) Target.create "SelfCheck" (fun _ ->