Skip to content

Commit

Permalink
Merge pull request #21 from MortalFlesh/fix/build-net-version
Browse files Browse the repository at this point in the history
Update build to fix publishing public libs
  • Loading branch information
MortalFlesh authored Dec 30, 2023
2 parents 4f7f39b + 1fd294f commit 14df792
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<!-- There is always Unreleased section on the top. Subsections (Add, Changed, Fix, Removed) should be Add as needed. -->
## Unreleased
- Fix build .net version

## 6.0.0 - 2023-12-14
- [**BC**] Use net 8.0
Expand Down
6 changes: 4 additions & 2 deletions build/Build.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ========================================================================================================
// === F# / Project fake build ==================================================================== 1.2.0 =
// === F# / Project fake build ==================================================================== 1.3.0 =
// --------------------------------------------------------------------------------------------------------
// Options:
// - no-clean - disables clean of dirs in the first step (required on CI)
Expand All @@ -23,7 +23,9 @@ let main args =
Summary = "Library to help with basic Console I/O"
Git = Git.init ()
}
Specs = Spec.defaultLibrary
Specs =
Spec.defaultLibrary
|> Spec.mapLibrary (fun library -> { library with NugetApi = NugetApi.AskForKey })
}

args |> Args.run
50 changes: 30 additions & 20 deletions build/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ module internal Targets =

Target.create "Release" (fun _ ->
match definition with
| { Specs = Library { ReleaseDir = releaseDir } } ->
| { Specs = Library { ReleaseDir = releaseDir; NugetApi = nugetApi } } ->
match "src" </> definition.Project.Name with
| releaseSource when releaseSource |> Directory.Exists ->
Dotnet.runOrFail "pack" releaseSource
Expand Down Expand Up @@ -294,36 +294,46 @@ module internal Targets =

Target.create "Publish" (fun _ ->
match definition with
| { Specs = Library { ReleaseDir = releaseDir } } ->
let organization =
envVar "PRIVATE_FEED_USER"
|> Option.orElse (envVar "NUGET_SERVER_ORGANIZATION")
|> Option.defaultValue "almacareer"
let nugetToken = envVar "PRIVATE_FEED_PASS" |> Option.requireSome "Environment variable PRIVATE_FEED_PASS is not set."

Trace.tracefn "[Nuget] Add source"
sprintf "nuget add source --username %s --password %s --store-password-in-clear-text --name github \"https://nuget.pkg.github.com/%s/index.json\""
organization nugetToken organization
|> Dotnet.runInRootOrFail
| { Specs = Library { NugetApi = NugetApi.NotUsed } } -> Trace.traceHeader "NugetApi is not used"

Trace.tracefn "[Nuget] Push packages"
sprintf "nuget push %s -s github --api-key=%s --skip-duplicate" (releaseDir </> "*.nupkg") nugetToken
|> Dotnet.runInRootOrFail
| { Specs = Library { ReleaseDir = releaseDir; NugetApi = NugetApi.Organization organization; NugetCustomServerRepository = nugetServer } } ->
Trace.traceHeader "Pushing to organization nuget server"

envVar "PRIVATE_FEED_PASS"
|> Option.requireSome "Environment variable PRIVATE_FEED_PASS is not set."
|> Nuget.push releaseDir (Some organization)

match envVar "NUGET_SERVER_TOKEN" with
| Some token ->
Trace.tracefn "Trigger: Update nuget-server readme"
match envVar "NUGET_SERVER_TOKEN", envVar "NUGET_SERVER_REPOSITORY" |> Option.orElse nugetServer with
| Some token, Some repository ->
Trace.tracefn "Trigger: Update %s readme" repository

Github.triggerAction {
EventType = "update-readme"
CurrentProject = definition.Project.Name
Token = token
Organization = envVar "NUGET_SERVER_ORGANIZATION" |> Option.defaultValue "almacareer"
Repository = envVar "NUGET_SERVER_REPOSITORY" |> Option.defaultValue "prc-nuget-server"
Organization = envVar "NUGET_SERVER_ORGANIZATION" |> Option.defaultValue organization
Repository = repository
}
|> Async.RunSynchronously

| _ -> ()

| { Specs = Library { ReleaseDir = releaseDir; NugetApi = NugetApi.AskForKey; Organization = organization }} ->
Trace.traceHeader "Pushing to public nuget server"

match UserInput.getUserInput "Are you sure - is it tagged yet? [y|n]: " with
| "y" | "yes" ->
match UserInput.getUserPassword "Nuget ApiKey: " with
| null | "" -> failwithf "You have to provide an api key for nuget."
| apiKey -> Nuget.push releaseDir organization apiKey
| _ -> ()

| { Specs = Library { ReleaseDir = releaseDir; NugetApi = NugetApi.KeyInEnvironment name; Organization = organization }} ->
Trace.traceHeader "Pushing to nuget server"

envVar name
|> Option.iter (Nuget.push releaseDir organization)

| _ -> ()
)

Expand Down
54 changes: 54 additions & 0 deletions build/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ module internal Utils =
let runOrFail command dir = run command dir |> orFail
let runInRootOrFail command = run command "." |> orFail

[<RequireQualifiedAccess>]
module Nuget =
let push releaseDir organization token =
let sourceName =
organization
|> Option.map (fun organization ->
let sourceName = "github"

Trace.tracefn "[Nuget] Add organization %A as a source" organization
sprintf "nuget add source --username %s --password %s --store-password-in-clear-text --name %s \"https://nuget.pkg.github.com/%s/index.json\""
organization token sourceName organization
|> Dotnet.runInRootOrFail

sourceName
)

Trace.tracefn "[Nuget] Push packages"
sprintf "nuget push %s --source=%s --api-key=%s --skip-duplicate"
(releaseDir </> "*.nupkg")
(sourceName |> Option.defaultValue "https://api.nuget.org/v3/index.json")
token
|> Dotnet.runInRootOrFail

[<AutoOpen>]
module ProjectDefinition =
type IProjectSources =
Expand Down Expand Up @@ -150,13 +173,25 @@ module internal Utils =
LibrarySources: IGlobbingPattern
TestsSources: IGlobbingPattern
AllSources: IGlobbingPattern
/// Organization (it is used for a custom github nuget source)
Organization: string option
/// Configuration for nuget api, to push packages into
NugetApi: NugetApi
/// Repository for custom nuget server, it will be triggered for a readme update
NugetCustomServerRepository: string option
}

interface IProjectSources with
member this.Sources = this.LibrarySources
member this.Tests = this.TestsSources
member this.All = this.AllSources

and [<RequireQualifiedAccess>] NugetApi =
| NotUsed
| AskForKey
| Organization of name: string
| KeyInEnvironment of string

and ExecutableSpec =
{
Changelog: string option
Expand Down Expand Up @@ -247,6 +282,9 @@ module internal Utils =
sources
++ "tests/*.fsproj"
++ "build/*.fsproj"
Organization = None
NugetApi = NugetApi.NotUsed
NugetCustomServerRepository = None
}

let defaultExecutable: ProjectSpec =
Expand Down Expand Up @@ -308,6 +346,22 @@ module internal Utils =
AllSources = release ++ "tests/**/*.fsproj"
}

let mapLibrary f = function
| Library spec -> f spec |> Library
| spec -> spec

let mapExecutable f = function
| Executable spec -> f spec |> Executable
| spec -> spec

let mapConsoleApplication f = function
| ConsoleApplication spec -> f spec |> ConsoleApplication
| spec -> spec

let mapSAFEStackApplication f = function
| SAFEStackApplication spec -> f spec |> SAFEStackApplication
| spec -> spec

[<RequireQualifiedAccess>]
module RuntimeId =
/// Runtime IDs: https://docs.microsoft.com/en-us/dotnet/core/rid-catalog#macos-rids
Expand Down
2 changes: 1 addition & 1 deletion build/build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down

0 comments on commit 14df792

Please sign in to comment.