From b3440b1d9cc11234c105d427568db88e82baa901 Mon Sep 17 00:00:00 2001 From: Romfos Date: Sat, 2 Nov 2024 13:10:41 +0100 Subject: [PATCH 1/2] Move package creating from build.jsproj to github actions --- .github/workflows/build_and_test.yml | 6 +- .github/workflows/release_build.yml | 11 ++- build/ExtractDocs.fs | 1 - build/build.fs | 117 +-------------------------- build/build.fsproj | 7 +- 5 files changed, 12 insertions(+), 130 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 377f517e..8aecd8d5 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -37,8 +37,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Setup .NET uses: actions/setup-dotnet@v4 @@ -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 diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index 7d01d884..cbec1f93 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -14,15 +14,11 @@ jobs: 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 @@ -31,8 +27,11 @@ jobs: ruby-version: '3.2' bundler-cache: true - - name: Build package and docs - run: dotnet run --project 'build/build.fsproj' -- -t All + - name: Build package + run: dotnet pack src/NSubstitute/NSubstitute.csproj -p:CI=true + + - name: Build documentation + run: dotnet run --project 'build/build.fsproj' -- -t Documentation - name: Upload packages uses: actions/upload-artifact@v4 diff --git a/build/ExtractDocs.fs b/build/ExtractDocs.fs index f7a56663..bc4ad516 100644 --- a/build/ExtractDocs.fs +++ b/build/ExtractDocs.fs @@ -1,7 +1,6 @@ module ExtractDocs open System -open System.IO open System.Text.RegularExpressions let LiquidTagRegex = @"```(?\w+)" + // Tag start with argument. e.g. "```csharp" diff --git a/build/build.fs b/build/build.fs index e49e9d8c..3d6250cc 100644 --- a/build/build.fs +++ b/build/build.fs @@ -9,7 +9,6 @@ open Fake.DotNet open Fake.IO open Fake.IO.Globbing.Operators open Fake.IO.FileSystemOperators -open Fake.Tools open ExtractDocs @@ -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(?\d+)\.(?\d+)\.(?\d+)(?
-\w+\d*)?-(?\d+)-g(?[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"
@@ -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" ]
 
 []
 let main argv =
@@ -245,5 +132,5 @@ let main argv =
     |> Context.RuntimeContext.Fake
     |> Context.setExecutionContext
     initTargets()
-    Target.runOrDefaultWithArguments "Default"
+    Target.runOrDefaultWithArguments "TestCodeFromDocs"
     0 
\ No newline at end of file
diff --git a/build/build.fsproj b/build/build.fsproj
index 52230f9e..4f3604de 100644
--- a/build/build.fsproj
+++ b/build/build.fsproj
@@ -16,10 +16,9 @@
   
     
     
-    
-    
-    
-    
+    
+    
+    
   
 
 

From e6a58e5583e45e50703b6b0a50bfe3ac0da03890 Mon Sep 17 00:00:00 2001
From: Romfos 
Date: Sun, 3 Nov 2024 11:36:07 +0100
Subject: [PATCH 2/2] Update github actions

---
 ...se_build.yml => release_documentation.yml} | 20 +------------
 .github/workflows/release_packages.yml        | 28 +++++++++++++++++++
 .../{build_and_test.yml => test.yml}          |  2 +-
 3 files changed, 30 insertions(+), 20 deletions(-)
 rename .github/workflows/{release_build.yml => release_documentation.yml} (62%)
 create mode 100644 .github/workflows/release_packages.yml
 rename .github/workflows/{build_and_test.yml => test.yml} (97%)

diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_documentation.yml
similarity index 62%
rename from .github/workflows/release_build.yml
rename to .github/workflows/release_documentation.yml
index cbec1f93..90bff66e 100644
--- a/.github/workflows/release_build.yml
+++ b/.github/workflows/release_documentation.yml
@@ -1,12 +1,6 @@
-name: Build release packages and documentation
+name: Release documentation
 on:
   workflow_dispatch:
-  push:
-    tags:
-      - 'v*'
-
-env:
-  CONFIGURATION: Release
 
 jobs:
   build:
@@ -27,21 +21,9 @@ jobs:
           ruby-version: '3.2'
           bundler-cache: true
 
-      - name: Build package
-        run: dotnet pack src/NSubstitute/NSubstitute.csproj -p:CI=true
-
       - name: Build documentation
         run: dotnet run --project 'build/build.fsproj' -- -t Documentation
 
-      - name: Upload packages
-        uses: actions/upload-artifact@v4
-        with:
-          name: packages
-          path: |
-            bin/Release/NSubstitute/*.nupkg
-            bin/Release/NSubstitute/*.snupkg
-          retention-days: 7
-
       - name: Upload documentation
         uses: actions/upload-artifact@v4
         with:
diff --git a/.github/workflows/release_packages.yml b/.github/workflows/release_packages.yml
new file mode 100644
index 00000000..770e9859
--- /dev/null
+++ b/.github/workflows/release_packages.yml
@@ -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
\ No newline at end of file
diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/test.yml
similarity index 97%
rename from .github/workflows/build_and_test.yml
rename to .github/workflows/test.yml
index 8aecd8d5..fb82bd71 100644
--- a/.github/workflows/build_and_test.yml
+++ b/.github/workflows/test.yml
@@ -1,4 +1,4 @@
-name: Build, Test, and Format
+name: Build, Test, and Format verification
 on:
   push:
     branches: