diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index f35bc58e..f71cd5c1 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,19 +1,3 @@ -# ------------------------------------------------------------------------------ -# -# -# This code was generated. -# -# - To turn off auto-generation set: -# -# [GitHubActions (AutoGenerate = false)] -# -# - To trigger manual generation invoke: -# -# nuke --generate-configuration GitHubActions_integration --host GitHubActions -# -# -# ------------------------------------------------------------------------------ - name: integration on: @@ -25,72 +9,71 @@ jobs: ubuntu-latest: name: ubuntu-latest runs-on: ubuntu-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: DeployNuGet' - run: ./build.cmd DeployNuGet + - name: 'Build with target: NuGetPush' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: 'Publish: coverage_report' + NUGET_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./build.cmd -t nugetpush + - name: 'Publish: coverage-report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-linux + path: .tests/coverage-report windows-latest: name: windows-latest runs-on: windows-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: DeployNuGet' - run: ./build.cmd DeployNuGet - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Build with target: Pack' + run: ./build.cmd -t pack - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-windows + path: .tests/coverage-report macos-latest: name: macos-latest runs-on: macos-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: DeployNuGet' - run: ./build.cmd DeployNuGet - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Build with target: Pack' + run: ./build.cmd -t pack - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-macos + path: .tests/coverage-report diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 071377c0..474ef63e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,19 +1,3 @@ -# ------------------------------------------------------------------------------ -# -# -# This code was generated. -# -# - To turn off auto-generation set: -# -# [GitHubActions (AutoGenerate = false)] -# -# - To trigger manual generation invoke: -# -# nuke --generate-configuration GitHubActions_main --host GitHubActions -# -# -# ------------------------------------------------------------------------------ - name: main on: @@ -25,72 +9,71 @@ jobs: ubuntu-latest: name: ubuntu-latest runs-on: ubuntu-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: DeployNuGet' - run: ./build.cmd DeployNuGet + - name: 'Build with target: NuGetPush' + run: ./build.cmd -t nugetpush env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NUGET_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-linux + path: .tests/coverage-report windows-latest: name: windows-latest runs-on: windows-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: DeployNuGet' - run: ./build.cmd DeployNuGet - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Build with target: Pack' + run: ./build.cmd -t pack - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-windows + path: .tests/coverage-report macos-latest: name: macos-latest runs-on: macos-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: DeployNuGet' - run: ./build.cmd DeployNuGet - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Build with target: Pack' + run: ./build.cmd -t pack - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-macos + path: .tests/coverage-report diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9da0231a..d18d68fb 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,19 +1,3 @@ -# ------------------------------------------------------------------------------ -# -# -# This code was generated. -# -# - To turn off auto-generation set: -# -# [GitHubActions (AutoGenerate = false)] -# -# - To trigger manual generation invoke: -# -# nuke --generate-configuration GitHubActions_pull-request --host GitHubActions -# -# -# ------------------------------------------------------------------------------ - name: pull-request on: @@ -25,72 +9,69 @@ jobs: ubuntu-latest: name: ubuntu-latest runs-on: ubuntu-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: Rebuild, CodeCoverage, Pack' - run: ./build.cmd Rebuild CodeCoverage Pack - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Build with target: Pack' + run: ./build.cmd -t pack - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-linux + path: .tests/coverage-report windows-latest: name: windows-latest runs-on: windows-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: Rebuild, CodeCoverage, Pack' - run: ./build.cmd Rebuild CodeCoverage Pack - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Build with target: Pack' + run: ./build.cmd -t pack - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-windows + path: .tests/coverage-report macos-latest: name: macos-latest runs-on: macos-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: Rebuild, CodeCoverage, Pack' - run: ./build.cmd Rebuild CodeCoverage Pack - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Build with target: Pack' + run: ./build.cmd -t pack - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 - if: runner.os == 'Linux' with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-macos + path: .tests/coverage-report diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e420f1a9..70f1df0c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,19 +1,3 @@ -# ------------------------------------------------------------------------------ -# -# -# This code was generated. -# -# - To turn off auto-generation set: -# -# [GitHubActions (AutoGenerate = false)] -# -# - To trigger manual generation invoke: -# -# nuke --generate-configuration GitHubActions_release --host GitHubActions -# -# -# ------------------------------------------------------------------------------ - name: release on: @@ -25,24 +9,25 @@ jobs: ubuntu-latest: name: ubuntu-latest runs-on: ubuntu-latest + env: + TERM: xterm + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 'Cache: .nuke/temp, ~/.nuget/packages' + - name: 'Cache: ~/.nuget/packages' uses: actions/cache@v4 with: path: | - .nuke/temp ~/.nuget/packages key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }} - - name: 'Run: DeployNuGet' - run: ./build.cmd DeployNuGet + - name: 'Build with target: NuGetPush' + run: ./build.cmd -t pack env: - NUGET_ORG_TOKEN: ${{ secrets.NUGET_ORG_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NUGET_TOKEN: ${{ secrets.NUGET_ORG_TOKEN }} - name: 'Publish: coverage_report' uses: actions/upload-artifact@v4 with: - name: coverage_report - path: .tests/coverage_report + name: coverage-report-linux + path: .tests/coverage-report diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json deleted file mode 100644 index be4fe84f..00000000 --- a/.nuke/build.schema.json +++ /dev/null @@ -1,133 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "definitions": { - "Host": { - "type": "string", - "enum": [ - "AppVeyor", - "AzurePipelines", - "Bamboo", - "Bitbucket", - "Bitrise", - "GitHubActions", - "GitLab", - "Jenkins", - "Rider", - "SpaceAutomation", - "TeamCity", - "Terminal", - "TravisCI", - "VisualStudio", - "VSCode" - ] - }, - "ExecutableTarget": { - "type": "string", - "enum": [ - "Build", - "Clean", - "CodeCoverage", - "DeployNuGet", - "Pack", - "PushNuGet", - "Rebuild", - "Restore", - "Test" - ] - }, - "Verbosity": { - "type": "string", - "description": "", - "enum": [ - "Verbose", - "Normal", - "Minimal", - "Quiet" - ] - }, - "NukeBuild": { - "properties": { - "Continue": { - "type": "boolean", - "description": "Indicates to continue a previously failed build attempt" - }, - "Help": { - "type": "boolean", - "description": "Shows the help text for this build assembly" - }, - "Host": { - "description": "Host for execution. Default is 'automatic'", - "$ref": "#/definitions/Host" - }, - "NoLogo": { - "type": "boolean", - "description": "Disables displaying the NUKE logo" - }, - "Partition": { - "type": "string", - "description": "Partition to use on CI" - }, - "Plan": { - "type": "boolean", - "description": "Shows the execution plan (HTML)" - }, - "Profile": { - "type": "array", - "description": "Defines the profiles to load", - "items": { - "type": "string" - } - }, - "Root": { - "type": "string", - "description": "Root directory during build execution" - }, - "Skip": { - "type": "array", - "description": "List of targets to be skipped. Empty list skips all dependencies", - "items": { - "$ref": "#/definitions/ExecutableTarget" - } - }, - "Target": { - "type": "array", - "description": "List of targets to be invoked. Default is '{default_target}'", - "items": { - "$ref": "#/definitions/ExecutableTarget" - } - }, - "Verbosity": { - "description": "Logging verbosity during build execution. Default is 'Normal'", - "$ref": "#/definitions/Verbosity" - } - } - } - }, - "allOf": [ - { - "properties": { - "Configuration": { - "type": "string", - "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", - "enum": [ - "Debug", - "Release" - ] - }, - "GITHUB_TOKEN": { - "type": "string" - }, - "NUGET_ORG_TOKEN": { - "type": "string" - }, - "Solution": { - "type": "string", - "description": "Path to a solution file that is automatically loaded" - } - } - }, - { - "$ref": "#/definitions/NukeBuild" - } - ] -} diff --git a/.nuke/parameters.json b/.nuke/parameters.json deleted file mode 100644 index 4eb7c338..00000000 --- a/.nuke/parameters.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "./build.schema.json", - "Solution": "Core.sln" -} diff --git a/Core.sln b/Core.sln index dce7aa22..f0ff9a93 100644 --- a/Core.sln +++ b/Core.sln @@ -63,13 +63,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Net.Servers. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Data.EfCore.SqlServer", "source\Data\CreativeCoders.Data.EfCore.SqlServer\CreativeCoders.Data.EfCore.SqlServer.csproj", "{C57A6AD0-A0AB-45F3-BC32-58E469CACC15}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{02EB95BA-07BE-441F-ADC7-3363AC17814C}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_build", "_build", "{DB7A40EE-F469-4B87-A629-250BBB9ECC92}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NukeBuild", "NukeBuild", "{20FCFF4D-882F-4663-81F4-A146D17B62A0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.NukeBuild", "source\NukeBuild\CreativeCoders.NukeBuild\CreativeCoders.NukeBuild.csproj", "{4687771E-6F0E-40C8-8C0A-DEDC20260604}" + ProjectSection(SolutionItems) = preProject + build.cmd = build.cmd + build.ps1 = build.ps1 + build.sh = build.sh + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{72E179CA-7AE6-412A-856D-7BD13838E8E3}" ProjectSection(SolutionItems) = preProject @@ -146,8 +145,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.Daemon.Linux EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.Daemon.Windows", "source\Daemon\CreativeCoders.Daemon.Windows\CreativeCoders.Daemon.Windows.csproj", "{30E75E1A-146F-422E-8C14-3AE0F7FB99B1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.NukeBuild.Components", "source\NukeBuild\CreativeCoders.NukeBuild.Components\CreativeCoders.NukeBuild.Components.csproj", "{5D68956E-580F-4A2A-B13F-1477E6DE6FCF}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "IO", "IO", "{F31389F0-613B-48B1-AA99-6BFC3D8D7D1A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.IO", "source\IO\CreativeCoders.IO\CreativeCoders.IO.csproj", "{3B1E60AF-5B5C-4BED-8AAF-79167CF5E2C0}" @@ -207,8 +204,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.AspNetCore.T EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.AspNetCore.Tests", "tests\CreativeCoders.AspNetCore.Tests\CreativeCoders.AspNetCore.Tests.csproj", "{9A2200C2-46F7-447A-8B9C-40A81D03D0B6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.NukeBuild.Tests", "tests\CreativeCoders.NukeBuild.Tests\CreativeCoders.NukeBuild.Tests.csproj", "{FC343B26-4AB3-47E7-B9EE-9EFFF0E02C7D}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTestApp", "samples\ConsoleTestApp\ConsoleTestApp.csproj", "{037EDB81-3473-4EF6-82A9-BCE5FAE1DE00}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Options", "Options", "{23126211-23BF-4399-A227-6C609FB7505E}" @@ -247,6 +242,22 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CliHostSampleApp", "samples EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.Cli.Tests", "tests\CreativeCoders.Cli.Tests\CreativeCoders.Cli.Tests.csproj", "{FF482B6D-D459-413E-82E0-9175C44DA8BA}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CakeBuild", "CakeBuild", "{E8EF00ED-01FA-4F51-A668-5AF8B6C0F09E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.CakeBuild", "source\CakeBuild\CreativeCoders.CakeBuild\CreativeCoders.CakeBuild.csproj", "{EB88412B-8523-4DA4-8FF9-CACECA0969E6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeBuildSample", "samples\CakeBuildSample\CakeBuildSample.csproj", "{58C01CB8-B65A-44FE-9BE0-22929CD474A2}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ci", "ci", "{F3331DB3-C40A-4712-A545-EE5C628B0F39}" + ProjectSection(SolutionItems) = preProject + .github\workflows\integration.yml = .github\workflows\integration.yml + .github\workflows\release.yml = .github\workflows\release.yml + .github\workflows\main.yml = .github\workflows\main.yml + .github\workflows\pull-request.yml = .github\workflows\pull-request.yml + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "build\Build.csproj", "{4A397E49-CB4F-4348-9798-A7F2B5F276DA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -325,12 +336,6 @@ Global {C57A6AD0-A0AB-45F3-BC32-58E469CACC15}.Debug|Any CPU.Build.0 = Debug|Any CPU {C57A6AD0-A0AB-45F3-BC32-58E469CACC15}.Release|Any CPU.ActiveCfg = Release|Any CPU {C57A6AD0-A0AB-45F3-BC32-58E469CACC15}.Release|Any CPU.Build.0 = Release|Any CPU - {02EB95BA-07BE-441F-ADC7-3363AC17814C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {02EB95BA-07BE-441F-ADC7-3363AC17814C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4687771E-6F0E-40C8-8C0A-DEDC20260604}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4687771E-6F0E-40C8-8C0A-DEDC20260604}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4687771E-6F0E-40C8-8C0A-DEDC20260604}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4687771E-6F0E-40C8-8C0A-DEDC20260604}.Release|Any CPU.Build.0 = Release|Any CPU {A815C965-84FF-4880-800E-CCFEEF017A41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A815C965-84FF-4880-800E-CCFEEF017A41}.Debug|Any CPU.Build.0 = Debug|Any CPU {A815C965-84FF-4880-800E-CCFEEF017A41}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -423,10 +428,6 @@ Global {30E75E1A-146F-422E-8C14-3AE0F7FB99B1}.Debug|Any CPU.Build.0 = Debug|Any CPU {30E75E1A-146F-422E-8C14-3AE0F7FB99B1}.Release|Any CPU.ActiveCfg = Release|Any CPU {30E75E1A-146F-422E-8C14-3AE0F7FB99B1}.Release|Any CPU.Build.0 = Release|Any CPU - {5D68956E-580F-4A2A-B13F-1477E6DE6FCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5D68956E-580F-4A2A-B13F-1477E6DE6FCF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5D68956E-580F-4A2A-B13F-1477E6DE6FCF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5D68956E-580F-4A2A-B13F-1477E6DE6FCF}.Release|Any CPU.Build.0 = Release|Any CPU {3B1E60AF-5B5C-4BED-8AAF-79167CF5E2C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3B1E60AF-5B5C-4BED-8AAF-79167CF5E2C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {3B1E60AF-5B5C-4BED-8AAF-79167CF5E2C0}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -527,10 +528,6 @@ Global {9A2200C2-46F7-447A-8B9C-40A81D03D0B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A2200C2-46F7-447A-8B9C-40A81D03D0B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A2200C2-46F7-447A-8B9C-40A81D03D0B6}.Release|Any CPU.Build.0 = Release|Any CPU - {FC343B26-4AB3-47E7-B9EE-9EFFF0E02C7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC343B26-4AB3-47E7-B9EE-9EFFF0E02C7D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC343B26-4AB3-47E7-B9EE-9EFFF0E02C7D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC343B26-4AB3-47E7-B9EE-9EFFF0E02C7D}.Release|Any CPU.Build.0 = Release|Any CPU {037EDB81-3473-4EF6-82A9-BCE5FAE1DE00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {037EDB81-3473-4EF6-82A9-BCE5FAE1DE00}.Debug|Any CPU.Build.0 = Debug|Any CPU {037EDB81-3473-4EF6-82A9-BCE5FAE1DE00}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -571,6 +568,14 @@ Global {FF482B6D-D459-413E-82E0-9175C44DA8BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF482B6D-D459-413E-82E0-9175C44DA8BA}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF482B6D-D459-413E-82E0-9175C44DA8BA}.Release|Any CPU.Build.0 = Release|Any CPU + {EB88412B-8523-4DA4-8FF9-CACECA0969E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB88412B-8523-4DA4-8FF9-CACECA0969E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB88412B-8523-4DA4-8FF9-CACECA0969E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB88412B-8523-4DA4-8FF9-CACECA0969E6}.Release|Any CPU.Build.0 = Release|Any CPU + {58C01CB8-B65A-44FE-9BE0-22929CD474A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58C01CB8-B65A-44FE-9BE0-22929CD474A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A397E49-CB4F-4348-9798-A7F2B5F276DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A397E49-CB4F-4348-9798-A7F2B5F276DA}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -604,9 +609,6 @@ Global {44D2EC83-4BC6-4C69-88BF-924A3FCAA1F6} = {354E69EA-9EA1-4F7E-A3C2-372DFB259C35} {B022D220-EEE7-4FBC-A7D5-FC00F16C1A36} = {354E69EA-9EA1-4F7E-A3C2-372DFB259C35} {C57A6AD0-A0AB-45F3-BC32-58E469CACC15} = {D913C0D3-85B9-4E89-82D6-8371FB6C99E7} - {02EB95BA-07BE-441F-ADC7-3363AC17814C} = {DB7A40EE-F469-4B87-A629-250BBB9ECC92} - {20FCFF4D-882F-4663-81F4-A146D17B62A0} = {2A7105AA-05B6-469A-93F5-719723A4D90D} - {4687771E-6F0E-40C8-8C0A-DEDC20260604} = {20FCFF4D-882F-4663-81F4-A146D17B62A0} {A815C965-84FF-4880-800E-CCFEEF017A41} = {9A3F55B8-E867-4EA2-B1FA-0C01DE79463E} {61B4DBCC-2F85-4F8F-9DF9-E5A4EC17334B} = {72E179CA-7AE6-412A-856D-7BD13838E8E3} {7B596434-1314-49F9-B31C-F09D9CC288E0} = {2A7105AA-05B6-469A-93F5-719723A4D90D} @@ -634,7 +636,6 @@ Global {3D078D4E-0437-4AD1-90DE-1FD858DA595B} = {99FFD9AA-7AEB-4A9D-881D-00B7277C3494} {74B31A58-28CB-4B90-B2A4-C64F339FC93D} = {99FFD9AA-7AEB-4A9D-881D-00B7277C3494} {30E75E1A-146F-422E-8C14-3AE0F7FB99B1} = {99FFD9AA-7AEB-4A9D-881D-00B7277C3494} - {5D68956E-580F-4A2A-B13F-1477E6DE6FCF} = {20FCFF4D-882F-4663-81F4-A146D17B62A0} {F31389F0-613B-48B1-AA99-6BFC3D8D7D1A} = {2A7105AA-05B6-469A-93F5-719723A4D90D} {3B1E60AF-5B5C-4BED-8AAF-79167CF5E2C0} = {F31389F0-613B-48B1-AA99-6BFC3D8D7D1A} {0D77E6F7-5D76-4DF0-BE57-BA459951CD2F} = {354E69EA-9EA1-4F7E-A3C2-372DFB259C35} @@ -663,7 +664,6 @@ Global {9357DAC0-2E7B-4394-AD43-305DE5AC2DF1} = {B485D7EE-B71A-41DE-9518-60F9B7FA8AE4} {6C2862AB-9938-4802-8B90-6454CE24198D} = {B485D7EE-B71A-41DE-9518-60F9B7FA8AE4} {9A2200C2-46F7-447A-8B9C-40A81D03D0B6} = {5A3FFD14-2258-4007-AC77-BAFB3B3EB26F} - {FC343B26-4AB3-47E7-B9EE-9EFFF0E02C7D} = {5A3FFD14-2258-4007-AC77-BAFB3B3EB26F} {037EDB81-3473-4EF6-82A9-BCE5FAE1DE00} = {72E179CA-7AE6-412A-856D-7BD13838E8E3} {23126211-23BF-4399-A227-6C609FB7505E} = {2A7105AA-05B6-469A-93F5-719723A4D90D} {70C54624-CAE5-4ED6-A087-88CD1470E2B7} = {23126211-23BF-4399-A227-6C609FB7505E} @@ -679,6 +679,11 @@ Global {ED92EBC6-C297-46AE-998B-155A26442AA5} = {CDCF2469-1668-4EB0-A73F-692115CF6776} {CA248700-A9E0-433E-98FE-4E1C6844811F} = {72E179CA-7AE6-412A-856D-7BD13838E8E3} {FF482B6D-D459-413E-82E0-9175C44DA8BA} = {5A3FFD14-2258-4007-AC77-BAFB3B3EB26F} + {E8EF00ED-01FA-4F51-A668-5AF8B6C0F09E} = {2A7105AA-05B6-469A-93F5-719723A4D90D} + {EB88412B-8523-4DA4-8FF9-CACECA0969E6} = {E8EF00ED-01FA-4F51-A668-5AF8B6C0F09E} + {58C01CB8-B65A-44FE-9BE0-22929CD474A2} = {72E179CA-7AE6-412A-856D-7BD13838E8E3} + {F3331DB3-C40A-4712-A545-EE5C628B0F39} = {92288F2D-DE57-4018-855B-BD7F2344265F} + {4A397E49-CB4F-4348-9798-A7F2B5F276DA} = {DB7A40EE-F469-4B87-A629-250BBB9ECC92} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EE24476B-9A4C-4146-B982-3461FAF8B3B0} diff --git a/Core.sln.DotSettings b/Core.sln.DotSettings index 20d15ded..c36b219f 100644 --- a/Core.sln.DotSettings +++ b/Core.sln.DotSettings @@ -47,7 +47,8 @@ IO LGPL MIT - MPL + MPL + MS OS False <Policy Inspect="True" Prefix="__" Suffix="" Style="aaBb"><ExtraRule Prefix="Command" Suffix="" Style="AaBb" /></Policy> diff --git a/GitVersion.yml b/GitVersion.yml index 7d2adb2e..ebd6e016 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,5 +1,7 @@ assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatchTag +tag-prefix: '^v?' +semantic-version-format: Loose major-version-bump-message: '\+semver:\s?(breaking|major)' minor-version-bump-message: '\+semver:\s?(feature|minor)' patch-version-bump-message: '\+semver:\s?(fix|patch)' @@ -7,112 +9,47 @@ no-bump-message: '\+semver:\s?(none|skip)' mode: ContinuousDeployment branches: feature: - mode: ContinuousDeployment - tag: feature.{BranchName} + mode: ContinuousDelivery + label: feature.{BranchName} increment: Minor - prevent-increment-of-merged-branch-version: false track-merge-target: false - regex: ^features?[/-] + regex: ^features?[\/-](?.+) + prevent-increment: + when-current-commit-tagged: false source-branches: - - develop - - main - - release - - feature - - support - - hotfix + - main tracks-release-branches: false is-release-branch: false - is-mainline: false + is-main-branch: false pre-release-weight: 30000 main: mode: ContinuousDeployment - tag: '' + label: '' increment: Patch - prevent-increment-of-merged-branch-version: true track-merge-target: false regex: ^master$|^main$ + prevent-increment: + when-current-commit-tagged: false source-branches: - - develop - - release + - develop + - release tracks-release-branches: false is-release-branch: false - is-mainline: true pre-release-weight: 55000 - develop: - mode: ContinuousDeployment - tag: alpha - increment: Minor - prevent-increment-of-merged-branch-version: false - track-merge-target: true - regex: ^dev(elop)?(ment)?$ - source-branches: [] - tracks-release-branches: true - is-release-branch: false - is-mainline: false - pre-release-weight: 0 - release: - mode: ContinuousDeployment - tag: beta - increment: None - prevent-increment-of-merged-branch-version: true - track-merge-target: false - regex: ^releases?[/-] - source-branches: - - develop - - main - - support - - release - tracks-release-branches: false - is-release-branch: true - is-mainline: false - pre-release-weight: 30000 pull-request: - mode: ContinuousDeployment - tag: PullRequest + mode: ContinuousDelivery + label: PR-{PullRequestName} increment: Inherit - prevent-increment-of-merged-branch-version: false - tag-number-pattern: '[/-](?\d+)' - track-merge-target: false - regex: ^(pull|pull\-requests|pr)[/-] - source-branches: - - develop - - main - - release - - feature - - support - - hotfix - tracks-release-branches: false - is-release-branch: false - is-mainline: false - pre-release-weight: 30000 - hotfix: - mode: ContinuousDeployment - tag: beta - increment: Patch - prevent-increment-of-merged-branch-version: false track-merge-target: false - regex: ^hotfix(es)?[/-] + regex: ^(pull|pull\-requests|pr)[/-](?.+) + prevent-increment: + when-current-commit-tagged: false source-branches: - - develop - - main - - support + - main + - feature tracks-release-branches: false is-release-branch: false - is-mainline: false pre-release-weight: 30000 - support: - mode: ContinuousDeployment - tag: '' - increment: Patch - prevent-increment-of-merged-branch-version: true - track-merge-target: false - regex: ^support[/-] - source-branches: - - main - tracks-release-branches: false - is-release-branch: false - is-mainline: true - pre-release-weight: 55000 ignore: - sha: [] -merge-message-formats: {} + sha: [ ] +merge-message-formats: { } diff --git a/build.ps1 b/build.ps1 index 4634dc03..1b91f63a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -13,12 +13,8 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent # CONFIGURATION ########################################################################### -$BuildProjectFile = "$PSScriptRoot\build\_build.csproj" -$TempDirectory = "$PSScriptRoot\\.nuke\temp" - +$BuildProjectFile = "$PSScriptRoot\build\Build.csproj" $DotNetGlobalFile = "$PSScriptRoot\\global.json" -$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" -$DotNetChannel = "STS" $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 $env:DOTNET_NOLOGO = 1 @@ -38,37 +34,12 @@ if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and ` $env:DOTNET_EXE = (Get-Command "dotnet").Path } else { - # Download install script - $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" - New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) - - # If global.json exists, load expected version - if (Test-Path $DotNetGlobalFile) { - $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) - if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { - $DotNetVersion = $DotNetGlobal.sdk.version - } - } + Write-Host "No matching dotnet version found" - # Install by channel or version - $DotNetDirectory = "$TempDirectory\dotnet-win" - if (!(Test-Path variable:DotNetVersion)) { - ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } - } else { - ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } - } - $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" - $env:PATH = "$DotNetDirectory;$env:PATH" + exit 1 } Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)" -if (Test-Path env:NUKE_ENTERPRISE_TOKEN) { - & $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null - & $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null -} - ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet } ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments } diff --git a/build.sh b/build.sh index fdff0c62..35eaabae 100755 --- a/build.sh +++ b/build.sh @@ -2,19 +2,15 @@ bash --version 2>&1 | head -n 1 -set -eo pipefail +set -e SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) ########################################################################### # CONFIGURATION ########################################################################### -BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj" -TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" - +BUILD_PROJECT_FILE="$SCRIPT_DIR/build/Build.csproj" DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" -DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" -DOTNET_CHANNEL="STS" export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_NOLOGO=1 @@ -23,45 +19,15 @@ export DOTNET_NOLOGO=1 # EXECUTION ########################################################################### -function FirstJsonValue { - perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}" -} - # If dotnet CLI is installed globally and it matches requested version, use for execution if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then export DOTNET_EXE="$(command -v dotnet)" else - # Download install script - DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" - mkdir -p "$TEMP_DIRECTORY" - curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" - chmod +x "$DOTNET_INSTALL_FILE" - - # If global.json exists, load expected version - if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then - DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")") - if [[ "$DOTNET_VERSION" == "" ]]; then - unset DOTNET_VERSION - fi - fi - - # Install by channel or version - DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" - if [[ -z ${DOTNET_VERSION+x} ]]; then - "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path - else - "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path - fi - export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" - export PATH="$DOTNET_DIRECTORY:$PATH" + echo "No matching dotnet version found" + exit 1 fi echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" -if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then - "$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true - "$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true -fi - "$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@" diff --git a/build/.editorconfig b/build/.editorconfig deleted file mode 100644 index 31e43dcd..00000000 --- a/build/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -[*.cs] -dotnet_style_qualification_for_field = false:warning -dotnet_style_qualification_for_property = false:warning -dotnet_style_qualification_for_method = false:warning -dotnet_style_qualification_for_event = false:warning -dotnet_style_require_accessibility_modifiers = never:warning - -csharp_style_expression_bodied_methods = true:silent -csharp_style_expression_bodied_properties = true:warning -csharp_style_expression_bodied_indexers = true:warning -csharp_style_expression_bodied_accessors = true:warning diff --git a/build/Build.cs b/build/Build.cs deleted file mode 100644 index c29722d2..00000000 --- a/build/Build.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using CreativeCoders.Core; -using CreativeCoders.Core.Collections; -using CreativeCoders.NukeBuild.BuildActions; -using CreativeCoders.NukeBuild.Components; -using CreativeCoders.NukeBuild.Components.Parameters; -using CreativeCoders.NukeBuild.Components.Targets; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.CI.GitHubActions; -using Nuke.Common.Execution; -using Nuke.Common.IO; -using Nuke.Common.ProjectModel; -using Serilog; - -#pragma warning disable S1144 // remove unused private members -#pragma warning disable S3903 // move class to namespace -[PublicAPI] -[UnsetVisualStudioEnvironmentVariables] -[GitHubActions("integration", - GitHubActionsImage.UbuntuLatest, GitHubActionsImage.WindowsLatest, GitHubActionsImage.MacOsLatest, - OnPushBranches = ["feature/**"], - InvokedTargets = [NukeTargets.DeployNuGet], - EnableGitHubToken = true, - PublishArtifacts = true, - PublishCondition = "runner.os == 'Linux'", - FetchDepth = 0 -)] -[GitHubActions("pull-request", - GitHubActionsImage.UbuntuLatest, GitHubActionsImage.WindowsLatest, GitHubActionsImage.MacOsLatest, - OnPullRequestBranches = ["main"], - InvokedTargets = [NukeTargets.Rebuild, NukeTargets.CodeCoverage, NukeTargets.Pack], - EnableGitHubToken = true, - PublishArtifacts = true, - PublishCondition = "runner.os == 'Linux'", - FetchDepth = 0 -)] -[GitHubActions("main", - GitHubActionsImage.UbuntuLatest, GitHubActionsImage.WindowsLatest, GitHubActionsImage.MacOsLatest, - OnPushBranches = ["main"], - InvokedTargets = [NukeTargets.DeployNuGet], - EnableGitHubToken = true, - PublishArtifacts = true, - PublishCondition = "runner.os == 'Linux'", - FetchDepth = 0 -)] -[GitHubActions(ReleaseWorkflow, GitHubActionsImage.UbuntuLatest, - OnPushTags = ["v**"], - InvokedTargets = [NukeTargets.DeployNuGet], - ImportSecrets = ["NUGET_ORG_TOKEN"], - EnableGitHubToken = true, - PublishArtifacts = true, - FetchDepth = 0 -)] -class Build : NukeBuild, - IGitRepositoryParameter, - IConfigurationParameter, - IGitVersionParameter, - ISourceDirectoryParameter, - IArtifactsSettings, - ICleanTarget, IBuildTarget, IRestoreTarget, ICodeCoverageTarget, IPushNuGetTarget, IRebuildTarget, - IDeployNuGetTarget -{ - public const string ReleaseWorkflow = "release"; - - readonly GitHubActions GitHubActions = GitHubActions.Instance; - - [Parameter(Name = "GITHUB_TOKEN")] string DevNuGetApiKey; - - [Parameter(Name = "NUGET_ORG_TOKEN")] string NuGetOrgApiKey; - - IList ICleanSettings.DirectoriesToClean => - this.As().DefaultDirectoriesToClean - .AddRange(this.As().TestBaseDirectory); - - public IEnumerable TestProjects => GetTestProjects(); - - bool IPushNuGetSettings.SkipPush => GitHubActions?.IsPullRequest == true || - !(GitHubActions.IsLocalBuild() || GitHubActions?.GetRunnerOs() == GitHubActionsRunnerOs.Linux); - - string IPushNuGetSettings.NuGetFeedUrl => - GitHubActions?.Workflow == ReleaseWorkflow - ? "nuget.org" - : "https://nuget.pkg.github.com/CreativeCodersTeam/index.json"; - - string IPushNuGetSettings.NuGetApiKey => - GitHubActions?.Workflow == ReleaseWorkflow - ? NuGetOrgApiKey - : DevNuGetApiKey; - - string IPackSettings.PackageProjectUrl => "https://github.com/CreativeCodersTeam/Core"; - - string IPackSettings.PackageLicenseExpression => PackageLicenseExpressions.ApacheLicense20; - - string IPackSettings.Copyright => $"{DateTime.Now.Year} CreativeCoders"; - - Project[] GetTestProjects() => - this.TryAs(out var solutionParameter) - ? solutionParameter.Solution.GetAllProjects("*") - .Where(x => ((string)x.Path)?.StartsWith(RootDirectory / "tests") ?? false).ToArray() - : []; - - public static int Main() => Execute(x => ((ICodeCoverageTarget)x).CodeCoverage); - - protected override void OnBuildInitialized() - { - base.OnBuildInitialized(); - - Log.Information("Build initialized"); - Log.Information("Skip Nuget Push: {SkipPush}", (this as IPushNuGetSettings).SkipPush); - - } -} diff --git a/build/Build.csproj b/build/Build.csproj new file mode 100644 index 00000000..858d37ec --- /dev/null +++ b/build/Build.csproj @@ -0,0 +1,14 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + diff --git a/build/BuildContext.cs b/build/BuildContext.cs new file mode 100644 index 00000000..b41eeabd --- /dev/null +++ b/build/BuildContext.cs @@ -0,0 +1,33 @@ +using Cake.Common.Build; +using Cake.Core; +using Cake.Core.IO; +using CreativeCoders.CakeBuild; +using CreativeCoders.CakeBuild.Tasks.Defaults; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; +using CreativeCoders.Core; +using CreativeCoders.Core.Collections; +using JetBrains.Annotations; + +namespace Build; + +[UsedImplicitly] +public class BuildContext(ICakeContext context) : CakeBuildContext(context), IDefaultTaskSettings +{ + public IList DirectoriesToClean => this.CastAs() + .GetDefaultDirectoriesToClean().AddRange(RootDir.Combine(".tests")); + + + public string Copyright => $"{DateTime.Now.Year} CreativeCoders"; + + public string PackageProjectUrl => "https://github.com/CreativeCodersTeam/Core"; + + public string PackageLicenseExpression => PackageLicenseExpressions.ApacheLicense20; + + public string NuGetFeedUrl => this.GitHubActions().Environment.Workflow.Workflow == "release" + ? "nuget.org" + : "https://nuget.pkg.github.com/CreativeCodersTeam/index.json"; + + public bool SkipPush => this.BuildSystem().IsPullRequest || + this.BuildSystem().IsLocalBuild || + this.GitHubActions().Environment.Runner.OS != "Linux"; +} diff --git a/build/Directory.Build.props b/build/Directory.Build.props deleted file mode 100644 index e147d635..00000000 --- a/build/Directory.Build.props +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/build/Directory.Build.targets b/build/Directory.Build.targets deleted file mode 100644 index 25326095..00000000 --- a/build/Directory.Build.targets +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/build/Program.cs b/build/Program.cs new file mode 100644 index 00000000..34637f16 --- /dev/null +++ b/build/Program.cs @@ -0,0 +1,19 @@ +using CreativeCoders.CakeBuild; + +namespace Build; + +internal static class Program +{ + internal static int Main(string[] args) + { + return CakeHostBuilder.Create() + .UseBuildContext() + .AddDefaultTasks() + .AddBuildServerIntegration() + .InstallTools( + new DotNetToolInstallation("GitVersion.Tool", "6.5.1"), + new DotNetToolInstallation("dotnet-reportgenerator-globaltool", "5.5.1")) + .Build() + .Run(args); + } +} diff --git a/build/_build.csproj b/build/_build.csproj deleted file mode 100644 index 3cd974b1..00000000 --- a/build/_build.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - Exe - net10.0 - - CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 - .. - .. - 1 - false - - - - - - - - - - - - - - diff --git a/build/_build.csproj.DotSettings b/build/_build.csproj.DotSettings deleted file mode 100644 index c815d363..00000000 --- a/build/_build.csproj.DotSettings +++ /dev/null @@ -1,31 +0,0 @@ - - DO_NOT_SHOW - DO_NOT_SHOW - DO_NOT_SHOW - DO_NOT_SHOW - DO_NOT_SHOW - Implicit - Implicit - ExpressionBody - 0 - NEXT_LINE - True - False - 120 - IF_OWNER_IS_SINGLE_LINE - WRAP_IF_LONG - False - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy><Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"><ElementKinds><Kind Name="FIELD" /><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> - <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"><ElementKinds><Kind Name="FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> - True - True - True - True - True - True - True - True - True - True diff --git a/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj b/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj index 686eabe4..3fc58281 100644 --- a/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj +++ b/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj @@ -5,10 +5,9 @@ - - - - + + + diff --git a/samples/CakeBuildSample/CakeBuildSample.csproj b/samples/CakeBuildSample/CakeBuildSample.csproj new file mode 100644 index 00000000..d9b57ee9 --- /dev/null +++ b/samples/CakeBuildSample/CakeBuildSample.csproj @@ -0,0 +1,20 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + + + diff --git a/samples/CakeBuildSample/Program.cs b/samples/CakeBuildSample/Program.cs new file mode 100644 index 00000000..cf6eea31 --- /dev/null +++ b/samples/CakeBuildSample/Program.cs @@ -0,0 +1,24 @@ +using Cake.Core.IO; +using Cake.DotNetTool.Module; +using Cake.Frosting; +using CreativeCoders.CakeBuild; +using CreativeCoders.Core.IO; +using CreativeCoders.Core.SysEnvironment; + +namespace CakeBuildSample; + +internal static class Program +{ + static int Main(string[] args) + { + return CakeHostBuilder.Create() + .UseBuildContext() + .AddDefaultTasks() + .AddBuildServerIntegration() + .InstallTools( + new DotNetToolInstallation("GitVersion.Tool", "6.5.1"), + new DotNetToolInstallation("dotnet-reportgenerator-globaltool", "5.5.1")) + .Build() + .Run(args); + } +} diff --git a/samples/CakeBuildSample/SampleBuildContext.cs b/samples/CakeBuildSample/SampleBuildContext.cs new file mode 100644 index 00000000..398b52bb --- /dev/null +++ b/samples/CakeBuildSample/SampleBuildContext.cs @@ -0,0 +1,33 @@ +using Cake.Common.Build; +using Cake.Core; +using Cake.Core.IO; +using CreativeCoders.CakeBuild; +using CreativeCoders.CakeBuild.Tasks.Defaults; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; +using CreativeCoders.Core; +using CreativeCoders.Core.Collections; +using JetBrains.Annotations; + +namespace CakeBuildSample; + +[UsedImplicitly] +public class SampleBuildContext(ICakeContext context) : CakeBuildContext(context), IDefaultTaskSettings +{ + public IList DirectoriesToClean => this.CastAs() + .GetDefaultDirectoriesToClean().AddRange(RootDir.Combine(".tests")); + + + public string Copyright => $"{DateTime.Now.Year} CreativeCoders"; + + public string PackageProjectUrl => "https://github.com/CreativeCodersTeam/Core"; + + public string PackageLicenseExpression => PackageLicenseExpressions.ApacheLicense20; + + public string NuGetFeedUrl => this.GitHubActions().Environment.Workflow.Workflow == "release" + ? "nuget.org" + : "https://nuget.pkg.github.com/CreativeCodersTeam/index.json"; + + public bool SkipPush => this.BuildSystem().IsPullRequest || + this.BuildSystem().IsLocalBuild || + this.GitHubActions().Environment.Runner.OS != "Linux"; +} diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj index 09f4151b..63c40571 100644 --- a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj +++ b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj @@ -10,10 +10,6 @@ - - - - diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/BuildServer/EndGroupTaskTeardown.cs b/source/CakeBuild/CreativeCoders.CakeBuild/BuildServer/EndGroupTaskTeardown.cs new file mode 100644 index 00000000..9490e08d --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/BuildServer/EndGroupTaskTeardown.cs @@ -0,0 +1,22 @@ +using Cake.Common.Build; +using Cake.Common.Diagnostics; +using Cake.Core; +using Cake.Frosting; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild.BuildServer; + +[UsedImplicitly] +public class EndGroupTaskTeardown : IFrostingTaskTeardown +{ + void IFrostingTaskTeardown.Teardown(ICakeContext context, ITaskTeardownContext info) + { + if (!context.GitHubActions().IsRunningOnGitHubActions) + { + return; + } + + context.Information(""); + context.GitHubActions().Commands.EndGroup(); + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/BuildServer/StartGroupTaskSetup.cs b/source/CakeBuild/CreativeCoders.CakeBuild/BuildServer/StartGroupTaskSetup.cs new file mode 100644 index 00000000..ff3c0586 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/BuildServer/StartGroupTaskSetup.cs @@ -0,0 +1,22 @@ +using Cake.Common.Build; +using Cake.Common.Diagnostics; +using Cake.Core; +using Cake.Frosting; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild.BuildServer; + +[UsedImplicitly] +public class StartGroupTaskSetup : IFrostingTaskSetup +{ + void IFrostingTaskSetup.Setup(ICakeContext context, ITaskSetupContext info) + { + if (!context.GitHubActions().IsRunningOnGitHubActions) + { + return; + } + + context.Information(""); + context.GitHubActions().Commands.StartGroup(info.Task.Name); + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/CakeBuildContext.cs b/source/CakeBuild/CreativeCoders.CakeBuild/CakeBuildContext.cs new file mode 100755 index 00000000..b1997cb6 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/CakeBuildContext.cs @@ -0,0 +1,137 @@ +using Cake.Common.Build; +using Cake.Common.Diagnostics; +using Cake.Common.Tools.GitVersion; +using Cake.Core; +using Cake.Core.IO; +using Cake.Frosting; +using CreativeCoders.Core.IO; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public class CakeBuildContext : FrostingContext, ICakeBuildContext, IBuildContextAccessor +{ + private readonly List _executedTasks = []; + + public CakeBuildContext(ICakeContext context) + : base(context) + { + RootDir = FindGitRootPath(context.Environment.WorkingDirectory) ?? + context.Environment.WorkingDirectory.GetParent(); + + var solutionsFilePath = context.Arguments.GetArgument("solution"); + SolutionFile = string.IsNullOrWhiteSpace(solutionsFilePath) + ? FindRootSolution(context) + : new FilePath(solutionsFilePath); + } + + private DirectoryPath? FindGitRootPath(DirectoryPath? startPath) + { + while (true) + { + if (startPath == null) + { + return null; + } + + if (FileSystem.Exist(startPath.Combine(".git"))) + { + return startPath; + } + + startPath = startPath.GetParent(); + } + } + + private FilePath FindRootSolution(ICakeContext context) + { + var solutionsFiles = + FileSys.Directory.EnumerateFiles(RootDir.FullPath, "*.sln", SearchOption.AllDirectories); + + var solutionsSlnxFiles = + FileSys.Directory.EnumerateFiles(RootDir.FullPath, "*.slnx", SearchOption.AllDirectories); + + var solutions = solutionsFiles.Concat(solutionsSlnxFiles).ToArray(); + + if (solutions.Length > 1) + { + context.Error("Multiple solution files found."); + } + + var solution = solutions.FirstOrDefault(); + + if (solution != null) + { + return solution; + } + + context.Error("No solution file found."); + + throw new InvalidOperationException("No solution file found"); + } + + public FilePath SolutionFile { get; } + + public DirectoryPath RootDir { get; } + + public virtual DirectoryPath ArtifactsDir => RootDir.Combine(".artifacts"); + + public virtual DirectoryPath TestOutputBasePath => RootDir.Combine(".tests"); + + public virtual DirectoryPath TestResultsDir => TestOutputBasePath.Combine("results"); + + public virtual DirectoryPath CodeCoverageDir => TestOutputBasePath.Combine("coverage"); + + public virtual DirectoryPath CodeCoverageReportDir => TestOutputBasePath.Combine("coverage-report"); + + public virtual string BuildConfiguration => this.BuildSystem().IsLocalBuild ? "Debug" : "Release"; + + public GitVersion Version => this.GetGitVersionSafe(); + + public IList ExecutedTasks => _executedTasks; + + public bool PrintSetupSummary => true; + + public void AddExecutedTask(IFrostingTask task) + { + _executedTasks.Add(task); + } + + public bool HasExecutedTask(Type taskType) + { + return _executedTasks.Any(x => x.GetType().IsAssignableTo(taskType)); + } + + public T GetRequiredSettings() + where T : class + { + return GetSettings() + ?? throw new InvalidOperationException($"No settings of type '{typeof(T).Name}' found"); + } + + public T? GetSettings() + where T : class + { + return this as T + ?? FindSettingsProperty() + ?? null; + } + + private T? FindSettingsProperty() + where T : class + { + var matchingProperties = GetType() + .GetProperties() + .Where(x => x.PropertyType == typeof(T) || + x.PropertyType.GetInterfaces().Any(intfType => + intfType == typeof(T))); + + return matchingProperties + .Select(x => x.GetValue(this)) + .OfType() + .FirstOrDefault(); + } + + public ICakeBuildContext Context => this; +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/CakeContextExtensions.cs b/source/CakeBuild/CreativeCoders.CakeBuild/CakeContextExtensions.cs new file mode 100755 index 00000000..06b3eb9b --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/CakeContextExtensions.cs @@ -0,0 +1,35 @@ +using Cake.Common.Diagnostics; +using Cake.Common.Tools.GitVersion; +using Cake.Core; +using Cake.Frosting; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public static class CakeContextExtensions +{ + public static bool TaskHasRun(this CakeBuildContext context) + where TTask : IFrostingTask + { + return context.ExecutedTasks.Any(x => x.GetType() == typeof(TTask)); + } + + public static GitVersion GetGitVersionSafe(this ICakeContext context, + string? major = null, string? minor = null, string? patch = null, string? build = null, + GitVersionSettings? gitVersionSettings = null) + { + try + { + return gitVersionSettings == null + ? context.GitVersion() + : context.GitVersion(gitVersionSettings); + } + catch (Exception e) + { + context.Warning("GitVersion failed. Using fallback version. Reason: {0}", e.Message); + + return StaticGitVersion.Create(major ?? "0", minor ?? "0", patch ?? "0", build ?? "1", ""); + } + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/CakeHostBuilder.cs b/source/CakeBuild/CreativeCoders.CakeBuild/CakeHostBuilder.cs new file mode 100644 index 00000000..54d777fc --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/CakeHostBuilder.cs @@ -0,0 +1,128 @@ +using Cake.Common.Diagnostics; +using Cake.Core; +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; +using CreativeCoders.Core; +using CreativeCoders.Core.IO; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +public class CakeHostBuilder : ICakeHostBuilder +{ + private readonly CakeHost _cakeHost = new CakeHost(); + + private bool _buildContextIsSet; + + public static ICakeHostBuilder Create() + { + return new CakeHostBuilder(); + } + + public ICakeHostBuilder UseBuildContext() + where TBuildContext : CakeBuildContext + { + _buildContextIsSet = true; + + _cakeHost.UseContext(); + + return this; + } + + public ICakeHostBuilder InstallTools(params ToolInstallation[] tools) + { + var tempToolsPath = FileSys.Path.Combine(FileSys.Path.GetTempPath(), ".cake-tools"); + + _cakeHost.SetToolPath(tempToolsPath); + + foreach (var tool in tools) + { + _cakeHost.InstallTool(new Uri($"{tool.ToolKind}:?package={tool.Name}&version={tool.Version}")); + } + + return this; + } + + public ICakeHostBuilder AddBuildServerIntegration() + { + _cakeHost.AddBuildServerIntegration(); + + return this; + } + + public ICakeHostBuilder AddDefaultTasks() + { + _cakeHost.AddDefaultTasks(); + + return this; + } + + public ICakeHostBuilder AddTask() + where TTask : class, IFrostingTask + { + _cakeHost.AddTask(); + + return this; + } + + public ICakeHostBuilder AddTasks(params Type[] taskTypes) + { + _cakeHost.AddTasks(taskTypes); + + return this; + } + + public ICakeHostBuilder ConfigureHost(Action configure) + { + Ensure.NotNull(configure); + + configure(_cakeHost); + + return this; + } + + public CakeHost Build() + { + if (!_buildContextIsSet) + { + _cakeHost.UseContext(); + } + + _cakeHost.UseSetup(); + + return _cakeHost; + } +} + +[UsedImplicitly] +public class DefaultHostSetup : IFrostingSetup +{ + public void Setup(ICakeContext context, ISetupContext info) + { + if (context is not CakeBuildContext buildContext) + { + return; + } + + if (!buildContext.PrintSetupSummary) + { + return; + } + + var pushSettings = buildContext.GetSettings(); + + if (pushSettings != null) + { + context.Information($"Skip Push: {pushSettings.SkipPush}"); + } + + var version = buildContext.Version; + + context.Information("Version Info"); + + context.Information($"Informational Version: {version.InformationalVersion}"); + context.Information($"Assembly Version: {version.AssemblySemVer}"); + context.Information($"File Version: {version.AssemblySemFileVer}"); + context.Information($"Package Version: {version.SemVer}"); + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/CakeHostExtensions.cs b/source/CakeBuild/CreativeCoders.CakeBuild/CakeHostExtensions.cs new file mode 100755 index 00000000..edb6dcbf --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/CakeHostExtensions.cs @@ -0,0 +1,113 @@ +using System.Reflection; +using Cake.Frosting; +using CreativeCoders.CakeBuild.BuildServer; +using CreativeCoders.CakeBuild.Tasks.Defaults; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; +using JetBrains.Annotations; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public static class CakeHostExtensions +{ + public static CakeHost AddTask(this CakeHost host) + where TTask : class, IFrostingTask + { + ArgumentNullException.ThrowIfNull(host); + + return host.ConfigureServices(x => x.AddSingleton()); + } + + public static CakeHost AddTask(this CakeHost host, TTaskSettings taskSettings) + where TTask : class, IFrostingTask + where TTaskSettings : class + { + ArgumentNullException.ThrowIfNull(host); + + return host.ConfigureServices(x => + { + x.AddSingleton(); + + x.TryAddSingleton(taskSettings); + } + ); + } + + public static CakeHost AddTasks(this CakeHost host, params Type[] taskTypes) + { + ArgumentNullException.ThrowIfNull(host); + ArgumentNullException.ThrowIfNull(taskTypes); + + return host.ConfigureServices(x => + { + foreach (var taskType in taskTypes) + { + if (!typeof(IFrostingTask).IsAssignableFrom(taskType)) + { + throw new InvalidOperationException( + $"Type '{taskType.FullName}' does not implement '{nameof(IFrostingTask)}'."); + } + + x.AddSingleton(typeof(IFrostingTask), taskType); + } + }); + } + + public static CakeHost AddDefaultTasks(this CakeHost host) + { + return host.AddTasks( + typeof(CleanTask), + typeof(RestoreTask), + typeof(BuildTask), + typeof(TestTask), + typeof(CodeCoverageTask), + typeof(PackTask), + typeof(NuGetPushTask)); + } + + public static CakeHost AddBuildServerIntegration(this CakeHost host) + { + return host + .UseTaskSetup() + .UseTaskTeardown(); + } + + public static CakeHost SetupHost(this CakeHost host) + where TBuildSetup : class + where TBuildContext : CakeBuildContext + { + return host + .UseContext() + .UseBuildSetup(); + } + + public static CakeHost UseBuildSetup(this CakeHost host) + where TBuildSetup : class + { + host.ConfigureServices(services => + { + services.AddSingleton(); + services.AddSettingsInterfacesFor(typeof(TBuildSetup), typeof(TBuildSetup)); + }); + + return host; + } + + private static void AddSettingsInterfacesFor(this IServiceCollection services, Type type, + Type buildSetupType) + { + var interfaceTypes = type.GetInterfaces(); + + foreach (var interfaceType in interfaceTypes) + { + if (interfaceType.GetCustomAttribute() is not null) + { + services.AddSingleton(interfaceType, sp => sp.GetRequiredService(buildSetupType)); + } + + services.AddSettingsInterfacesFor(interfaceType, buildSetupType); + } + } +} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/CreativeCoders.NukeBuild.csproj b/source/CakeBuild/CreativeCoders.CakeBuild/CreativeCoders.CakeBuild.csproj similarity index 55% rename from source/NukeBuild/CreativeCoders.NukeBuild/CreativeCoders.NukeBuild.csproj rename to source/CakeBuild/CreativeCoders.CakeBuild/CreativeCoders.CakeBuild.csproj index 88dacedf..69c651f0 100644 --- a/source/NukeBuild/CreativeCoders.NukeBuild/CreativeCoders.NukeBuild.csproj +++ b/source/CakeBuild/CreativeCoders.CakeBuild/CreativeCoders.CakeBuild.csproj @@ -1,12 +1,13 @@  - Library - Nuke build extensions + net10.0 + enable + enable - + diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/DotNetMSBuildSettingsExtensions.cs b/source/CakeBuild/CreativeCoders.CakeBuild/DotNetMSBuildSettingsExtensions.cs new file mode 100644 index 00000000..9d5b24e4 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/DotNetMSBuildSettingsExtensions.cs @@ -0,0 +1,47 @@ +using Cake.Common.Tools.DotNet.MSBuild; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public static class DotNetMSBuildSettingsExtensions +{ + public static DotNetMSBuildSettings WithPackageProjectUrl(this DotNetMSBuildSettings settings, + string packageProjectUrl) + { + return settings.SetPropertyIfNotEmpty("PackageProjectUrl", packageProjectUrl); + } + + public static DotNetMSBuildSettings WithPackageLicenseUrl(this DotNetMSBuildSettings settings, + string packageLicenseUrl) + { + return settings.SetPropertyIfNotEmpty("PackageLicenseUrl", packageLicenseUrl); + } + + public static DotNetMSBuildSettings WithPackageLicenseExpression(this DotNetMSBuildSettings settings, + string packageLicenseExpression) + { + return settings.SetPropertyIfNotEmpty("PackageLicenseExpression", packageLicenseExpression); + } + + public static DotNetMSBuildSettings WithCopyright(this DotNetMSBuildSettings settings, string copyright) + { + return settings.SetPropertyIfNotEmpty("Copyright", copyright); + } + + public static DotNetMSBuildSettings SetProperty(this DotNetMSBuildSettings settings, string propertyName, + string propertyValue) + { + settings.Properties[propertyName] = [propertyValue]; + return settings; + } + + public static DotNetMSBuildSettings SetPropertyIfNotEmpty(this DotNetMSBuildSettings settings, + string propertyName, + string? propertyValue) + { + return string.IsNullOrEmpty(propertyValue) + ? settings + : settings.SetProperty(propertyName, propertyValue); + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/DotNetToolInstallation.cs b/source/CakeBuild/CreativeCoders.CakeBuild/DotNetToolInstallation.cs new file mode 100644 index 00000000..7c672625 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/DotNetToolInstallation.cs @@ -0,0 +1,6 @@ +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public class DotNetToolInstallation(string name, string version) : ToolInstallation("dotnet", name, version); diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/IBuildContextAccessor.cs b/source/CakeBuild/CreativeCoders.CakeBuild/IBuildContextAccessor.cs new file mode 100644 index 00000000..fe5ec9ab --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/IBuildContextAccessor.cs @@ -0,0 +1,6 @@ +namespace CreativeCoders.CakeBuild; + +public interface IBuildContextAccessor +{ + ICakeBuildContext Context { get; } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/ICakeBuildContext.cs b/source/CakeBuild/CreativeCoders.CakeBuild/ICakeBuildContext.cs new file mode 100644 index 00000000..26990553 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/ICakeBuildContext.cs @@ -0,0 +1,40 @@ +using Cake.Common.Tools.GitVersion; +using Cake.Core; +using Cake.Core.IO; +using Cake.Frosting; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public interface ICakeBuildContext : ICakeContext +{ + FilePath SolutionFile { get; } + + DirectoryPath RootDir { get; } + + DirectoryPath ArtifactsDir { get; } + + DirectoryPath TestOutputBasePath { get; } + + DirectoryPath TestResultsDir { get; } + + DirectoryPath CodeCoverageDir { get; } + + DirectoryPath CodeCoverageReportDir { get; } + + string BuildConfiguration { get; } + + GitVersion Version { get; } + + bool PrintSetupSummary { get; } + + IList ExecutedTasks { get; } + + void AddExecutedTask(IFrostingTask task); + + bool HasExecutedTask(Type taskType); + + T GetRequiredSettings() + where T : class; +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/ICakeHostBuilder.cs b/source/CakeBuild/CreativeCoders.CakeBuild/ICakeHostBuilder.cs new file mode 100644 index 00000000..1a0978f8 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/ICakeHostBuilder.cs @@ -0,0 +1,26 @@ +using Cake.Frosting; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public interface ICakeHostBuilder +{ + ICakeHostBuilder AddBuildServerIntegration(); + + ICakeHostBuilder AddDefaultTasks(); + + ICakeHostBuilder AddTask() + where TTask : class, IFrostingTask; + + ICakeHostBuilder AddTasks(params Type[] taskTypes); + + ICakeHostBuilder ConfigureHost(Action configure); + + ICakeHostBuilder UseBuildContext() + where TBuildContext : CakeBuildContext; + + ICakeHostBuilder InstallTools(params ToolInstallation[] tools); + + CakeHost Build(); +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/NuGetToolInstallation.cs b/source/CakeBuild/CreativeCoders.CakeBuild/NuGetToolInstallation.cs new file mode 100644 index 00000000..e29dfe5c --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/NuGetToolInstallation.cs @@ -0,0 +1,6 @@ +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild; + +[PublicAPI] +public class NuGetToolInstallation(string name, string version) : ToolInstallation("nuget", name, version); diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/StaticGitVersion.cs b/source/CakeBuild/CreativeCoders.CakeBuild/StaticGitVersion.cs new file mode 100755 index 00000000..7fb903df --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/StaticGitVersion.cs @@ -0,0 +1,40 @@ +using Cake.Common.Tools.GitVersion; + +namespace CreativeCoders.CakeBuild; + +public static class StaticGitVersion +{ + public static GitVersion Create(string major, string minor, string patch, string build, + string preReleaseTag) + { + var version = $"{major}.{minor}.{patch}.{build}"; + var versionWithPreRelease = string.IsNullOrWhiteSpace(preReleaseTag) + ? version + : $"{version}-{preReleaseTag}"; + + return new GitVersion + { + Major = int.Parse(major), + Minor = int.Parse(minor), + Patch = int.Parse(patch), + PreReleaseTag = preReleaseTag, + BuildMetaData = build, + AssemblySemVer = versionWithPreRelease, + FullSemVer = versionWithPreRelease, + AssemblySemFileVer = version, + BranchName = "unknown", + InformationalVersion = versionWithPreRelease, + MajorMinorPatch = $"{major}.{minor}.{patch}", + LegacySemVer = versionWithPreRelease, + NuGetVersion = versionWithPreRelease, + NuGetVersionV2 = versionWithPreRelease, + PreReleaseLabel = preReleaseTag, + SemVer = versionWithPreRelease, + NuGetPreReleaseTag = preReleaseTag, + NuGetPreReleaseTagV2 = preReleaseTag, + CommitDate = DateTimeOffset.Now.ToString(), + PreReleaseTagWithDash = $"-{preReleaseTag}", + PreReleaseLabelWithDash = $"-{preReleaseTag}" + }; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/BuildTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/BuildTask.cs new file mode 100755 index 00000000..f58f0c69 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/BuildTask.cs @@ -0,0 +1,8 @@ +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +[TaskName("Build")] +[IsDependentOn(typeof(RestoreTask))] +public class BuildTask : BuildTask; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/CleanTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/CleanTask.cs new file mode 100644 index 00000000..9fc7d34d --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/CleanTask.cs @@ -0,0 +1,7 @@ +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +[TaskName("Clean")] +public class CleanTask : CleanTask; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/CodeCoverageTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/CodeCoverageTask.cs new file mode 100644 index 00000000..1469fd88 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/CodeCoverageTask.cs @@ -0,0 +1,8 @@ +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +[TaskName("CodeCoverage")] +[IsDependentOn(typeof(TestTask))] +public class CodeCoverageTask : CodeCoverageTask; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/IDefaultTaskSettings.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/IDefaultTaskSettings.cs new file mode 100644 index 00000000..60885f0f --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/IDefaultTaskSettings.cs @@ -0,0 +1,10 @@ +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +public interface IDefaultTaskSettings : + ICleanTaskSettings, + ITestTaskSettings, + ICodeCoverageTaskSettings, + IPackTaskSettings, + INuGetPushTaskSettings; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/NuGetPushTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/NuGetPushTask.cs new file mode 100644 index 00000000..9706cf88 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/NuGetPushTask.cs @@ -0,0 +1,8 @@ +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +[TaskName("NuGetPush")] +[IsDependentOn(typeof(PackTask))] +public class NuGetPushTask : NuGetPushTask; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/PackTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/PackTask.cs new file mode 100644 index 00000000..452bbe86 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/PackTask.cs @@ -0,0 +1,8 @@ +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +[TaskName("Pack")] +[IsDependentOn(typeof(CodeCoverageTask))] +public class PackTask : PackTask; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/RestoreTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/RestoreTask.cs new file mode 100755 index 00000000..6d4d5a96 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/RestoreTask.cs @@ -0,0 +1,8 @@ +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +[TaskName("Restore")] +[IsDependentOn(typeof(CleanTask))] +public class RestoreTask : RestoreTask; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/TestTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/TestTask.cs new file mode 100644 index 00000000..780a6e81 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Defaults/TestTask.cs @@ -0,0 +1,8 @@ +using Cake.Frosting; +using CreativeCoders.CakeBuild.Tasks.Templates; + +namespace CreativeCoders.CakeBuild.Tasks.Defaults; + +[TaskName("Test")] +[IsDependentOn(typeof(BuildTask))] +public class TestTask : TestTask; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/FrostingTaskBase.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/FrostingTaskBase.cs new file mode 100755 index 00000000..3f174630 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/FrostingTaskBase.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using Cake.Common.Diagnostics; +using Cake.Frosting; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild.Tasks; + +[PublicAPI] +public abstract class FrostingTaskBase : AsyncFrostingTask + where T : CakeBuildContext +{ + public sealed override async Task RunAsync(T context) + { + var taskName = ReadTaskName(); + + context.Information($"Running task '{taskName}' ..."); + + await RunAsyncCore(context).ConfigureAwait(false); + } + + protected string ReadTaskName() + { + var taskNameAttr = GetType().GetCustomAttribute(); + + return taskNameAttr?.Name ?? GetType().Name; + } + + protected abstract Task RunAsyncCore(T context); + + public override void Finally(T context) + { + base.Finally(context); + + context.AddExecutedTask(this); + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/BuildTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/BuildTask.cs new file mode 100755 index 00000000..755cb13e --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/BuildTask.cs @@ -0,0 +1,60 @@ +using Cake.Common.Diagnostics; +using Cake.Common.Tools.DotNet; +using Cake.Common.Tools.DotNet.Build; +using Cake.Common.Tools.DotNet.MSBuild; +using Cake.Core.Diagnostics; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild.Tasks.Templates; + +[PublicAPI] +public class BuildTask : FrostingTaskBase + where T : CakeBuildContext +{ + protected virtual void ApplyDotNetBuildSettings(T context, DotNetBuildSettings dotNetBuildSettings) { } + + private DotNetBuildSettings CreateDotNetBuildSettings(T context) + { + var dotNetBuildSettings = new DotNetBuildSettings + { + Configuration = context.BuildConfiguration, + NoRestore = context.HasExecutedTask(typeof(RestoreTask)), + NoIncremental = true, + MSBuildSettings = new DotNetMSBuildSettings + { + InformationalVersion = context.Version.InformationalVersion, + AssemblyVersion = context.Version.AssemblySemVer, + FileVersion = context.Version.AssemblySemFileVer, + PackageVersion = context.Version.SemVer, + Version = context.Version.SemVer + } + }; + + ApplyDotNetBuildSettings(context, dotNetBuildSettings); + + if (dotNetBuildSettings.NoRestore) + { + context.Information("Skip restore"); + } + + return dotNetBuildSettings; + } + + protected override Task RunAsyncCore(T context) + { + var dotnetSettings = CreateDotNetBuildSettings(context); + + context.Log.Information("Building solution {0} with configuration {1}", + context.SolutionFile.FullPath, dotnetSettings.Configuration); + + context.Information("Build with informational version: " + + dotnetSettings.MSBuildSettings.InformationalVersion); + context.Information("Build with assembly version: " + dotnetSettings.MSBuildSettings.AssemblyVersion); + context.Information("Build with file version: " + dotnetSettings.MSBuildSettings.FileVersion); + context.Information("Build with package version: " + dotnetSettings.MSBuildSettings.PackageVersion); + + context.DotNetBuild(context.SolutionFile.FullPath, dotnetSettings); + + return Task.CompletedTask; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/CleanTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/CleanTask.cs new file mode 100755 index 00000000..e35304a5 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/CleanTask.cs @@ -0,0 +1,30 @@ +using Cake.Common.Diagnostics; +using Cake.Common.Tools.DotNet; +using Cake.Core.IO; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +namespace CreativeCoders.CakeBuild.Tasks.Templates; + +public class CleanTask : FrostingTaskBase where T : CakeBuildContext +{ + protected override Task RunAsyncCore(T context) + { + var settings = context.GetRequiredSettings(); + + DeleteDirectories(context, settings.DirectoriesToClean); + + context.DotNetClean(context.SolutionFile.FullPath); + + return Task.CompletedTask; + } + + private static void DeleteDirectories(T context, IEnumerable dirsForDelete) + { + foreach (var dir in dirsForDelete.Where(dir => context.FileSystem.GetDirectory(dir).Exists)) + { + context.Information("Deleting directory '{0}'", dir); + + context.FileSystem.GetDirectory(dir).Delete(true); + } + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/CodeCoverageTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/CodeCoverageTask.cs new file mode 100755 index 00000000..3ef801b5 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/CodeCoverageTask.cs @@ -0,0 +1,24 @@ +using Cake.Common.Tools.ReportGenerator; +using Cake.Core.IO; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +namespace CreativeCoders.CakeBuild.Tasks.Templates; + +public class CodeCoverageTask : FrostingTaskBase + where T : CakeBuildContext +{ + protected override Task RunAsyncCore(T context) + { + var codeCoverageSettings = context.GetRequiredSettings(); + + var reportGeneratorSettings = new ReportGeneratorSettings + { + ReportTypes = codeCoverageSettings.ReportTypes.ToList() + }; + + context.ReportGenerator(new GlobPattern(codeCoverageSettings.ReportGlobPattern), + context.CodeCoverageReportDir, reportGeneratorSettings); + + return Task.CompletedTask; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/NuGetPushTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/NuGetPushTask.cs new file mode 100755 index 00000000..688fc212 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/NuGetPushTask.cs @@ -0,0 +1,41 @@ +using Cake.Common.Diagnostics; +using Cake.Common.Tools.DotNet; +using Cake.Common.Tools.DotNet.NuGet.Push; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +namespace CreativeCoders.CakeBuild.Tasks.Templates; + +public class NuGetPushTask : FrostingTaskBase where T : CakeBuildContext +{ + protected override Task RunAsyncCore(T context) + { + var pushSettings = context.GetRequiredSettings(); + + if (pushSettings.SkipPush) + { + context.Information("Skip NuGet push"); + return Task.CompletedTask; + } + + var packSettings = context.GetRequiredSettings(); + + var filePath = packSettings.OutputDirectory.GetFilePath("*.nupkg"); + + context.DotNetNuGetPush(filePath, CreateNuGetPushSettings(pushSettings)); + + return Task.CompletedTask; + } + + private static DotNetNuGetPushSettings CreateNuGetPushSettings(INuGetPushTaskSettings settings) + { + var nugetPushSettings = new DotNetNuGetPushSettings + { + Source = settings.NuGetFeedUrl, + ApiKey = settings.NuGetApiKey, + SkipDuplicate = true, + IgnoreSymbols = false + }; + + return nugetPushSettings; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/PackTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/PackTask.cs new file mode 100755 index 00000000..8c418331 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/PackTask.cs @@ -0,0 +1,47 @@ +using Cake.Common.Tools.DotNet; +using Cake.Common.Tools.DotNet.MSBuild; +using Cake.Common.Tools.DotNet.Pack; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +namespace CreativeCoders.CakeBuild.Tasks.Templates; + +public class PackTask : FrostingTaskBase + where T : CakeBuildContext +{ + protected override Task RunAsyncCore(T context) + { + var packSettings = context.GetRequiredSettings(); + + context.DotNetPack(context.SolutionFile.FullPath, CreateDotNetPackSettings(context, packSettings)); + + return Task.CompletedTask; + } + + private DotNetPackSettings CreateDotNetPackSettings(T context, IPackTaskSettings packSettings) + { + var dotNetPackSettings = new DotNetPackSettings + { + OutputDirectory = packSettings.OutputDirectory, + Configuration = context.BuildConfiguration, + NoBuild = context.HasExecutedTask(typeof(BuildTask)), + IncludeSymbols = true, + SymbolPackageFormat = "snupkg", + + MSBuildSettings = new DotNetMSBuildSettings + { + InformationalVersion = context.Version.InformationalVersion, + AssemblyVersion = context.Version.AssemblySemVer, + FileVersion = context.Version.AssemblySemFileVer, + PackageVersion = context.Version.SemVer + } + }; + + dotNetPackSettings.MSBuildSettings + .WithPackageProjectUrl(packSettings.PackageProjectUrl) + .WithPackageLicenseUrl(packSettings.PackageLicenseUrl) + .WithPackageLicenseExpression(packSettings.PackageLicenseExpression) + .WithCopyright(packSettings.Copyright); + + return dotNetPackSettings; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/RestoreTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/RestoreTask.cs new file mode 100755 index 00000000..99eaa2d6 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/RestoreTask.cs @@ -0,0 +1,14 @@ +using Cake.Common.Tools.DotNet; + +namespace CreativeCoders.CakeBuild.Tasks.Templates; + +public class RestoreTask : FrostingTaskBase + where T : CakeBuildContext +{ + protected override Task RunAsyncCore(T context) + { + context.DotNetRestore(context.RootDir.FullPath); + + return Task.CompletedTask; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/CakeTaskSettingsAttribute.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/CakeTaskSettingsAttribute.cs new file mode 100644 index 00000000..caa24a5f --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/CakeTaskSettingsAttribute.cs @@ -0,0 +1,4 @@ +namespace CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +[AttributeUsage(AttributeTargets.Interface)] +public class CakeTaskSettingsAttribute : Attribute; diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ICleanTaskSettings.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ICleanTaskSettings.cs new file mode 100644 index 00000000..d94c0675 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ICleanTaskSettings.cs @@ -0,0 +1,38 @@ +using Cake.Core.IO; + +namespace CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +[CakeTaskSettings] +public interface ICleanTaskSettings : IBuildContextAccessor +{ + IList DirectoriesToClean => GetDefaultDirectoriesToClean(); + + IList GetDefaultDirectoriesToClean() + { + var dirs = new List(); + + string[] defaultSourceDirs = ["source", "src", "samples", "tests"]; + + var sourceDirs = defaultSourceDirs + .Select(x => Context.RootDir.Combine(x)) + .Where(Context.FileSystem.Exist) + .Select(x => x.FullPath); + + foreach (var sourceDir in sourceDirs) + { + var binDirs = Context.Globber.Match(sourceDir + "/**/bin") + .OfType(); + + dirs.AddRange(binDirs); + + var objDirs = Context.Globber.Match(sourceDir + "/**/obj") + .OfType(); + + dirs.AddRange(objDirs); + } + + dirs.AddRange([Context.ArtifactsDir, Context.TestOutputBasePath]); + + return dirs; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ICodeCoverageTaskSettings.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ICodeCoverageTaskSettings.cs new file mode 100644 index 00000000..eaf19585 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ICodeCoverageTaskSettings.cs @@ -0,0 +1,15 @@ +using Cake.Common.Tools.ReportGenerator; + +namespace CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +[CakeTaskSettings] +public interface ICodeCoverageTaskSettings : IBuildContextAccessor +{ + IEnumerable ReportTypes => + [ + ReportGeneratorReportType.Html, + ReportGeneratorReportType.MarkdownSummaryGithub + ]; + + string ReportGlobPattern => Context.CodeCoverageDir.FullPath + "/**/*.xml"; +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/INuGetPushTaskSettings.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/INuGetPushTaskSettings.cs new file mode 100644 index 00000000..5ac98d04 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/INuGetPushTaskSettings.cs @@ -0,0 +1,11 @@ +namespace CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +[CakeTaskSettings] +public interface INuGetPushTaskSettings : IBuildContextAccessor +{ + string NuGetFeedUrl => "nuget.org"; + + string NuGetApiKey => Context.Environment.GetEnvironmentVariable("NUGET_TOKEN"); + + bool SkipPush => false; +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/IPackTaskSettings.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/IPackTaskSettings.cs new file mode 100644 index 00000000..4b74a908 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/IPackTaskSettings.cs @@ -0,0 +1,17 @@ +using Cake.Core.IO; + +namespace CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +[CakeTaskSettings] +public interface IPackTaskSettings : IBuildContextAccessor +{ + DirectoryPath OutputDirectory => Context.ArtifactsDir.Combine("nuget"); + + string Copyright => string.Empty; + + string PackageProjectUrl => string.Empty; + + string PackageLicenseUrl => string.Empty; + + string PackageLicenseExpression => string.Empty; +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ITestTaskSettings.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ITestTaskSettings.cs new file mode 100644 index 00000000..56879aff --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/ITestTaskSettings.cs @@ -0,0 +1,35 @@ +using Cake.Common.Solution; +using Cake.Core.IO; + +namespace CreativeCoders.CakeBuild.Tasks.Templates.Settings; + +[CakeTaskSettings] +public interface ITestTaskSettings : IBuildContextAccessor +{ + IEnumerable TestProjects + { + get + { + if (Context.SolutionFile.GetExtension()?.ToLower() != ".sln") + { + // Currently no support for new XML based slnx solution file format + return []; + } + + var solution = Context.ParseSolution(Context.SolutionFile); + + var testProjects = solution.Projects + .Where(p => + p.Path.MakeAbsolute(Context.Environment).FullPath.StartsWith(TestSourceDir.FullPath, + StringComparison.InvariantCulture)); + + return testProjects + .Select(x => x.Path) + .Where(x => x.GetExtension()?.ToLower() == ".csproj"); + } + } + + bool GenerateCoverageReport => true; + + DirectoryPath TestSourceDir => Context.RootDir.Combine("tests"); +} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PackageLicenseExpressions.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/PackageLicenseExpressions.cs similarity index 79% rename from source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PackageLicenseExpressions.cs rename to source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/PackageLicenseExpressions.cs index 81d301b4..7f4467e3 100644 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PackageLicenseExpressions.cs +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/Settings/PackageLicenseExpressions.cs @@ -1,9 +1,7 @@ -using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; -namespace CreativeCoders.NukeBuild.BuildActions; +namespace CreativeCoders.CakeBuild.Tasks.Templates.Settings; -[ExcludeFromCodeCoverage] [PublicAPI] public static class PackageLicenseExpressions { diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/TestTask.cs b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/TestTask.cs new file mode 100755 index 00000000..e3fcc887 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/Tasks/Templates/TestTask.cs @@ -0,0 +1,58 @@ +using Cake.Common.Diagnostics; +using Cake.Common.Tools.DotNet; +using Cake.Common.Tools.DotNet.Test; +using Cake.Core.IO; +using CreativeCoders.CakeBuild.Tasks.Templates.Settings; +using JetBrains.Annotations; + +namespace CreativeCoders.CakeBuild.Tasks.Templates; + +[PublicAPI] +public class TestTask : FrostingTaskBase where T : CakeBuildContext +{ + protected override Task RunAsyncCore(T context) + { + var testSettings = context.GetRequiredSettings(); + + var testProjects = testSettings.TestProjects.OrderBy(x => x.FullPath).ToArray(); + + context.Information($"Found {testProjects.Length} test project(s)"); + + foreach (var testProject in testProjects) + { + context.Information($"Test project found: {testProject.GetFilename()}"); + + context.DotNetTest(testProject.FullPath, + CreateDotNetBuildSettings(context, testProject, testSettings)); + } + + return Task.CompletedTask; + } + + protected virtual void ApplyDotNetTestSettings(T context, DotNetTestSettings dotNetBuildSettings) { } + + private DotNetTestSettings CreateDotNetBuildSettings(T context, FilePath testProject, + ITestTaskSettings testSettings) + { + var testResultFile = + context.TestResultsDir.CombineWithFilePath($"{testProject.GetFilenameWithoutExtension()}.trx"); + + var dotNetTestSettings = new DotNetTestSettings + { + Configuration = context.BuildConfiguration, + NoBuild = context.HasExecutedTask(typeof(BuildTask)), + Loggers = [$"trx;LogFileName={testResultFile}"], + Collectors = testSettings.GenerateCoverageReport ? ["XPlat Code Coverage"] : [], + ResultsDirectory = context.CodeCoverageDir + }; + + ApplyDotNetTestSettings(context, dotNetTestSettings); + + if (dotNetTestSettings.NoBuild) + { + context.Information("Skip build"); + } + + return dotNetTestSettings; + } +} diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/ToolInstallation.cs b/source/CakeBuild/CreativeCoders.CakeBuild/ToolInstallation.cs new file mode 100644 index 00000000..1ba24b45 --- /dev/null +++ b/source/CakeBuild/CreativeCoders.CakeBuild/ToolInstallation.cs @@ -0,0 +1,12 @@ +using CreativeCoders.Core; + +namespace CreativeCoders.CakeBuild; + +public class ToolInstallation(string toolKind, string name, string version) +{ + public string ToolKind { get; } = Ensure.IsNotNullOrWhitespace(toolKind); + + public string Name { get; } = Ensure.IsNotNullOrWhitespace(name); + + public string Version { get; } = Ensure.IsNotNullOrWhitespace(version); +} diff --git a/source/Core/CreativeCoders.Core/Ensure.cs b/source/Core/CreativeCoders.Core/Ensure.cs index 78215ee5..883c23a5 100644 --- a/source/Core/CreativeCoders.Core/Ensure.cs +++ b/source/Core/CreativeCoders.Core/Ensure.cs @@ -17,7 +17,7 @@ namespace CreativeCoders.Core; [PublicAPI] public static class Ensure { - private const string UnkownParamName = "[unknown]"; + private const string UnknownParamName = "[unknown]"; ///------------------------------------------------------------------------------------------------- /// Ensures that is not null. @@ -35,7 +35,7 @@ public static class Ensure [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: System.Diagnostics.CodeAnalysis.NotNull] public static T NotNull([System.Diagnostics.CodeAnalysis.NotNull] [NoEnumeration] T? value, - [CallerArgumentExpression("value")] string paramName = UnkownParamName) + [CallerArgumentExpression("value")] string paramName = UnknownParamName) { return value ?? throw new ArgumentNullException(paramName); } @@ -43,7 +43,7 @@ public static T NotNull([System.Diagnostics.CodeAnalysis.NotNull] [NoEnumerat [ContractAnnotation("value: null => halt")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull] [NoEnumeration] object? value, - [CallerArgumentExpression("value")] string paramName = UnkownParamName) + [CallerArgumentExpression("value")] string paramName = UnknownParamName) { if (value is null) { @@ -84,7 +84,7 @@ public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull] [NoEnu [ContractAnnotation("halt <= value: null; value: notnull => notnull")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string IsNotNullOrEmpty([System.Diagnostics.CodeAnalysis.NotNull] string? value, - [CallerArgumentExpression("value")] string paramName = UnkownParamName) + [CallerArgumentExpression("value")] string paramName = UnknownParamName) { return string.IsNullOrEmpty(value) ? throw new ArgumentException("Must not be null or empty", paramName) @@ -104,7 +104,7 @@ public static string IsNotNullOrEmpty([System.Diagnostics.CodeAnalysis.NotNull] [ContractAnnotation("halt <= value: null")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsNotNullOrEmpty(IEnumerable? value, - [CallerArgumentExpression("value")] string paramName = UnkownParamName) + [CallerArgumentExpression("value")] string paramName = UnknownParamName) { if (value == null || !value.Any()) { @@ -126,7 +126,7 @@ public static void IsNotNullOrEmpty(IEnumerable? value, [ContractAnnotation("halt <= value: null; value: notnull => notnull")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string IsNotNullOrWhitespace(string? value, - [CallerArgumentExpression("value")] string paramName = UnkownParamName) + [CallerArgumentExpression("value")] string paramName = UnknownParamName) { return string.IsNullOrWhiteSpace(value) ? throw new ArgumentException("Must not be null or whitespace", paramName) @@ -143,7 +143,7 @@ public static string IsNotNullOrWhitespace(string? value, /// Name of the parameter. /// ------------------------------------------------------------------------------------------------- public static void FileExists(string? fileName, - [CallerArgumentExpression("fileName")] string paramName = UnkownParamName) + [CallerArgumentExpression("fileName")] string paramName = UnknownParamName) { if (!FileSys.File.Exists(fileName)) { @@ -165,7 +165,7 @@ public static void FileExists(string? fileName, ///------------------------------------------------------------------------------------------------- public static void DirectoryExists(string? directoryName, [CallerArgumentExpression("directoryName")] - string paramName = UnkownParamName) + string paramName = UnknownParamName) { if (!FileSys.Directory.Exists(directoryName)) { @@ -184,7 +184,7 @@ public static void DirectoryExists(string? directoryName, ///------------------------------------------------------------------------------------------------- [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void GuidIsNotEmpty(Guid guid, - [CallerArgumentExpression("guid")] string paramName = UnkownParamName) + [CallerArgumentExpression("guid")] string paramName = UnknownParamName) { if (guid.Equals(Guid.Empty)) { @@ -202,7 +202,7 @@ public static void GuidIsNotEmpty(Guid guid, public static void That(bool condition, string message = "Assertion failed", [CallerArgumentExpression("condition")] - string paramName = UnkownParamName) + string paramName = UnknownParamName) { if (!condition) { @@ -223,7 +223,7 @@ public static void That(bool condition, public static void ThatRange(bool condition, string message = "Assertion failed", [CallerArgumentExpression("condition")] - string paramName = UnkownParamName) + string paramName = UnknownParamName) { if (!condition) { @@ -246,7 +246,7 @@ public static void ThatRange(bool condition, ///------------------------------------------------------------------------------------------------- [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IndexIsInRange(int index, int startIndex, int endIndex, - [CallerArgumentExpression("index")] string paramName = UnkownParamName) + [CallerArgumentExpression("index")] string paramName = UnknownParamName) { if (index < startIndex || index > endIndex) { @@ -269,7 +269,7 @@ public static void IndexIsInRange(int index, int startIndex, int endIndex, ///------------------------------------------------------------------------------------------------- [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IndexIsInRange(int index, int collectionLength, - [CallerArgumentExpression("index")] string paramName = UnkownParamName) + [CallerArgumentExpression("index")] string paramName = UnknownParamName) { if (index < 0 || index >= collectionLength) { @@ -289,7 +289,7 @@ public static void IndexIsInRange(int index, int collectionLength, ///------------------------------------------------------------------------------------------------- [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Argument Argument(T? value, - [CallerArgumentExpression("value")] string paramName = UnkownParamName) + [CallerArgumentExpression("value")] string paramName = UnknownParamName) { return new Argument(value, paramName); } diff --git a/source/Core/CreativeCoders.Core/ObjectExtensions.cs b/source/Core/CreativeCoders.Core/ObjectExtensions.cs index 014047e4..778ba00b 100644 --- a/source/Core/CreativeCoders.Core/ObjectExtensions.cs +++ b/source/Core/CreativeCoders.Core/ObjectExtensions.cs @@ -47,6 +47,8 @@ public static bool TryAs(this object instance, [MaybeNullWhen(false)] out T a return false; } + public static T CastAs(this object instance) => (T)Ensure.NotNull(instance); + public static async ValueTask TryDisposeAsync(this object instance) { switch (instance) diff --git a/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj b/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj index 7690a83b..77f02e75 100644 --- a/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj +++ b/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj @@ -5,10 +5,6 @@ Default message queue implementation for CreativeCoders.Messaging.Core - - - - diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/CreativeCoders.NukeBuild.Components.csproj b/source/NukeBuild/CreativeCoders.NukeBuild.Components/CreativeCoders.NukeBuild.Components.csproj deleted file mode 100644 index ab039504..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/CreativeCoders.NukeBuild.Components.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Library - enable - enable - - - - - - - - - - - - - diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/GitHubActionsExtensions.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/GitHubActionsExtensions.cs deleted file mode 100644 index d8f11a1c..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/GitHubActionsExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using CreativeCoders.Core.SysEnvironment; -using JetBrains.Annotations; -using Nuke.Common.CI.GitHubActions; - -namespace CreativeCoders.NukeBuild.Components; - -[PublicAPI] -public static class GitHubActionsExtensions -{ - public static bool IsRunnerOs(this GitHubActions gitHubActions, string runnerOs) - { - return gitHubActions.GetRunnerOs() - .Equals(runnerOs, StringComparison.OrdinalIgnoreCase); - } - - public static string GetRunnerOs(this GitHubActions gitHubActions) - { - return Env.GetEnvironmentVariable("RUNNER_OS") ?? string.Empty; - } - - public static bool IsLocalBuild(this GitHubActions? gitHubActions) - { - return gitHubActions == null || - Env.GetEnvironmentVariable("GITHUB_ACTIONS")? - .Equals("true", StringComparison.OrdinalIgnoreCase) == false; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/GitHubActionsRunnerOs.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/GitHubActionsRunnerOs.cs deleted file mode 100644 index 8ec7bcd3..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/GitHubActionsRunnerOs.cs +++ /dev/null @@ -1,13 +0,0 @@ -using JetBrains.Annotations; - -namespace CreativeCoders.NukeBuild.Components; - -[PublicAPI] -public static class GitHubActionsRunnerOs -{ - public const string Windows = "Windows"; - - public const string Linux = "Linux"; - - public const string MacOs = "macOS"; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/GithubReleaseTasks.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/GithubReleaseTasks.cs deleted file mode 100644 index 6f7e8149..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/GithubReleaseTasks.cs +++ /dev/null @@ -1,79 +0,0 @@ -using CreativeCoders.Core.IO; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using Nuke.Common.CI.GitHubActions; -using Octokit; -using Serilog; - -namespace CreativeCoders.NukeBuild.Components; - -public class GithubReleaseTasks(string githubToken) -{ - private readonly GitHubClient _githubClient = - new GitHubClient(new ProductHeaderValue("CreativeCoders.Nuke")) - { - Credentials = new Credentials(githubToken) - }; - - public async Task CreateReleaseAsync(string releaseVersion, string name, string body, bool isPreRelease, - IEnumerable releaseAssets) - { - var release = await CreateReleaseDraftAsync(releaseVersion, name, body, isPreRelease) - .ConfigureAwait(false); - - await UploadReleaseAssets(release, releaseAssets).ConfigureAwait(false); - - await _githubClient.Repository.Release - .Edit(GitHubActions.Instance.RepositoryOwner, GetRepositoryName(), release.Id, - new ReleaseUpdate { Draft = false }).ConfigureAwait(false); - } - - private async Task UploadReleaseAssets(Release release, - IEnumerable githubReleaseAssets) - { - foreach (var releaseAssetUpload in githubReleaseAssets.Select(releaseAsset => new ReleaseAssetUpload - { - ContentType = MimeMapping.MimeUtility.GetMimeMapping(releaseAsset.FileName), - FileName = FileSys.Path.GetFileName(releaseAsset.FileName), - RawData = FileSys.File.OpenRead(releaseAsset.FileName) - })) - { - _ = await _githubClient.Repository.Release.UploadAsset(release, releaseAssetUpload) - .ConfigureAwait(false); - } - } - - private async Task CreateReleaseDraftAsync(string releaseVersion, string name, string body, - bool isPreRelease) - { - var repositoryOwner = GitHubActions.Instance.RepositoryOwner; - var repositoryName = GetRepositoryName(); - - Log.Debug("Create github release"); - Log.Debug("Repo Owner: {RepositoryOwner}", repositoryOwner); - Log.Debug("Repo name: {RepositoryName}", repositoryName); - Log.Debug("Version: {ReleaseVersion}", releaseVersion); - Log.Debug("Name: {Name}", name); - Log.Debug("Body: {Body}", body); - - return await _githubClient.Repository.Release - .Create(repositoryOwner, repositoryName, - new NewRelease(releaseVersion) - { - Name = name, - Body = body, - Draft = true, - Prerelease = isPreRelease - }) - .ConfigureAwait(false); - } - - private static string GetRepositoryName() - { - var index = GitHubActions.Instance.Repository.LastIndexOf('/'); - - return index > -1 - ? GitHubActions.Instance.Repository[(index + 1)..] - : throw new InvalidOperationException( - $"No repository name found in '{GitHubActions.Instance.Repository}'"); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Global.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Global.cs deleted file mode 100644 index 87ebd04c..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Global.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Diagnostics.CodeAnalysis; - -[assembly: ExcludeFromCodeCoverage] diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/NukeBuildExtensions.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/NukeBuildExtensions.cs deleted file mode 100644 index 67f7c955..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/NukeBuildExtensions.cs +++ /dev/null @@ -1,60 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.NukeBuild.Components.Parameters; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.Git; -using Nuke.Common.IO; -using Nuke.Common.ProjectModel; -using Nuke.Common.Tools.GitVersion; - -namespace CreativeCoders.NukeBuild.Components; - -[PublicAPI] -public static class NukeBuildExtensions -{ - public static GitVersion? GetGitVersion(this INukeBuild build) - { - return build.As()?.GitVersion; - } - - public static AbsolutePath GetArtifactsDirectory(this INukeBuild build) - { - return build.As()?.ArtifactsDirectory ?? - throw new InvalidOperationException("No artifacts directory specified"); - } - - public static Configuration GetConfiguration(this INukeBuild build) - { - return build.As()?.Configuration ?? - (build.IsLocalBuild ? Configuration.Debug : Configuration.Release); - } - - public static GitRepository GetGitRepository(this INukeBuild build) - { - return build.As()?.GitRepository ?? - throw new InvalidOperationException("No GitRepository present"); - } - - public static Solution GetSolution(this INukeBuild build) - { - return build.As()?.Solution ?? - throw new InvalidOperationException("No Solution present"); - } - - public static void DisableAllTelemetry(this INukeBuild build) - { - build.DisableDotnetTelemetry(); - build.DisableNukeTelemetry(); - } - - public static void DisableDotnetTelemetry(this INukeBuild build) - { - Environment.SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1"); - } - - public static void DisableNukeTelemetry(this INukeBuild build) - { - Environment.SetEnvironmentVariable("NUKE_TELEMETRY_OPTOUT", "1"); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/Configuration.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/Configuration.cs deleted file mode 100644 index 7147027a..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/Configuration.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel; -using Nuke.Common.Tooling; - -namespace CreativeCoders.NukeBuild.Components.Parameters; - -[TypeConverter(typeof(TypeConverter))] -public class Configuration : Enumeration -{ - public static readonly Configuration Debug = new Configuration { Value = nameof(Debug) }; - - public static readonly Configuration Release = new Configuration { Value = nameof(Release) }; - - public static implicit operator string(Configuration configuration) - { - return configuration.Value; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IConfigurationParameter.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IConfigurationParameter.cs deleted file mode 100644 index 24be7ca9..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IConfigurationParameter.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.Components.Parameters; - -public interface IConfigurationParameter : INukeBuild -{ - [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] - Configuration Configuration => TryGetValue(() => Configuration) ?? - (IsLocalBuild ? Configuration.Debug : Configuration.Release); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IGitRepositoryParameter.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IGitRepositoryParameter.cs deleted file mode 100644 index 8f2e2549..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IGitRepositoryParameter.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Nuke.Common; -using Nuke.Common.Git; - -namespace CreativeCoders.NukeBuild.Components.Parameters; - -public interface IGitRepositoryParameter : INukeBuild -{ - [GitRepository] - GitRepository GitRepository => TryGetValue(() => GitRepository) ?? - throw new MissingMemberException( - nameof(IGitRepositoryParameter), - nameof(GitRepository)); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IGitVersionParameter.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IGitVersionParameter.cs deleted file mode 100644 index 2f7f1272..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/IGitVersionParameter.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Nuke.Common; -using Nuke.Common.Tools.GitVersion; - -namespace CreativeCoders.NukeBuild.Components.Parameters; - -public interface IGitVersionParameter : INukeBuild -{ - [GitVersion] - GitVersion? GitVersion => TryGetValue(() => GitVersion); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/ISolutionParameter.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/ISolutionParameter.cs deleted file mode 100644 index b2dd6e5d..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/ISolutionParameter.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Nuke.Common; -using Nuke.Common.ProjectModel; - -namespace CreativeCoders.NukeBuild.Components.Parameters; - -public interface ISolutionParameter : INukeBuild -{ - [Solution] - [Required] - Solution Solution => TryGetValue(() => Solution) ?? throw new ArgumentNullException(nameof(Solution)); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/ISourceDirectoryParameter.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/ISourceDirectoryParameter.cs deleted file mode 100644 index fff663e0..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Parameters/ISourceDirectoryParameter.cs +++ /dev/null @@ -1,13 +0,0 @@ -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Parameters; - -[PublicAPI] -public interface ISourceDirectoryParameter : INukeBuild -{ - string SourceDirectoryRelativePath => "source"; - - AbsolutePath SourceDirectory => RootDirectory / SourceDirectoryRelativePath; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/CommonTargetTasks.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/CommonTargetTasks.cs deleted file mode 100644 index c7b329ef..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/CommonTargetTasks.cs +++ /dev/null @@ -1,25 +0,0 @@ -using CreativeCoders.Core.Collections; -using CreativeCoders.Core.IO; -using JetBrains.Annotations; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public static class CommonTargetTasks -{ - public static void SafeDeleteDirectory(AbsolutePath directory) - { - if (!FileSys.Directory.Exists(directory)) - { - return; - } - - directory.DeleteDirectory(); - } - - public static void SafeDeleteDirectories(this IEnumerable directories) - { - directories.ForEach(SafeDeleteDirectory); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IBuildTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IBuildTarget.cs deleted file mode 100644 index ef3a7b89..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IBuildTarget.cs +++ /dev/null @@ -1,39 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.NukeBuild.Components.Parameters; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface IBuildTarget : ISolutionParameter -{ - Target Build => d => d - .TryBefore() - .TryDependsOn() - .Executes(() => DotNetTasks.DotNetBuild(x => x - .Apply(ConfigureCompileSettings) - )); - - DotNetBuildSettings ConfigureCompileSettings(DotNetBuildSettings buildSettings) - => ConfigureDefaultCompileSettings(buildSettings); - - sealed DotNetBuildSettings ConfigureDefaultCompileSettings(DotNetBuildSettings buildSettings) - { - var solutionParameter = this.As(); - - return buildSettings - .When(_ => solutionParameter != null, x => x - // ReSharper disable once NullableWarningSuppressionIsUsed - .SetProjectFile(solutionParameter!.Solution)) - .WhenNotNull(this as IConfigurationParameter, (x, configuration) => x - .SetConfiguration(configuration.Configuration)) - .WhenNotNull((this as IGitVersionParameter)?.GitVersion, (x, gitVersion) => x - .SetAssemblyVersion(gitVersion.AssemblySemVer) - .SetFileVersion(gitVersion.AssemblySemFileVer) - .SetInformationalVersion(gitVersion.InformationalVersion)) - .SetNoRestore(SucceededTargets.Contains(this.As()?.Restore)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICleanTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICleanTarget.cs deleted file mode 100644 index 82fb183c..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICleanTarget.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using CreativeCoders.Core; -using CreativeCoders.NukeBuild.Components.Parameters; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface ICleanTarget : INukeBuild, ICleanSettings -{ - Target Clean => d => d - .TryBefore() - .Executes(() => - { - DotNetTasks.DotNetClean(x => x - .Apply(ConfigureCleanSettings)); - - DirectoriesToClean.SafeDeleteDirectories(); - }); - - DotNetCleanSettings ConfigureCleanSettings(DotNetCleanSettings cleanSettings) - => ConfigureDefaultCleanSettings(cleanSettings); - - [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - sealed DotNetCleanSettings ConfigureDefaultCleanSettings(DotNetCleanSettings cleanSettings) - { - var solutionParameter = this.As(); - - return cleanSettings - .When(_ => solutionParameter != null, - x => x.SetProject(solutionParameter!.Solution)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICodeCoverageTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICodeCoverageTarget.cs deleted file mode 100644 index a635ffca..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICodeCoverageTarget.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.IO.Compression; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.ReportGenerator; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface ICodeCoverageTarget : ITestTarget, ICodeCoverageSettings -{ - Target CodeCoverage => d => d - .TryBefore() - .DependsOn() - .Produces(TargetDirectory / "*.*") - .Executes(() => - { - ReportGeneratorTasks.ReportGenerator(x => x - .SetFramework(Framework) - .SetReports(Reports) - .SetTargetDirectory(TargetDirectory)); - - ZipFile.CreateFromDirectory(TargetDirectory, CoverageReportArchive); - }); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICreateDistPackagesTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICreateDistPackagesTarget.cs deleted file mode 100644 index e9a78293..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICreateDistPackagesTarget.cs +++ /dev/null @@ -1,38 +0,0 @@ -using CreativeCoders.Core.Collections; -using CreativeCoders.IO.Archives; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface ICreateDistPackagesTarget : INukeBuild, ICreateDistPackagesSettings -{ - Target CreateDistPackages => d => d - .TryAfter() - .Executes(() => - { - DistPackages.ForEach(distPackage => - { - switch (distPackage.Format) - { - case DistPackageFormat.TarGz: - new TarArchiveCreator() - .SetArchiveFileName(DistOutputPath / $"{distPackage.Name}.tar.gz") - .AddFromDirectory(distPackage.DistFolder, "*.*", true) - .Create(true); - break; - case DistPackageFormat.Zip: - new ZipArchiveCreator() - .SetArchiveFileName(DistOutputPath / $"{distPackage.Name}.zip") - .AddFromDirectory(distPackage.DistFolder, "*.*", true) - .Create(); - break; - default: - throw new ArgumentOutOfRangeException(nameof(distPackage), - "Package format not supported"); - } - }); - }); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICreateGithubReleaseTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICreateGithubReleaseTarget.cs deleted file mode 100644 index 389fac94..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ICreateGithubReleaseTarget.cs +++ /dev/null @@ -1,25 +0,0 @@ -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface ICreateGithubReleaseTarget : ICreateGithubReleaseSettings -{ - Target CreateGithubRelease => d => d - .TryAfter() - .TryAfter() - .TryAfter() - .Executes(async () => - { - await new GithubReleaseTasks(GithubToken) - .CreateReleaseAsync( - ReleaseVersion, - ReleaseName, - ReleaseBody, - IsPreRelease, - ReleaseAssets) - .ConfigureAwait(false); - }); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IDeployNuGetTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IDeployNuGetTarget.cs deleted file mode 100644 index fd2f40f8..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IDeployNuGetTarget.cs +++ /dev/null @@ -1,13 +0,0 @@ -using JetBrains.Annotations; -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface IDeployNuGetTarget -{ - Target DeployNuGet => d => d - .DependsOn() - .DependsOn() - .DependsOn(); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPackTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPackTarget.cs deleted file mode 100644 index db855967..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPackTarget.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using CreativeCoders.Core; -using CreativeCoders.NukeBuild.Components.Parameters; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface IPackTarget : IPackSettings, ISolutionParameter -{ - Target Pack => d => d - .TryDependsOn() - .Executes(() => - { - DotNetTasks.DotNetPack(s => s - .Apply(ConfigurePackSettings) - ); - }); - - DotNetPackSettings ConfigurePackSettings(DotNetPackSettings packSettings) - => ConfigureDefaultPackSettings(packSettings); - - [SuppressMessage("ReSharper", "SuspiciousTypeConversion.Global")] - DotNetPackSettings ConfigureDefaultPackSettings(DotNetPackSettings packSettings) - { - return packSettings - .SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg) - .SetProject(Solution) - .WhenNotNull(this as IConfigurationParameter, (x, configurationParameter) => x - .SetConfiguration(configurationParameter.Configuration)) - .EnableIncludeSymbols() - .When(_ => !string.IsNullOrWhiteSpace(OutputDirectory), x => x - .SetOutputDirectory(OutputDirectory)) - .WhenNotNull(this as IGitVersionParameter, (x, gitVersionParameter) => x - .SetVersion(gitVersionParameter.GitVersion?.NuGetVersionV2)) - .SetNoBuild(SucceededTargets.Contains(this.As()?.Build)) - .When(_ => !string.IsNullOrWhiteSpace(Copyright), x => x - .SetCopyright(Copyright)) - .When(_ => !string.IsNullOrWhiteSpace(PackageProjectUrl), x => x - .SetPackageProjectUrl(PackageProjectUrl)) - .When(_ => !string.IsNullOrWhiteSpace(PackageLicenseUrl), x => x - .SetPackageLicenseUrl(PackageLicenseUrl)) - .When(_ => !string.IsNullOrWhiteSpace(PackageLicenseExpression), x => x - .SetProperty("PackageLicenseExpression", PackageLicenseExpression)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPublishTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPublishTarget.cs deleted file mode 100644 index 86b8b529..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPublishTarget.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using CreativeCoders.Core; -using CreativeCoders.NukeBuild.Components.Parameters; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface IPublishTarget : IPublishSettings -{ - Target Publish => d => d - .TryAfter() - .TryAfter() - .DependsOn() - .Produces(PublishingItems.Any() - ? PublishingItems - .Where(x => x.ProduceArtifact) - .Select(x => x.OutputPath.ToString()) - .ToArray() - : [PublishOutputPath]) - .Executes(() => - { - if (PublishingItems.Any()) - { - DotNetTasks.DotNetPublish(x => x - .Apply(ConfigurePublishSettings) - .CombineWith(PublishingItems, ConfigurePublishItemSettings)); - } - else - { - DotNetTasks.DotNetPublish(x => x - .Apply(ConfigurePublishSettings)); - } - }); - - DotNetPublishSettings ConfigurePublishSettings(DotNetPublishSettings publishSettings) - => ConfigureDefaultPublishSettings(publishSettings); - - [SuppressMessage("ReSharper", "SuspiciousTypeConversion.Global")] - sealed DotNetPublishSettings ConfigureDefaultPublishSettings(DotNetPublishSettings publishSettings) - { - return publishSettings - .SetNoBuild(SucceededTargets.Contains(this.As()?.Build)) - .WhenNotNull(this as ISolutionParameter, (x, solutionParameter) => x - .SetProject(solutionParameter.Solution)) - .SetOutput(PublishOutputPath) - .WhenNotNull(this as IConfigurationParameter, (x, configuration) => x - .SetConfiguration(configuration.Configuration)) - .WhenNotNull((this as IGitVersionParameter)?.GitVersion, (x, gitVersion) => x - .SetAssemblyVersion(gitVersion.AssemblySemVer) - .SetFileVersion(gitVersion.AssemblySemFileVer) - .SetInformationalVersion(gitVersion.InformationalVersion) - .SetVersion(gitVersion.FullSemVer)); - } - - DotNetPublishSettings ConfigurePublishItemSettings(DotNetPublishSettings publishSettings, - PublishingItem publishingItem) - => ConfigureDefaultPublishItemSettings(publishSettings, publishingItem); - - static DotNetPublishSettings ConfigureDefaultPublishItemSettings(DotNetPublishSettings publishSettings, - PublishingItem publishingItem) - { - return publishSettings - .SetProject(publishingItem.ProjectPath) - .SetOutput(publishingItem.OutputPath) - .SetSelfContained(publishingItem.SelfContained) - .When(_ => !string.IsNullOrWhiteSpace(publishingItem.Runtime), x => x - .SetRuntime(publishingItem.Runtime)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPushNuGetTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPushNuGetTarget.cs deleted file mode 100644 index 62d7bc78..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IPushNuGetTarget.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CreativeCoders.Core.Collections; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.IO; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface IPushNuGetTarget : IPackTarget, IPushNuGetSettings -{ - Target PushNuGet => d => d - .OnlyWhenDynamic(() => !SkipPush) - .DependsOn() - .Executes(() => - { - OutputDirectory - .GlobFiles("*.nupkg") - .ForEach(packagePath => - { - DotNetTasks.DotNetNuGetPush(x => x - .Apply(ConfigureNuGetPushSettings, packagePath)); - }); - }); - - DotNetNuGetPushSettings ConfigureNuGetPushSettings(DotNetNuGetPushSettings nuGetPushSettings, - AbsolutePath packagePath) - => ConfigureDefaultNuGetPushSettings(nuGetPushSettings, packagePath); - - sealed DotNetNuGetPushSettings ConfigureDefaultNuGetPushSettings( - DotNetNuGetPushSettings nuGetPushSettings, AbsolutePath packagePath) - { - return nuGetPushSettings - .SetTargetPath(packagePath) - .When(_ => !string.IsNullOrWhiteSpace(NuGetFeedUrl), x => x - .SetSource(NuGetFeedUrl)) - .When(_ => !string.IsNullOrWhiteSpace(NuGetApiKey), x => x - .SetApiKey(NuGetApiKey)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IRebuildTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IRebuildTarget.cs deleted file mode 100644 index ee729cf4..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IRebuildTarget.cs +++ /dev/null @@ -1,13 +0,0 @@ -using JetBrains.Annotations; -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface IRebuildTarget -{ - Target Rebuild => d => d - .DependsOn() - .DependsOn() - .DependsOn(); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IRestoreTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IRestoreTarget.cs deleted file mode 100644 index 2af438df..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/IRestoreTarget.cs +++ /dev/null @@ -1,33 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.NukeBuild.Components.Parameters; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface IRestoreTarget : INukeBuild -{ - Target Restore => d => d - .TryBefore() - .Executes(() => - { - DotNetTasks.DotNetRestore(x => x - .Apply(ConfigureRestoreSettings)); - }); - - DotNetRestoreSettings ConfigureRestoreSettings(DotNetRestoreSettings buildSettings) - => ConfigureDefaultRestoreSettings(buildSettings); - - sealed DotNetRestoreSettings ConfigureDefaultRestoreSettings(DotNetRestoreSettings buildSettings) - { - var solutionParameter = this.As(); - - return buildSettings - .When(_ => solutionParameter != null, x => x - // ReSharper disable once NullableWarningSuppressionIsUsed - .SetProjectFile(solutionParameter!.Solution)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ITestTarget.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ITestTarget.cs deleted file mode 100644 index 6dfb6858..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/ITestTarget.cs +++ /dev/null @@ -1,49 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.NukeBuild.Components.Parameters; -using CreativeCoders.NukeBuild.Components.Targets.Settings; -using JetBrains.Annotations; -using Nuke.Common; -using Nuke.Common.ProjectModel; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public interface ITestTarget : ITestSettings -{ - Target Test => d => d - .TryBefore() - .Executes(() => - { - DotNetTasks.DotNetTest(x => x - .Apply(ConfigureTestSettings) - .CombineWith(TestProjects, ConfigureTestProjectSettings)); - }); - - DotNetTestSettings ConfigureTestProjectSettings(DotNetTestSettings settings, Project project) - => ConfigureDefaultTestProjectSettings(settings, project); - - sealed DotNetTestSettings ConfigureDefaultTestProjectSettings(DotNetTestSettings settings, - Project project) - { - var testResultFile = Path.Combine(TestResultsDirectory, $"{project.Name}.trx"); - return settings - .SetProjectFile(project) - .SetLoggers($"trx;LogFileName={testResultFile}"); - } - - DotNetTestSettings ConfigureTestSettings(DotNetTestSettings testSettings) - => ConfigureDefaultTestSettings(testSettings); - - sealed DotNetTestSettings ConfigureDefaultTestSettings(DotNetTestSettings testSettings) - { - return testSettings - .SetNoBuild(SucceededTargets.Contains(this.As()?.Build)) - .WhenNotNull(this as IConfigurationParameter, (x, configurationParameter) => x - .SetConfiguration(configurationParameter.Configuration)) - .When(_ => GenerateCodeCoverage, x => x - .SetDataCollector("XPlat Code Coverage") - .SetResultsDirectory(CoverageDirectory)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/NukeTargets.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/NukeTargets.cs deleted file mode 100644 index 5f525657..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/NukeTargets.cs +++ /dev/null @@ -1,31 +0,0 @@ -using JetBrains.Annotations; - -namespace CreativeCoders.NukeBuild.Components.Targets; - -[PublicAPI] -public static class NukeTargets -{ - public const string Restore = nameof(IRestoreTarget.Restore); - - public const string Clean = nameof(ICleanTarget.Clean); - - public const string Build = nameof(IBuildTarget.Build); - - public const string Rebuild = nameof(IRebuildTarget.Rebuild); - - public const string Test = nameof(ITestTarget.Test); - - public const string CodeCoverage = nameof(ICodeCoverageTarget.CodeCoverage); - - public const string Pack = nameof(IPackTarget.Pack); - - public const string PushNuGet = nameof(IPushNuGetTarget.PushNuGet); - - public const string DeployNuGet = nameof(IDeployNuGetTarget.DeployNuGet); - - public const string Publish = nameof(IPublishTarget.Publish); - - public const string CreateDistPackages = nameof(ICreateDistPackagesTarget.CreateDistPackages); - - public const string CreateGitHubRelease = nameof(ICreateGithubReleaseTarget.CreateGithubRelease); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/DistPackage.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/DistPackage.cs deleted file mode 100644 index 09857ee7..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/DistPackage.cs +++ /dev/null @@ -1,14 +0,0 @@ -using JetBrains.Annotations; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -[PublicAPI] -public class DistPackage(string name, AbsolutePath distFolder) -{ - public DistPackageFormat Format { get; set; } - - public string Name { get; } = name; - - public AbsolutePath DistFolder { get; } = distFolder; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/DistPackageFormat.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/DistPackageFormat.cs deleted file mode 100644 index 8698dfb1..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/DistPackageFormat.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public enum DistPackageFormat -{ - TarGz, - Zip -} \ No newline at end of file diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/GithubReleaseAsset.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/GithubReleaseAsset.cs deleted file mode 100644 index 01c8f803..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/GithubReleaseAsset.cs +++ /dev/null @@ -1,9 +0,0 @@ -using JetBrains.Annotations; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -[PublicAPI] -public class GithubReleaseAsset(string fileName) -{ - public string FileName { get; } = fileName; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IArtifactsSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IArtifactsSettings.cs deleted file mode 100644 index 31a118ab..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IArtifactsSettings.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Nuke.Common; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface IArtifactsSettings : INukeBuild -{ - AbsolutePath ArtifactsDirectory => RootDirectory / ".artifacts"; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICleanSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICleanSettings.cs deleted file mode 100644 index 66bb075e..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICleanSettings.cs +++ /dev/null @@ -1,28 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.Core.Collections; -using CreativeCoders.NukeBuild.Components.Parameters; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface ICleanSettings -{ - IList DirectoriesToClean => DefaultDirectoriesToClean; - - IList DefaultDirectoriesToClean - { - get - { - IList dirs = new List(); - - if (this.TryAs(out var sourceDirectoryParameter)) - { - dirs.AddRange(sourceDirectoryParameter - .SourceDirectory - .GlobDirectories("**/bin", "**/obj")); - } - - return dirs; - } - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICodeCoverageSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICodeCoverageSettings.cs deleted file mode 100644 index 78009fbe..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICodeCoverageSettings.cs +++ /dev/null @@ -1,20 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.Core.IO; -using CreativeCoders.Core.SysEnvironment; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface ICodeCoverageSettings : ITestSettings -{ - AbsolutePath TargetDirectory => this.TryAs(out var testSettings) - ? testSettings.TestBaseDirectory / "coverage_report" - : TemporaryDirectory / "coverage_report"; - - AbsolutePath CoverageReportArchive => - TargetDirectory.Parent / FileSys.Path.ChangeExtension(TargetDirectory.Name, "zip"); - - string Framework => $"net{Env.Version.Major}.0"; - - IEnumerable Reports => [TestBaseDirectory / "coverage" / "**" / "*.xml"]; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICreateDistPackagesSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICreateDistPackagesSettings.cs deleted file mode 100644 index 16fc7084..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICreateDistPackagesSettings.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface ICreateDistPackagesSettings -{ - IEnumerable DistPackages { get; } - - AbsolutePath DistOutputPath { get; } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICreateGithubReleaseSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICreateGithubReleaseSettings.cs deleted file mode 100644 index 99896a6a..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ICreateGithubReleaseSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface ICreateGithubReleaseSettings : INukeBuild -{ - [Parameter(Name = "GITHUB_TOKEN")] - string GithubToken => TryGetValue(() => GithubToken) ?? string.Empty; - - string ReleaseName { get; } - - string ReleaseBody { get; } - - bool IsPreRelease => false; - - string ReleaseVersion { get; } - - IEnumerable ReleaseAssets { get; } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPackSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPackSettings.cs deleted file mode 100644 index 861e4e94..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPackSettings.cs +++ /dev/null @@ -1,20 +0,0 @@ -using CreativeCoders.Core; -using Nuke.Common; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface IPackSettings : INukeBuild -{ - AbsolutePath OutputDirectory => this.TryAs(out var artifactsSettings) - ? artifactsSettings.ArtifactsDirectory / "nuget" - : TemporaryDirectory / "nuget"; - - string Copyright => string.Empty; - - string PackageProjectUrl => string.Empty; - - string PackageLicenseUrl => string.Empty; - - string PackageLicenseExpression => string.Empty; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPublishSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPublishSettings.cs deleted file mode 100644 index 7172495b..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPublishSettings.cs +++ /dev/null @@ -1,14 +0,0 @@ -using CreativeCoders.Core; -using Nuke.Common; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface IPublishSettings : INukeBuild -{ - AbsolutePath PublishOutputPath => this.TryAs(out var artifactsSettings) - ? artifactsSettings.ArtifactsDirectory / "dist" - : TemporaryDirectory / "dist"; - - IEnumerable PublishingItems => []; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPushNuGetSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPushNuGetSettings.cs deleted file mode 100644 index 8de525d8..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/IPushNuGetSettings.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface IPushNuGetSettings : INukeBuild -{ - [Parameter(Name = "NuGetFeedUrl")] - string NuGetFeedUrl => TryGetValue(() => NuGetFeedUrl) ?? string.Empty; - - [Parameter(Name = "NuGetApiKey")] - string NuGetApiKey => TryGetValue(() => NuGetApiKey) ?? string.Empty; - - bool SkipPush => false; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ITestSettings.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ITestSettings.cs deleted file mode 100644 index ba319013..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/ITestSettings.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Nuke.Common; -using Nuke.Common.IO; -using Nuke.Common.ProjectModel; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -public interface ITestSettings : INukeBuild -{ - IEnumerable TestProjects { get; } - - AbsolutePath TestBaseDirectory => RootDirectory / ".tests"; - - AbsolutePath TestResultsDirectory => TestBaseDirectory / "results"; - - bool GenerateCodeCoverage => true; - - AbsolutePath CoverageDirectory => TestBaseDirectory / "coverage"; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/PublishingItem.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/PublishingItem.cs deleted file mode 100644 index 3704cd7b..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/Targets/Settings/PublishingItem.cs +++ /dev/null @@ -1,18 +0,0 @@ -using JetBrains.Annotations; -using Nuke.Common.IO; - -namespace CreativeCoders.NukeBuild.Components.Targets.Settings; - -[PublicAPI] -public class PublishingItem(AbsolutePath projectPath, AbsolutePath outputPath) -{ - public AbsolutePath ProjectPath { get; } = projectPath; - - public AbsolutePath OutputPath { get; } = outputPath; - - public string? Runtime { get; set; } - - public bool SelfContained { get; set; } - - public bool ProduceArtifact { get; set; } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild.Components/ToolSettingsExtensions.cs b/source/NukeBuild/CreativeCoders.NukeBuild.Components/ToolSettingsExtensions.cs deleted file mode 100644 index 83a27bcb..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild.Components/ToolSettingsExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CreativeCoders.NukeBuild.Components; - -public static class ToolSettingsExtensions -{ - public static T WhenNotNull(this T settings, TObject? instance, Func configure) - where TObject : class - { - return instance != null - ? configure(settings, instance) - : settings; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/BuildActionBase.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/BuildActionBase.cs deleted file mode 100644 index d8346c4f..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/BuildActionBase.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -public abstract class BuildActionBase : IBuildAction - where TBuildAction : BuildActionBase, new() -{ - public ITargetDefinition Setup(ITargetDefinition targetDefinition) - { - return Setup(targetDefinition, null); - } - - public ITargetDefinition Setup(ITargetDefinition targetDefinition, Action configureAction) - { - targetDefinition.Executes(() => ExecuteAction(configureAction)); - - return targetDefinition; - } - - private void ExecuteAction(Action configureAction) - { - configureAction((TBuildAction) this); - - OnExecute(); - } - - public void SetBuildInfo(IBuildInfo buildInfo) - { - BuildInfo = buildInfo; - } - - protected abstract void OnExecute(); - - protected IBuildInfo BuildInfo { get; private set; } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CleanBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CleanBuildAction.cs deleted file mode 100644 index 24cabd35..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CleanBuildAction.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; -using Nuke.Common.IO; -using Nuke.Common.Utilities.Collections; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class CleanBuildAction : BuildActionBase -{ - private readonly List _cleanDirectories = []; - - protected override void OnExecute() - { - BuildInfo.SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(SafeDeleteDirectory); - - _cleanDirectories.ForEach(SafeDeleteDirectory); - } - - private static void SafeDeleteDirectory(AbsolutePath directory) - { - directory.CreateOrCleanDirectory(); - directory.DeleteDirectory(); - } - - public CleanBuildAction AddDirectoryForClean(AbsolutePath directory) - { - _cleanDirectories.Add(directory); - - return this; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CopyToArtifactsBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CopyToArtifactsBuildAction.cs deleted file mode 100644 index 22bc8ea7..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CopyToArtifactsBuildAction.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using JetBrains.Annotations; -using Nuke.Common.IO; -using Nuke.Common.Utilities.Collections; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class CopyToArtifactsBuildAction : BuildActionBase -{ - private string _fileMask; - - protected override void OnExecute() - { - if (string.IsNullOrEmpty(_fileMask)) - { - throw new ArgumentException("file mask must not be null or empty"); - } - - BuildInfo.SourceDirectory.GlobFiles(_fileMask).ForEach(CopyFileToArtifacts); - } - - private void CopyFileToArtifacts(AbsolutePath fullFileName) - { - var fileName = Path.GetFileName(fullFileName); - - if (string.IsNullOrEmpty(fileName)) - { - return; - } - - var targetFile = Path.Combine(BuildInfo.ArtifactsDirectory, fileName); - fullFileName.Copy(targetFile, ExistsPolicy.FileOverwrite); - } - - public void SetFileMask(string fileMask) - { - _fileMask = fileMask; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CoverageReportAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CoverageReportAction.cs deleted file mode 100644 index 3eba2518..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/CoverageReportAction.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using CreativeCoders.Core.SysEnvironment; -using JetBrains.Annotations; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.ReportGenerator; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class CoverageReportAction : BuildActionBase -{ - private string _framework = $"net{Env.Version.Major}.0"; - - private string[] _reports; - - private string _targetDirectory; - - protected override void OnExecute() - { - ReportGeneratorTasks.ReportGenerator(x => x - .SetFramework(_framework) - .SetReports(_reports) - .SetTargetDirectory(_targetDirectory)); - } - - public CoverageReportAction SetFramework(string framework) - { - _framework = framework; - - return this; - } - - public CoverageReportAction SetReports(params string[] reports) - { - _reports = reports; - - return this; - } - - public CoverageReportAction SetTargetDirectory(string targetDirectory) - { - _targetDirectory = targetDirectory; - - return this; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetCompileBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetCompileBuildAction.cs deleted file mode 100644 index 5eb7e15f..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetCompileBuildAction.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class DotNetCompileBuildAction : BuildActionBase -{ - protected override void OnExecute() - { - DotNetTasks.DotNetBuild(s => s - .SetProjectFile(BuildInfo.Solution) - .SetConfiguration(BuildInfo.Configuration) - .SetAssemblyVersion(BuildInfo.VersionInfo.GetAssemblySemVer()) - .SetFileVersion(BuildInfo.VersionInfo.GetAssemblySemFileVer()) - .SetInformationalVersion(BuildInfo.VersionInfo.InformationalVersion) - .EnableNoRestore()); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetPublishBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetPublishBuildAction.cs deleted file mode 100644 index 9abd2900..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetPublishBuildAction.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class DotNetPublishBuildAction : BuildActionBase -{ - private string _projectFile; - - private string _output; - - private string _runtime; - - private bool _selfContained; - - protected override void OnExecute() - { - DotNetTasks.DotNetPublish(x => - { - var settings = x - .SetProject(_projectFile) - .SetConfiguration(BuildInfo.Configuration) - .SetOutput(_output) - .SetVersion(BuildInfo.VersionInfo.NuGetVersionV2) - .SetSelfContained(_selfContained); - - if (!string.IsNullOrWhiteSpace(_runtime)) - { - settings = settings.SetRuntime(_runtime); - } - - return settings; - }); - } - - public DotNetPublishBuildAction SetProject(string projectFile) - { - _projectFile = projectFile; - - return this; - } - - public DotNetPublishBuildAction SetOutput(string output) - { - _output = output; - - return this; - } - - public DotNetPublishBuildAction SetRuntime(string runtime) - { - _runtime = runtime; - - return this; - } - - public DotNetPublishBuildAction SetSelfContained(bool selfContained) - { - _selfContained = selfContained; - - return this; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetRuntime.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetRuntime.cs deleted file mode 100644 index 7c4dad22..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetRuntime.cs +++ /dev/null @@ -1,25 +0,0 @@ -using JetBrains.Annotations; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[PublicAPI] -public static class DotNetRuntime -{ - public const string WinX64 = "win-x64"; - - public const string WinX86 = "win-x86"; - - public const string WinArm64 = "win-arm64"; - - public const string WinArm = "win-arm"; - - public const string LinuxX64 = "linux-x64"; - - public const string LinuxMuslX64 = "linux-x64"; - - public const string LinuxArm64 = "linux-arm64"; - - public const string LinuxArm = "linux-arm"; - - public const string MacOsX64 = "osx-x64"; -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetTestAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetTestAction.cs deleted file mode 100644 index 57fed972..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/DotNetTestAction.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; -using JetBrains.Annotations; -using Nuke.Common.IO; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class DotNetTestAction : BuildActionBase -{ - private AbsolutePath _coverageDirectory; - - private bool _enableCodeCoverage; - - private string _logger = "xunit"; - private string _projectsPattern; - - private string _resultFileExt = "xml"; - - private string _resultsDirectory; - - private AbsolutePath _testProjectsBaseDirectory; - - protected override void OnExecute() - { - if (!Directory.Exists(_testProjectsBaseDirectory)) - { - return; - } - - var unitTestProjects = _testProjectsBaseDirectory.GlobFiles(_projectsPattern); - - var failedTests = new List<(string UnitTestProject, Exception Exception)>(); - - foreach (var unitTestProject in unitTestProjects) - { - var projectName = Path.GetFileNameWithoutExtension(unitTestProject); - - var testResultFile = Path.Combine(_resultsDirectory, $"{projectName}.{_resultFileExt}"); - - try - { - var testSettings = - CreateTestSettings(unitTestProject, testResultFile); - - DotNetTasks.DotNetTest(testSettings); - } - catch (Exception e) - { - failedTests.Add((UnitTestProject: unitTestProject, Exception: e)); - } - } - - if (failedTests.Count > 0) - { - throw failedTests.First().Exception; - } - } - - private DotNetTestSettings CreateTestSettings(string unitTestProject, string testResultFile) - { - var settings = new DotNetTestSettings() - .SetProjectFile(unitTestProject) - .SetConfiguration(BuildInfo.Configuration) - .SetLoggers($"{_logger};LogFileName={testResultFile}"); - - if (_enableCodeCoverage) - { - return settings - .SetDataCollector("XPlat Code Coverage") - .SetResultsDirectory(_coverageDirectory); - } - - return settings; - } - - public DotNetTestAction SetTestProjectsBaseDirectory(AbsolutePath testProjectsBaseDirectory) - { - _testProjectsBaseDirectory = testProjectsBaseDirectory; - - return this; - } - - public DotNetTestAction SetProjectsPattern(string projectsPattern) - { - _projectsPattern = projectsPattern; - - return this; - } - - public DotNetTestAction SetResultsDirectory(string resultsDirectory) - { - _resultsDirectory = resultsDirectory; - - return this; - } - - public DotNetTestAction SetCoverageDirectory(AbsolutePath coverageDirectory) - { - _coverageDirectory = coverageDirectory; - - return this; - } - - public DotNetTestAction EnableCoverage() - { - _enableCodeCoverage = true; - - return this; - } - - public DotNetTestAction UseLogger(string logger) - { - _logger = logger; - - return this; - } - - public DotNetTestAction SetResultFileExt(string resultFileExt) - { - _resultFileExt = resultFileExt; - - return this; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/IBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/IBuildAction.cs deleted file mode 100644 index 52b9dffe..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/IBuildAction.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Nuke.Common; - -namespace CreativeCoders.NukeBuild.BuildActions; - -public interface IBuildAction - where TBuildAction : IBuildAction -{ - ITargetDefinition Setup(ITargetDefinition targetDefinition); - - ITargetDefinition Setup(ITargetDefinition targetDefinition, Action configureAction); - - void SetBuildInfo(IBuildInfo buildInfo); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/MsBuildCompileBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/MsBuildCompileBuildAction.cs deleted file mode 100644 index cbb0f969..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/MsBuildCompileBuildAction.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; -using Nuke.Common.Tools.MSBuild; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class MsBuildCompileBuildAction : BuildActionBase -{ - protected override void OnExecute() - { - MSBuildTasks.MSBuild(s => s - .SetProjectFile(BuildInfo.Solution) - .SetConfiguration(BuildInfo.Configuration) - .SetAssemblyVersion(BuildInfo.VersionInfo.GetAssemblySemVer()) - .SetFileVersion(BuildInfo.VersionInfo.GetAssemblySemFileVer()) - .SetInformationalVersion(BuildInfo.VersionInfo.InformationalVersion) - .DisableRestore()); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PackBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PackBuildAction.cs deleted file mode 100644 index 49dcff62..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PackBuildAction.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using CreativeCoders.Core; -using JetBrains.Annotations; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class PackBuildAction : BuildActionBase -{ - private DotNetSymbolPackageFormat _symbolPackageFormat = DotNetSymbolPackageFormat.snupkg; - - private string _packageLicenseUrl; - - private string _packageLicenseExpression; - - private string _packageProjectUrl; - - private string _copyright; - - private bool _enableNoBuild; - - protected override void OnExecute() - { - DotNetTasks.DotNetPack(s => s - //.SetWorkingDirectory(BuildInfo.Solution.Directory) - .SetSymbolPackageFormat(_symbolPackageFormat) - .SetProject(BuildInfo.Solution) - .SetConfiguration(BuildInfo.Configuration) - .EnableIncludeSymbols() - .SetOutputDirectory(BuildInfo.ArtifactsDirectory) - .SetVersion(BuildInfo.VersionInfo.NuGetVersionV2) - .FluentIf(_enableNoBuild, x => x.EnableNoBuild()) - .FluentIf(!string.IsNullOrWhiteSpace(_copyright), x => x.SetCopyright(_copyright)) - .FluentIf(!string.IsNullOrWhiteSpace(_packageProjectUrl), - x => x.SetPackageProjectUrl(_packageProjectUrl)) - .FluentIf(!string.IsNullOrEmpty(_packageLicenseUrl), - x => x.SetPackageLicenseUrl(_packageLicenseUrl)) - .FluentIf(!string.IsNullOrWhiteSpace(_packageLicenseExpression), - x => x.SetProperty("PackageLicenseExpression", _packageLicenseExpression)) - ); - } - - public PackBuildAction SetSymbolPackageFormat(DotNetSymbolPackageFormat symbolPackageFormat) - { - _symbolPackageFormat = symbolPackageFormat; - - return this; - } - - public PackBuildAction SetPackageLicenseUrl(string packageLicenseUrl) - { - _packageLicenseUrl = packageLicenseUrl; - - return this; - } - - public PackBuildAction SetPackageLicenseExpression(string packageLicenseExpression) - { - _packageLicenseExpression = packageLicenseExpression; - - return this; - } - - public PackBuildAction SetPackageProjectUrl(string packageProjectUrl) - { - _packageProjectUrl = packageProjectUrl; - - return this; - } - - public PackBuildAction SetCopyright(string copyright) - { - _copyright = copyright; - - return this; - } - - public PackBuildAction SetEnableNoBuild(bool enableNoBuild) - { - _enableNoBuild = enableNoBuild; - - return this; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PushBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PushBuildAction.cs deleted file mode 100644 index 23ca79cf..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/PushBuildAction.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using CreativeCoders.Core; -using JetBrains.Annotations; -using Nuke.Common.IO; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class PushBuildAction : BuildActionBase -{ - private string _apiKey; - - private string _source; - - private string _symbolSource; - - private string _symbolApiKey; - - protected override void OnExecute() - { - foreach (var packagePath in BuildInfo.ArtifactsDirectory.GlobFiles("*.nupkg")) - { - PushPackage(packagePath); - } - } - - private void PushPackage(string package) - { - DotNetTasks.DotNetNuGetPush(x => x - .SetTargetPath(package) - .FluentIf(_source != null, config => config.SetSource(_source)) - .FluentIf(_apiKey != null, config => config.SetApiKey(_apiKey)) - .FluentIf(_symbolSource != null, config => config.SetSymbolSource(_symbolSource)) - .FluentIf(_symbolApiKey != null, config => config.SetSymbolApiKey(_symbolApiKey)) - ); - } - - public PushBuildAction SetApiKey(string apiKey) - { - _apiKey = apiKey; - - return this; - } - - public PushBuildAction SetSource(string source) - { - _source = source; - - if (_source != null && !_source.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) - { - _source = "https://" + _source; - } - - return this; - } - - public PushBuildAction SetSymbolSource(string symbolSource) - { - _symbolSource = symbolSource; - - return this; - } - - public PushBuildAction SetSymbolApiKey(string symbolApiKey) - { - _symbolApiKey = symbolApiKey; - - return this; - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/RestoreBuildAction.cs b/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/RestoreBuildAction.cs deleted file mode 100644 index 2e5024a4..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/BuildActions/RestoreBuildAction.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; -using Nuke.Common.Tools.DotNet; - -namespace CreativeCoders.NukeBuild.BuildActions; - -[ExcludeFromCodeCoverage] -[PublicAPI] -public class RestoreBuildAction : BuildActionBase -{ - protected override void OnExecute() - { - DotNetTasks.DotNetRestore(s => s - .SetProjectFile(BuildInfo.Solution)); - } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/GitVersionWrapper.cs b/source/NukeBuild/CreativeCoders.NukeBuild/GitVersionWrapper.cs deleted file mode 100644 index 9c223b8f..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/GitVersionWrapper.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Nuke.Common.Tools.GitVersion; - -#nullable enable - -namespace CreativeCoders.NukeBuild; - -public class GitVersionWrapper(GitVersion? gitVersion, string defaultVersion, int defaultBuildRevision) - : IVersionInfo -{ - private static string SafeCallGitVersion(Func callGitVersion, string defaultGitVersion) - { - try - { - return callGitVersion() ?? defaultGitVersion; - } - catch (Exception) - { - return defaultGitVersion; - } - } - - public string GetAssemblySemVer() - => SafeCallGitVersion( - () => gitVersion?.AssemblySemVer, - $"{defaultVersion}.{defaultBuildRevision}"); - - public string GetAssemblySemFileVer() - => SafeCallGitVersion( - () => gitVersion?.AssemblySemFileVer, - $"{defaultVersion}.{defaultBuildRevision}"); - - public string InformationalVersion - => SafeCallGitVersion( - () => gitVersion?.InformationalVersion, - $"{defaultVersion}.{defaultBuildRevision}-unknown"); - - public string NuGetVersionV2 - => SafeCallGitVersion( - () => gitVersion?.NuGetVersionV2, - $"{defaultVersion}-unknown"); -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/IBuildInfo.cs b/source/NukeBuild/CreativeCoders.NukeBuild/IBuildInfo.cs deleted file mode 100644 index a307c81e..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/IBuildInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -using JetBrains.Annotations; -using Nuke.Common.Git; -using Nuke.Common.IO; -using Nuke.Common.ProjectModel; - -namespace CreativeCoders.NukeBuild; - -[PublicAPI] -public interface IBuildInfo -{ - string Configuration { get; } - - Solution Solution { get; } - - GitRepository GitRepository { get; } - - IVersionInfo VersionInfo { get; } - - AbsolutePath SourceDirectory { get; } - - AbsolutePath ArtifactsDirectory { get; } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/IVersionInfo.cs b/source/NukeBuild/CreativeCoders.NukeBuild/IVersionInfo.cs deleted file mode 100644 index e138731c..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/IVersionInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CreativeCoders.NukeBuild; - -public interface IVersionInfo -{ - string GetAssemblySemVer(); - - string GetAssemblySemFileVer(); - - string InformationalVersion { get; } - - string NuGetVersionV2 { get; } -} diff --git a/source/NukeBuild/CreativeCoders.NukeBuild/TargetDefinitionExtensions.cs b/source/NukeBuild/CreativeCoders.NukeBuild/TargetDefinitionExtensions.cs deleted file mode 100644 index 5b3c241b..00000000 --- a/source/NukeBuild/CreativeCoders.NukeBuild/TargetDefinitionExtensions.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using CreativeCoders.NukeBuild.BuildActions; -using JetBrains.Annotations; -using Nuke.Common; - -namespace CreativeCoders.NukeBuild; - -[PublicAPI] -public static class TargetDefinitionExtensions -{ - public static ITargetDefinition UseBuildAction(this ITargetDefinition targetDefinition) - where TBuildAction : IBuildAction, new() - { - var action = new TBuildAction(); - - return action.Setup(targetDefinition); - } - - public static ITargetDefinition UseBuildAction(this ITargetDefinition targetDefinition, - Action configureAction) - where TBuildAction : IBuildAction, new() - { - var action = new TBuildAction(); - - return action.Setup(targetDefinition, configureAction); - } - - public static ITargetDefinition UseBuildAction(this ITargetDefinition targetDefinition, - IBuildInfo buildInfo) - where TBuildAction : IBuildAction, new() - { - var action = new TBuildAction(); - - return action.Setup(targetDefinition, x => x.SetBuildInfo(buildInfo)); - } - - public static ITargetDefinition UseBuildAction(this ITargetDefinition targetDefinition, - IBuildInfo buildInfo, Action configureAction) - where TBuildAction : IBuildAction, new() - { - var action = new TBuildAction(); - - return action.Setup(targetDefinition, - x => - { - x.SetBuildInfo(buildInfo); - - configureAction(x); - }); - } - - public static ITargetDefinition ExecuteTarget(this ITargetDefinition targetDefinition, Target target) - { - return targetDefinition.Executes(() => target.Invoke(targetDefinition)); - } -} diff --git a/tests/CreativeCoders.AspNetCore.Tests/TokenAuth/Jwt/TestServerContext.cs b/tests/CreativeCoders.AspNetCore.Tests/TokenAuth/Jwt/TestServerContext.cs index f5f72cf2..a223f5d4 100644 --- a/tests/CreativeCoders.AspNetCore.Tests/TokenAuth/Jwt/TestServerContext.cs +++ b/tests/CreativeCoders.AspNetCore.Tests/TokenAuth/Jwt/TestServerContext.cs @@ -15,6 +15,8 @@ public sealed class TestServerContext : IAsyncDisposable { private readonly TestServer _testServer; + private readonly IHost _host; + public TestServerContext(Action? configureServices = null, Action? configureJwtApiOptions = null, Action? configureTokenApiOptions = null, @@ -52,7 +54,11 @@ public TestServerContext(Action? configureServices = null, }); }); - _testServer = new TestServer(webHostBuilder); + _host = webHostBuilder.Build(); + + _host.StartAsync().Wait(); + + _testServer = _host.GetTestServer(); HttpClient = _testServer.CreateClient(); } @@ -67,15 +73,20 @@ public TestServerContext(Action? configureServices = null, public async ValueTask DisposeAsync() { - await _testServer.Host.StopAsync(); - - _testServer.Dispose(); + await _host.StopAsync(); + _host.Dispose(); } - private static IWebHostBuilder SetupWebHostBuilder(Action? configureServices) + private static IHostBuilder SetupWebHostBuilder(Action? configureServices) { - return new WebHostBuilder() - .ConfigureServices(services => configureServices?.Invoke(services)) - .UseStartup(); + return new HostBuilder() + .ConfigureWebHost(webHostBuilder => + { + webHostBuilder + .ConfigureServices(services => configureServices?.Invoke(services)) + .UseTestServer() // If using TestServer + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup(); + }); } } diff --git a/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj b/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj index d35fcf4b..c6287dab 100644 --- a/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj +++ b/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj @@ -9,9 +9,8 @@ - - - + + @@ -22,11 +21,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - + diff --git a/tests/CreativeCoders.MiscTest.UnitTests/NukeBuild/GitVersionWrapperTests.cs b/tests/CreativeCoders.MiscTest.UnitTests/NukeBuild/GitVersionWrapperTests.cs deleted file mode 100644 index b1d1cbaa..00000000 --- a/tests/CreativeCoders.MiscTest.UnitTests/NukeBuild/GitVersionWrapperTests.cs +++ /dev/null @@ -1,270 +0,0 @@ -using CreativeCoders.NukeBuild; -using FakeItEasy; -using AwesomeAssertions; -using Nuke.Common.Tools.GitVersion; -using Xunit; - -namespace CreativeCoders.MiscTest.UnitTests.NukeBuild; - -public class GitVersionWrapperTests -{ - [Theory] - [InlineData("1", 1, 1, 1, 0, "")] - [InlineData("1.0", 1, 1, 0, 1, "")] - [InlineData("1.0.1", 1, 1, 1, 1, "1")] - public void GetAssemblySemVer_GitVersionThrowsException_ReturnsDefaultVersion( - string defaultVersion, int defaultBuildRevision, int expectedMajor, - int expectedMinor, int expectedPatch, string expectedBuildMetaData) - { - var gitVersion = CreateGitVersion(expectedMajor, expectedMinor, expectedPatch, expectedBuildMetaData); - - var versionWrapper = new GitVersionWrapper(gitVersion, defaultVersion, defaultBuildRevision); - - // Act - var actualVersion = versionWrapper.GetAssemblySemVer(); - - // Assert - actualVersion - .Should() - .Be($"{expectedMajor}.{expectedMinor}.{expectedPatch}-{expectedBuildMetaData}"); - } - - [Theory] - [InlineData("1", 1, 1, 1, 0, "")] - [InlineData("1.0", 1, 1, 0, 1, "")] - [InlineData("1.0.1", 1, 1, 1, 1, "1")] - public void GetAssemblySemVer_GitVersionReturnsNull_ReturnsDefaultVersion( - string defaultVersion, int defaultBuildRevision, int expectedMajor, - int expectedMinor, int expectedPatch, string expectedBuildMetaData) - { - var gitVersion = CreateGitVersion(expectedMajor, expectedMinor, expectedPatch, expectedBuildMetaData); - - var versionWrapper = new GitVersionWrapper(gitVersion, defaultVersion, defaultBuildRevision); - - // Act - var actualVersion = versionWrapper.GetAssemblySemVer(); - - // Assert - actualVersion - .Should() - .Be($"{expectedMajor}.{expectedMinor}.{expectedPatch}-{expectedBuildMetaData}"); - } - - [Theory] - [InlineData(1, 1, 0, "")] - [InlineData(1, 0, 1, "")] - [InlineData(1, 1, 1, "1")] - public void GetAssemblySemVer_GitVersionReturnsVersion_ReturnsVersion(int expectedMajor, - int expectedMinor, int expectedPatch, string expectedBuildMetaData) - { - var gitVersion = CreateGitVersion(expectedMajor, expectedMinor, expectedPatch, expectedBuildMetaData); - - var versionWrapper = new GitVersionWrapper(gitVersion, "2.0", 2); - - // Act - var actualVersion = versionWrapper.GetAssemblySemVer(); - - // Assert - actualVersion - .Should() - .Be($"{expectedMajor}.{expectedMinor}.{expectedPatch}-{expectedBuildMetaData}"); - } - - [Theory] - [InlineData("1", 1)] - [InlineData("1.0", 1)] - [InlineData("1.0.1", 1)] - public void GetAssemblySemFileVer_GitVersionReturnsNull_ReturnsDefaultVersion( - string defaultVersion, int defaultBuildRevision) - { - var gitVersion = CreateGitVersionWithEmptyProps(); - - var versionWrapper = new GitVersionWrapper(gitVersion, defaultVersion, defaultBuildRevision); - - // Act - var actualVersion = versionWrapper.GetAssemblySemFileVer(); - - // Assert - actualVersion - .Should() - .Be(defaultVersion + $".{defaultBuildRevision}"); - } - - [Theory] - [InlineData(1, 0, 0, "")] - [InlineData(1, 2, 3, "b12")] - public void GetAssemblySemFileVer_GitVersionReturnsVersion_ReturnsVersion(int expectedMajor, - int expectedMinor, int expectedPatch, string expectedBuildMetaData) - { - var gitVersion = CreateGitVersion(expectedMajor, expectedMinor, expectedPatch, expectedBuildMetaData); - - var versionWrapper = new GitVersionWrapper(gitVersion, "2.0", 2); - - // Act - var actualVersion = versionWrapper.GetAssemblySemFileVer(); - - // Assert - actualVersion - .Should() - .Be($"{expectedMajor}.{expectedMinor}.{expectedPatch}-{expectedBuildMetaData}"); - } - - [Theory] - [InlineData("1", 1, "1.1-unknown")] - [InlineData("1.0", 1, "1.0.1-unknown")] - [InlineData("1.0.1", 1, "1.0.1.1-unknown")] - public void InformationalVersion_GitVersionReturnsNull_ReturnsDefaultVersion( - string defaultVersion, int defaultBuildRevision, string expectedVersion) - { - var gitVersion = CreateGitVersionWithEmptyProps(); - - var versionWrapper = new GitVersionWrapper(gitVersion, defaultVersion, defaultBuildRevision); - - // Act - var actualVersion = versionWrapper.InformationalVersion; - - // Assert - actualVersion - .Should() - .Be(expectedVersion); - } - - [Theory] - [InlineData(1, 0, 0, "")] - [InlineData(1, 2, 3, "b12")] - public void InformationalVersion_GitVersionReturnsVersion_ReturnsVersion(int expectedMajor, - int expectedMinor, int expectedPatch, string expectedBuildMetaData) - { - var gitVersion = CreateGitVersion(expectedMajor, expectedMinor, expectedPatch, expectedBuildMetaData); - - var versionWrapper = new GitVersionWrapper(gitVersion, "2.0", 2); - - // Act - var actualVersion = versionWrapper.InformationalVersion; - - // Assert - actualVersion - .Should() - .Be($"{expectedMajor}.{expectedMinor}.{expectedPatch}-{expectedBuildMetaData}"); - } - - [Theory] - [InlineData("1", 1, "1-unknown")] - [InlineData("1.0", 1, "1.0-unknown")] - [InlineData("1.0.1", 1, "1.0.1-unknown")] - public void NuGetVersionV2_GitVersionReturnsNull_ReturnsDefaultVersion( - string defaultVersion, int defaultBuildRevision, string expectedVersion) - { - var gitVersion = CreateGitVersionWithEmptyProps(); - - var versionWrapper = new GitVersionWrapper(gitVersion, defaultVersion, defaultBuildRevision); - - // Act - var actualVersion = versionWrapper.NuGetVersionV2; - - // Assert - actualVersion - .Should() - .Be(expectedVersion); - } - - [Theory] - [InlineData(1, 0, 0, "")] - [InlineData(1, 2, 3, "b12")] - public void NuGetVersionV2_GitVersionReturnsVersion_ReturnsVersion(int expectedMajor, - int expectedMinor, int expectedPatch, string expectedBuildMetaData) - { - var gitVersion = CreateGitVersion(expectedMajor, expectedMinor, expectedPatch, expectedBuildMetaData); - - var versionWrapper = new GitVersionWrapper(gitVersion, "2.0", 2); - - // Act - var actualVersion = versionWrapper.NuGetVersionV2; - - // Assert - actualVersion - .Should() - .Be($"{expectedMajor}.{expectedMinor}.{expectedPatch}"); - } - - private GitVersion CreateGitVersionWithEmptyProps() - { - return new GitVersion( - BranchName: "main", - Sha: "dummySha", - ShortSha: "dummy", - Major: 0, - Minor: 0, - Patch: 0, - PreReleaseTag: string.Empty, - PreReleaseTagWithDash: string.Empty, - PreReleaseLabel: string.Empty, - PreReleaseLabelWithDash: string.Empty, - PreReleaseNumber: null, - WeightedPreReleaseNumber: null, - BuildMetaData: null, - BuildMetaDataPadded: string.Empty, - FullBuildMetaData: string.Empty, - MajorMinorPatch: null, - SemVer: null, - LegacySemVer: null, - LegacySemVerPadded: null, - AssemblySemVer: null, - AssemblySemFileVer: null, - FullSemVer: null, - InformationalVersion: null, - EscapedBranchName: "main", - CommitDate: DateTimeOffset.Now.ToString(), - CommitsSinceVersionSource: "0", - CommitsSinceVersionSourcePadded: "0000", - UncommittedChanges: 0, - VersionSourceSha: "dummySourceSha", - NuGetVersionV2: null, - NuGetVersion: null, - NuGetPreReleaseTagV2: string.Empty, - NuGetPreReleaseTag: string.Empty - ); - } - - private GitVersion CreateGitVersion(int major, int minor, int patch, string buildMetaData) - { - var shortVersion = $"{major}.{minor}.{patch}"; - var fullVersion = $"{major}.{minor}.{patch}-{buildMetaData}"; - - return new GitVersion( - BranchName: "main", - Sha: "dummySha", - ShortSha: "dummy", - Major: major, - Minor: minor, - Patch: patch, - PreReleaseTag: string.Empty, - PreReleaseTagWithDash: string.Empty, - PreReleaseLabel: string.Empty, - PreReleaseLabelWithDash: string.Empty, - PreReleaseNumber: null, - WeightedPreReleaseNumber: null, - BuildMetaData: buildMetaData, - BuildMetaDataPadded: string.Empty, - FullBuildMetaData: string.Empty, - MajorMinorPatch: shortVersion, - SemVer: shortVersion, - LegacySemVer: shortVersion, - LegacySemVerPadded: shortVersion, - AssemblySemVer: fullVersion, - AssemblySemFileVer: fullVersion, - FullSemVer: shortVersion, - InformationalVersion: fullVersion, - EscapedBranchName: "main", - CommitDate: DateTimeOffset.Now.ToString(), - CommitsSinceVersionSource: "0", - CommitsSinceVersionSourcePadded: "0000", - UncommittedChanges: 0, - VersionSourceSha: "dummySourceSha", - NuGetVersionV2: shortVersion, - NuGetVersion: shortVersion, - NuGetPreReleaseTagV2: string.Empty, - NuGetPreReleaseTag: string.Empty - ); - } -} diff --git a/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj b/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj index b6c59270..61fc06fa 100644 --- a/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj +++ b/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj @@ -29,8 +29,4 @@ - - - -