Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move package creating from build.fsproj to github actions #838

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
name: Build release packages and documentation
name: Release documentation
on:
workflow_dispatch:
push:
tags:
- 'v*'

env:
CONFIGURATION: Release

jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x

- name: Setup Ruby for documentation build
Expand All @@ -31,17 +21,8 @@ jobs:
ruby-version: '3.2'
bundler-cache: true

- name: Build package and docs
run: dotnet run --project 'build/build.fsproj' -- -t All

- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: packages
path: |
bin/Release/NSubstitute/*.nupkg
bin/Release/NSubstitute/*.snupkg
retention-days: 7
- name: Build documentation
run: dotnet run --project 'build/build.fsproj' -- -t Documentation

- name: Upload documentation
uses: actions/upload-artifact@v4
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/release_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release packages
on:
workflow_dispatch:

jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x

- name: Build package
run: dotnet pack src/NSubstitute/NSubstitute.csproj -p:CI=true

- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: packages
path: |
bin/Release/NSubstitute/*.nupkg
bin/Release/NSubstitute/*.snupkg
retention-days: 7
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build, Test, and Format
name: Build, Test, and Format verification
on:
push:
branches:
Expand Down Expand Up @@ -37,8 +37,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
Expand All @@ -53,8 +51,8 @@ jobs:
ruby-version: '3.2'
bundler-cache: true

- name: Build all targets
run: build\build.cmd --target All
- name: Build documentation
run: build\build.cmd --target Documentation

format-verify:
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion build/ExtractDocs.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module ExtractDocs

open System
open System.IO
open System.Text.RegularExpressions

let LiquidTagRegex = @"```(?<tag>\w+)" + // Tag start with argument. e.g. "```csharp"
Expand Down
117 changes: 2 additions & 115 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.IO.FileSystemOperators
open Fake.Tools

open ExtractDocs

Expand Down Expand Up @@ -42,111 +41,15 @@ module ExamplesToCode =
ConvertFile file targetDir

type BuildVersion = { assembly: string; file: string; info: string; package: string }
let getVersion () =
// The --first-parent flag is needed to make our walk linear from current commit and top.
// This way also merge commit is counted as "1".
let desc = Git.CommandHelper.runSimpleGitCommand "" "describe --tags --long --abbrev=40 --first-parent --match=v*"
let result = Regex.Match(desc,
@"^v(?<maj>\d+)\.(?<min>\d+)\.(?<rev>\d+)(?<pre>-\w+\d*)?-(?<num>\d+)-g(?<sha>[a-z0-9]+)$",
RegexOptions.IgnoreCase)
.Groups
let getMatch (name:string) = result.[name].Value

let (major, minor, revision, preReleaseSuffix, commitsNum, commitSha) =
(getMatch "maj" |> int, getMatch "min" |> int, getMatch "rev" |> int, getMatch "pre", getMatch "num" |> int, getMatch "sha")

// Assembly version should contain major and minor only, as no breaking changes are expected in bug fix releases.
let assemblyVersion = sprintf "%d.%d.0.0" major minor
let fileVersion = sprintf "%d.%d.%d.%d" major minor revision commitsNum

// If number of commits since last tag is greater than zero, we append another identifier with number of commits.
// The produced version is larger than the last tag version.
// If we are on a tag, we use version without modification.
// Examples of output: 3.50.2.1, 3.50.2.215, 3.50.1-rc1.3, 3.50.1-rc3.35
let packageVersion = match commitsNum with
| 0 -> sprintf "%d.%d.%d%s" major minor revision preReleaseSuffix
| _ -> sprintf "%d.%d.%d%s.%d" major minor revision preReleaseSuffix commitsNum

let infoVersion = match commitsNum with
| 0 -> packageVersion
| _ -> sprintf "%s-%s" packageVersion commitSha

{ assembly = assemblyVersion; file = fileVersion; info = infoVersion; package = packageVersion }


let root = __SOURCE_DIRECTORY__ </> ".." |> Path.getFullName

let configuration = Environment.environVarOrDefault "configuration" "Debug"
let version = getVersion ()

let additionalArgs = [
"AssemblyVersion", version.assembly
"FileVersion", version.file
"InformationalVersion", version.info
"PackageVersion", version.package
]

let output = root </> "bin" </> configuration
let solution = (root </> "NSubstitute.sln")

let initTargets() =
Target.create "Default" ignore
Target.create "All" ignore

Target.description("Clean compilation artifacts and remove output bin directory")
Target.create "Clean" (fun _ ->
DotNet.exec (fun p -> { p with WorkingDirectory = root }) "clean"
(sprintf "--configuration %s --verbosity minimal" configuration)
|> ignore
Shell.cleanDirs [ output ]
)

Target.description("Restore dependencies")
Target.create "Restore" (fun _ ->
DotNet.restore (fun p -> p) solution
)

Target.description("Compile all projects")
Target.create "Build" (fun _ ->
DotNet.build (fun p ->
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
}) solution
)

Target.description("Run tests")
Target.create "Test" (fun _ ->
DotNet.test (fun p ->
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
}) (root </> "tests/NSubstitute.Acceptance.Specs/NSubstitute.Acceptance.Specs.csproj")
)

Target.description("Generate Nuget package")
Target.create "Package" (fun _ ->
DotNet.pack (fun p ->
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
}) (root </> "src/NSubstitute/NSubstitute.csproj")
)

Target.description("Run all benchmarks. Must be run with configuration=Release.")
Target.create "Benchmarks" (fun _ ->
if configuration <> "Release" then
failwith "Benchmarks can only be run in Release mode. Please re-run the build in Release configuration."

let benchmarkCsproj = root </> "tests/NSubstitute.Benchmarks/NSubstitute.Benchmarks.csproj" |> Path.getFullName
let benchmarkToRun = Environment.environVarOrDefault "benchmark" "*" // Defaults to "*" (all)
[ "netcoreapp2.1" ]
|> List.iter (fun framework ->
Trace.traceImportant ("Benchmarking " + framework)
let work = output </> "benchmark-" + framework
Directory.ensure work
DotNet.exec (fun p -> { p with WorkingDirectory = work }) "run"
("--framework " + framework + " --project " + benchmarkCsproj + " -- " + benchmarkToRun)
|> ignore
)
)

Target.description("Extract, build and test code from documentation.")
Target.create "TestCodeFromDocs" <| fun _ ->
let outputCodePath = output </> "CodeFromDocs"
Expand Down Expand Up @@ -219,23 +122,7 @@ let initTargets() =
printfn ""
Target.listAvailable()

"Clean" ?=> "Build" |> ignore
"Clean" ?=> "Test" |> ignore
"Clean" ?=> "Restore" |> ignore
"Clean" ?=> "Documentation" |> ignore
"Clean" ?=> "TestCodeFromDocs" |> ignore
"Clean" ?=> "Package" |> ignore
"Clean" ?=> "Default" |> ignore

"Build" <== [ "Restore" ]
"Test" <== [ "Build" ]
"Documentation" <== [ "TestCodeFromDocs" ]
"Benchmarks" <== [ "Build" ]
// For packaging, use a clean build and make sure all tests (inc. docs) pass.
"Package" <== [ "Clean"; "Build"; "Test"; "TestCodeFromDocs" ]

"Default" <== [ "Restore"; "Build"; "Test" ]
"All" <== [ "Clean"; "Default"; "Documentation"; "Package" ]

[<EntryPoint>]
let main argv =
Expand All @@ -245,5 +132,5 @@ let main argv =
|> Context.RuntimeContext.Fake
|> Context.setExecutionContext
initTargets()
Target.runOrDefaultWithArguments "Default"
Target.runOrDefaultWithArguments "TestCodeFromDocs"
0
7 changes: 3 additions & 4 deletions build/build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="17.9.5" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.9.5" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.235" />
<PackageReference Include="Fake.DotNet.Cli" Version="6.0.0" />
<PackageReference Include="Fake.Tools.Git" Version="6.0.0" />
<PackageReference Include="Fake.Core.Target" Version="6.0.0" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.374" />
<PackageReference Include="Fake.DotNet.Cli" Version="6.1.3" />
<PackageReference Include="Fake.Core.Target" Version="6.1.3" />
</ItemGroup>

</Project>
Loading