diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a1b55c0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,37 @@ +name: Main CI-CD + +env: + SIMCUBE_NUGET_SERVER: https://api.nuget.org/v3/index.json + SIMCUBE_NUGET_API_KEY: ${{ secrets.PUBLIC_NUGET_TOKEN }} + DOTNET_NOLOGO: true + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + +on: + push: + tags: + - "*" + + workflow_dispatch: + +jobs: + build-test-pull-request: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: '7.0.x' + + - name: Build, Test and Pack + run: | + dotnet tool restore + dotnet cake --pack true + + - name: Push to nuget + working-directory: artifacts/ + run: dotnet nuget push *.nupkg -s $SIMCUBE_NUGET_SERVER -k $SIMCUBE_NUGET_API_KEY diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml deleted file mode 100644 index cf50a74..0000000 --- a/.github/workflows/master.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Master Deploy - -env: - SIMCUBE_SONARQUBE_ENABLED: "true" - SIMCUBE_SONARQUBE_URL: ${{ secrets.SONAR_HOST }} - SIMCUBE_SONARQUBE_API_KEY: ${{ secrets.SONAR_API_KEY }} - SIMCUBE_SONARQUBE_PROJECT_KEY: "CakeBuildah" - SIMCUBE_SOLUTION_FILE_PATH: "Cake.Buildah.sln" - SIMCUBE_BUILD_NAME: "Cake.Buildah" - SIMCUBE_DOTNET_TOOL_PATH: "/home/runner/.dotnet/tools" - SIMCUBE_SOLUTION_ROOT: ${{ github.workspace }} - SIMCUBE_MANUAL_VERSION: 1.0.${{ github.run_number }}.0 - SIMCUBE_MANUAL_BRANCH_NAME: ${{ github.ref_name }} - SIMCUBE_NUGET_SERVER: https://api.nuget.org/v3/index.json - SIMCUBE_NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - SIMCUBE_YAML_CONFIG_ENABLED: "true" - DOTNET_NOLOGO: true - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_CLI_TELEMETRY_OPTOUT: true - -on: - push: - branches: - - master - - workflow_dispatch: - -jobs: - build-test-analyse-and-publish: - runs-on: ubuntu-latest - - steps: - - uses: SimCubeLtd/buildtool-action@main - with: - installRequired: 'true' - checkout: 'true' - setupDotNet: 'true' diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 7de420a..850f258 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -1,16 +1,6 @@ name: Pull Requests env: - SIMCUBE_SONARQUBE_PROJECT_KEY: "CakeBuildah" - SIMCUBE_SOLUTION_FILE_PATH: "Cake.Buildah.sln" - SIMCUBE_BUILD_NAME: "Cake.Buildah" - SIMCUBE_DOTNET_TOOL_PATH: "/home/runner/.dotnet/tools" - SIMCUBE_SOLUTION_ROOT: ${{ github.workspace }} - SIMCUBE_MANUAL_VERSION: 1.0.${{ github.run_number }}.0 - SIMCUBE_MANUAL_BRANCH_NAME: ${{ github.ref_name }} - SIMCUBE_PULL_REQUEST_NUMBER: ${{ github.event.number }} - SIMCUBE_PULL_REQUEST_SOURCE_BRANCH: ${{ github.head_ref }} - SIMCUBE_PULL_REQUEST_TARGET_BRANCH: ${{ github.base_ref }} DOTNET_NOLOGO: true DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true DOTNET_CLI_TELEMETRY_OPTOUT: true @@ -19,7 +9,7 @@ on: - pull_request jobs: - build-test-and-analyse-pull-request: + build-test-pull-request: runs-on: ubuntu-latest steps: @@ -27,24 +17,11 @@ jobs: with: fetch-depth: 0 - - if: "! github.event.pull_request.head.repo.fork " - name: "Building from Main Repository. Analysis is Supported." - uses: SimCubeLtd/buildtool-action@main - env: - SIMCUBE_SONARQUBE_URL: ${{ secrets.SONAR_HOST }} - SIMCUBE_SONARQUBE_API_KEY: ${{ secrets.SONAR_API_KEY }} - SIMCUBE_SONARQUBE_ENABLED: "true" - SIMCUBE_ENABLE_QUALITY_GATE: "true" + - uses: actions/setup-dotnet@v3 with: - installRequired: 'true' - checkout: 'true' - setupDotNet: 'true' - - - if: " github.event.pull_request.head.repo.fork " - name: "Building from Fork. Analysis is not supported" - uses: SimCubeLtd/buildtool-action@main - with: - installRequired: 'true' - checkout: 'true' - setupDotNet: 'true' + dotnet-version: '7.0.x' + - name: Build, Test and Pack + run: | + dotnet tool restore + dotnet cake diff --git a/.gitignore b/.gitignore index 7b95662..74793aa 100644 --- a/.gitignore +++ b/.gitignore @@ -352,3 +352,5 @@ MigrationBackup/ Artifacts/ tools/ .idea/ + +.DS_Store diff --git a/Cake.Buildah.sln b/Cake.Buildah.sln index 50a5154..8e82764 100644 --- a/Cake.Buildah.sln +++ b/Cake.Buildah.sln @@ -11,7 +11,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Build.props = Directory.Build.props LICENSE = LICENSE README.md = README.md - SimCubeBuildTool.yml = SimCubeBuildTool.yml + build.cake = build.cake + dotnet-tools.json = dotnet-tools.json + global.json = global.json EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F17B1FA8-2860-40C7-BD34-8A5D7FE7A6E4}" @@ -24,8 +26,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Buildah.Tests", "tests EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{449F9620-38BD-4278-AD27-6582EEF3A18D}" ProjectSection(SolutionItems) = preProject - .github\workflows\master.yml = .github\workflows\master.yml .github\workflows\pull-requests.yml = .github\workflows\pull-requests.yml + .github\workflows\main.yml = .github\workflows\main.yml EndProjectSection EndProject Global diff --git a/SimCubeBuildTool.yml b/SimCubeBuildTool.yml deleted file mode 100644 index fb2147f..0000000 --- a/SimCubeBuildTool.yml +++ /dev/null @@ -1,8 +0,0 @@ -#-------------------------------------------------------- -# Packable Item Configuration -#-------------------------------------------------------- -packableConfig: - pushPackages: true - packages: - - projectName: Cake.Buildah - includeSource: false diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..bd4a0d8 --- /dev/null +++ b/build.cake @@ -0,0 +1,104 @@ +#addin nuget:?package=SimpleExec&version=11.0.0 +#addin "nuget:?package=Cake.MinVer&version=3.0.0" + +using System.Text.Json; +using SimpleExec; + +var target = Argument("Target", "Default"); + +var configuration = + HasArgument("Configuration") ? Argument("Configuration") : + EnvironmentVariable("Configuration", "Release"); + +var shouldPack = HasArgument("pack") ? Argument("pack") : false; + +var settings = new MinVerSettings() +{ + AutoIncrement = MinVerAutoIncrement.Minor, + DefaultPreReleasePhase = "preview", + MinimumMajorMinor = "1.0", + TagPrefix = "v", + Verbosity = MinVerVerbosity.Trace, +}; + +var version = MinVer(settings); + +Task("Clean") + .Description("Cleans the artifacts, bin and obj directories.") + .Does(() => + { + DeleteDirectories(GetDirectories("**/bin"), new DeleteDirectorySettings() { Force = true, Recursive = true }); + DeleteDirectories(GetDirectories("**/obj"), new DeleteDirectorySettings() { Force = true, Recursive = true }); + CleanDirectory("./artifacts"); + CleanDirectory("./test-output"); + }); + +Task("Restore") + .Description("Restores NuGet packages.") + .IsDependentOn("Clean") + .Does(() => + { + DotNetRestore(); + }); + +Task("Build") + .Description("Builds the solution.") + .IsDependentOn("Restore") + .Does(() => + { + DotNetBuild( + ".", + new DotNetBuildSettings() + { + Configuration = configuration, + NoRestore = true, + ArgumentCustomization = args => + args + .Append($"-p:Version={version}") + .Append($"-p:InformationalVersion={version}"), + }); + }); + +Task("Test") + .Description("Runs unit tests and outputs test results to the artifacts directory.") + .Does(() => + { + DotNetTest( + "tests/Cake.Buildah.Tests/Cake.Buildah.Tests.csproj", + new DotNetTestSettings() + { + Blame = true, + Configuration = configuration, + ResultsDirectory = "./test-output", + NoBuild = true, + NoRestore = true, + Collectors = new string[] { "Code Coverage", "XPlat Code Coverage" }, + }); + }); + +Task("Pack") + .Description("Packs the Required Project") + .IsDependentOn("Test") + .WithCriteria(shouldPack) + .Does(() => + { + DotNetPack("src/Cake.Buildah/Cake.Buildah.csproj", + new DotNetPackSettings() + { + NoBuild = true, + NoRestore = true, + NoLogo = true, + OutputDirectory = "./artifacts", + Verbosity = DotNetVerbosity.Minimal, + Configuration = configuration, + ArgumentCustomization = builder => builder.Append($"-p:PackageVersion={version}") + }); + }); + +Task("Default") + .Description("Cleans, restores NuGet packages, builds the solution and then runs unit tests.") + .IsDependentOn("Build") + .IsDependentOn("Test") + .IsDependentOn("Pack"); + +RunTarget(target); diff --git a/dotnet-tools.json b/dotnet-tools.json new file mode 100644 index 0000000..52d8bff --- /dev/null +++ b/dotnet-tools.json @@ -0,0 +1,18 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "3.0.0", + "commands": [ + "dotnet-cake" + ] + }, + "minver-cli": { + "version": "4.2.0", + "commands": [ + "minver" + ] + } + } +} diff --git a/global.json b/global.json new file mode 100644 index 0000000..9c9b66d --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "7.0.100", + "rollForward": "latestMajor", + "allowPrerelease": false + } +} diff --git a/tests/Cake.Buildah.Tests/Cake.Buildah.Tests.csproj b/tests/Cake.Buildah.Tests/Cake.Buildah.Tests.csproj index b5df265..76a4718 100644 --- a/tests/Cake.Buildah.Tests/Cake.Buildah.Tests.csproj +++ b/tests/Cake.Buildah.Tests/Cake.Buildah.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 latest None false