Skip to content

Commit 8538ea0

Browse files
authored
Merge pull request #838 from Romfos/main
Move package creating from build.fsproj to github actions
2 parents 72418ad + e6a58e5 commit 8538ea0

File tree

6 files changed

+39
-147
lines changed

6 files changed

+39
-147
lines changed

.github/workflows/release_build.yml renamed to .github/workflows/release_documentation.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
name: Build release packages and documentation
1+
name: Release documentation
22
on:
33
workflow_dispatch:
4-
push:
5-
tags:
6-
- 'v*'
7-
8-
env:
9-
CONFIGURATION: Release
104

115
jobs:
126
build:
137
runs-on: windows-latest
148
steps:
159
- name: Checkout
1610
uses: actions/checkout@v4
17-
with:
18-
fetch-depth: 0
1911

2012
- name: Setup .NET
2113
uses: actions/setup-dotnet@v4
2214
with:
2315
dotnet-version: |
24-
6.0.x
25-
7.0.x
2616
8.0.x
2717
2818
- name: Setup Ruby for documentation build
@@ -31,17 +21,8 @@ jobs:
3121
ruby-version: '3.2'
3222
bundler-cache: true
3323

34-
- name: Build package and docs
35-
run: dotnet run --project 'build/build.fsproj' -- -t All
36-
37-
- name: Upload packages
38-
uses: actions/upload-artifact@v4
39-
with:
40-
name: packages
41-
path: |
42-
bin/Release/NSubstitute/*.nupkg
43-
bin/Release/NSubstitute/*.snupkg
44-
retention-days: 7
24+
- name: Build documentation
25+
run: dotnet run --project 'build/build.fsproj' -- -t Documentation
4526

4627
- name: Upload documentation
4728
uses: actions/upload-artifact@v4
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release packages
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
build:
7+
runs-on: windows-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
12+
- name: Setup .NET
13+
uses: actions/setup-dotnet@v4
14+
with:
15+
dotnet-version: |
16+
8.0.x
17+
18+
- name: Build package
19+
run: dotnet pack src/NSubstitute/NSubstitute.csproj -p:CI=true
20+
21+
- name: Upload packages
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: packages
25+
path: |
26+
bin/Release/NSubstitute/*.nupkg
27+
bin/Release/NSubstitute/*.snupkg
28+
retention-days: 7

.github/workflows/build_and_test.yml renamed to .github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build, Test, and Format
1+
name: Build, Test, and Format verification
22
on:
33
push:
44
branches:
@@ -37,8 +37,6 @@ jobs:
3737
steps:
3838
- name: Checkout
3939
uses: actions/checkout@v4
40-
with:
41-
fetch-depth: 0
4240

4341
- name: Setup .NET
4442
uses: actions/setup-dotnet@v4
@@ -53,8 +51,8 @@ jobs:
5351
ruby-version: '3.2'
5452
bundler-cache: true
5553

56-
- name: Build all targets
57-
run: build\build.cmd --target All
54+
- name: Build documentation
55+
run: build\build.cmd --target Documentation
5856

5957
format-verify:
6058
runs-on: ubuntu-latest

build/ExtractDocs.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module ExtractDocs
22

33
open System
4-
open System.IO
54
open System.Text.RegularExpressions
65

76
let LiquidTagRegex = @"```(?<tag>\w+)" + // Tag start with argument. e.g. "```csharp"

build/build.fs

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ open Fake.DotNet
99
open Fake.IO
1010
open Fake.IO.Globbing.Operators
1111
open Fake.IO.FileSystemOperators
12-
open Fake.Tools
1312

1413
open ExtractDocs
1514

@@ -42,111 +41,15 @@ module ExamplesToCode =
4241
ConvertFile file targetDir
4342

4443
type BuildVersion = { assembly: string; file: string; info: string; package: string }
45-
let getVersion () =
46-
// The --first-parent flag is needed to make our walk linear from current commit and top.
47-
// This way also merge commit is counted as "1".
48-
let desc = Git.CommandHelper.runSimpleGitCommand "" "describe --tags --long --abbrev=40 --first-parent --match=v*"
49-
let result = Regex.Match(desc,
50-
@"^v(?<maj>\d+)\.(?<min>\d+)\.(?<rev>\d+)(?<pre>-\w+\d*)?-(?<num>\d+)-g(?<sha>[a-z0-9]+)$",
51-
RegexOptions.IgnoreCase)
52-
.Groups
53-
let getMatch (name:string) = result.[name].Value
54-
55-
let (major, minor, revision, preReleaseSuffix, commitsNum, commitSha) =
56-
(getMatch "maj" |> int, getMatch "min" |> int, getMatch "rev" |> int, getMatch "pre", getMatch "num" |> int, getMatch "sha")
57-
58-
// Assembly version should contain major and minor only, as no breaking changes are expected in bug fix releases.
59-
let assemblyVersion = sprintf "%d.%d.0.0" major minor
60-
let fileVersion = sprintf "%d.%d.%d.%d" major minor revision commitsNum
61-
62-
// If number of commits since last tag is greater than zero, we append another identifier with number of commits.
63-
// The produced version is larger than the last tag version.
64-
// If we are on a tag, we use version without modification.
65-
// Examples of output: 3.50.2.1, 3.50.2.215, 3.50.1-rc1.3, 3.50.1-rc3.35
66-
let packageVersion = match commitsNum with
67-
| 0 -> sprintf "%d.%d.%d%s" major minor revision preReleaseSuffix
68-
| _ -> sprintf "%d.%d.%d%s.%d" major minor revision preReleaseSuffix commitsNum
69-
70-
let infoVersion = match commitsNum with
71-
| 0 -> packageVersion
72-
| _ -> sprintf "%s-%s" packageVersion commitSha
73-
74-
{ assembly = assemblyVersion; file = fileVersion; info = infoVersion; package = packageVersion }
75-
44+
7645
let root = __SOURCE_DIRECTORY__ </> ".." |> Path.getFullName
7746

7847
let configuration = Environment.environVarOrDefault "configuration" "Debug"
79-
let version = getVersion ()
80-
81-
let additionalArgs = [
82-
"AssemblyVersion", version.assembly
83-
"FileVersion", version.file
84-
"InformationalVersion", version.info
85-
"PackageVersion", version.package
86-
]
8748

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

9152
let initTargets() =
92-
Target.create "Default" ignore
93-
Target.create "All" ignore
94-
95-
Target.description("Clean compilation artifacts and remove output bin directory")
96-
Target.create "Clean" (fun _ ->
97-
DotNet.exec (fun p -> { p with WorkingDirectory = root }) "clean"
98-
(sprintf "--configuration %s --verbosity minimal" configuration)
99-
|> ignore
100-
Shell.cleanDirs [ output ]
101-
)
102-
103-
Target.description("Restore dependencies")
104-
Target.create "Restore" (fun _ ->
105-
DotNet.restore (fun p -> p) solution
106-
)
107-
108-
Target.description("Compile all projects")
109-
Target.create "Build" (fun _ ->
110-
DotNet.build (fun p ->
111-
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
112-
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
113-
}) solution
114-
)
115-
116-
Target.description("Run tests")
117-
Target.create "Test" (fun _ ->
118-
DotNet.test (fun p ->
119-
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
120-
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
121-
}) (root </> "tests/NSubstitute.Acceptance.Specs/NSubstitute.Acceptance.Specs.csproj")
122-
)
123-
124-
Target.description("Generate Nuget package")
125-
Target.create "Package" (fun _ ->
126-
DotNet.pack (fun p ->
127-
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
128-
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
129-
}) (root </> "src/NSubstitute/NSubstitute.csproj")
130-
)
131-
132-
Target.description("Run all benchmarks. Must be run with configuration=Release.")
133-
Target.create "Benchmarks" (fun _ ->
134-
if configuration <> "Release" then
135-
failwith "Benchmarks can only be run in Release mode. Please re-run the build in Release configuration."
136-
137-
let benchmarkCsproj = root </> "tests/NSubstitute.Benchmarks/NSubstitute.Benchmarks.csproj" |> Path.getFullName
138-
let benchmarkToRun = Environment.environVarOrDefault "benchmark" "*" // Defaults to "*" (all)
139-
[ "netcoreapp2.1" ]
140-
|> List.iter (fun framework ->
141-
Trace.traceImportant ("Benchmarking " + framework)
142-
let work = output </> "benchmark-" + framework
143-
Directory.ensure work
144-
DotNet.exec (fun p -> { p with WorkingDirectory = work }) "run"
145-
("--framework " + framework + " --project " + benchmarkCsproj + " -- " + benchmarkToRun)
146-
|> ignore
147-
)
148-
)
149-
15053
Target.description("Extract, build and test code from documentation.")
15154
Target.create "TestCodeFromDocs" <| fun _ ->
15255
let outputCodePath = output </> "CodeFromDocs"
@@ -219,23 +122,7 @@ let initTargets() =
219122
printfn ""
220123
Target.listAvailable()
221124

222-
"Clean" ?=> "Build" |> ignore
223-
"Clean" ?=> "Test" |> ignore
224-
"Clean" ?=> "Restore" |> ignore
225-
"Clean" ?=> "Documentation" |> ignore
226-
"Clean" ?=> "TestCodeFromDocs" |> ignore
227-
"Clean" ?=> "Package" |> ignore
228-
"Clean" ?=> "Default" |> ignore
229-
230-
"Build" <== [ "Restore" ]
231-
"Test" <== [ "Build" ]
232125
"Documentation" <== [ "TestCodeFromDocs" ]
233-
"Benchmarks" <== [ "Build" ]
234-
// For packaging, use a clean build and make sure all tests (inc. docs) pass.
235-
"Package" <== [ "Clean"; "Build"; "Test"; "TestCodeFromDocs" ]
236-
237-
"Default" <== [ "Restore"; "Build"; "Test" ]
238-
"All" <== [ "Clean"; "Default"; "Documentation"; "Package" ]
239126

240127
[<EntryPoint>]
241128
let main argv =
@@ -245,5 +132,5 @@ let main argv =
245132
|> Context.RuntimeContext.Fake
246133
|> Context.setExecutionContext
247134
initTargets()
248-
Target.runOrDefaultWithArguments "Default"
135+
Target.runOrDefaultWithArguments "TestCodeFromDocs"
249136
0

build/build.fsproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
<ItemGroup>
1717
<PackageReference Include="Microsoft.Build" Version="17.9.5" />
1818
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.9.5" />
19-
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.235" />
20-
<PackageReference Include="Fake.DotNet.Cli" Version="6.0.0" />
21-
<PackageReference Include="Fake.Tools.Git" Version="6.0.0" />
22-
<PackageReference Include="Fake.Core.Target" Version="6.0.0" />
19+
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.374" />
20+
<PackageReference Include="Fake.DotNet.Cli" Version="6.1.3" />
21+
<PackageReference Include="Fake.Core.Target" Version="6.1.3" />
2322
</ItemGroup>
2423

2524
</Project>

0 commit comments

Comments
 (0)