diff --git a/.build/Build.Clean.cs b/.build/Build.Clean.cs index 07190be..3e39cd3 100644 --- a/.build/Build.Clean.cs +++ b/.build/Build.Clean.cs @@ -1,9 +1,12 @@ +using JetBrains.Annotations; + using Nuke.Common; using Nuke.Common.Tools.DotNet; partial class Build : NukeBuild { Target Clean => _ => _ + .Description("Cleans the build tree") .Before(Restore) .Executes(() => DotNetTasks.DotNetClean(c => c.SetProject(SolutionFilePath))); diff --git a/.build/Build.Compile.cs b/.build/Build.Compile.cs index 05dc3c1..490beca 100644 --- a/.build/Build.Compile.cs +++ b/.build/Build.Compile.cs @@ -4,10 +4,12 @@ partial class Build : NukeBuild { Target Restore => _ => _ + .Description("Downloads and install .NET packages") .Executes(() => DotNetTasks.DotNetRestore(c => c.SetProjectFile(SolutionFilePath))); Target Compile => _ => _ + .Description("Compiles the entire build tree") .DependsOn(Restore) .Executes(() => DotNetTasks.DotNetBuild(c => c diff --git a/.build/Build.Docker.cs b/.build/Build.Docker.cs index fcc50c9..b3490c0 100644 --- a/.build/Build.Docker.cs +++ b/.build/Build.Docker.cs @@ -8,6 +8,9 @@ partial class Build : NukeBuild { + [Parameter("Whether to push the built Docker image to GHCR")] + readonly bool PushImage = false; + private string DockerImage => $"ghcr.io/fetcharr/fetcharr"; private string[] DockerVersionTags => GitVersion.BranchName.Equals("main", StringComparison.InvariantCultureIgnoreCase) @@ -18,17 +21,30 @@ partial class Build : NukeBuild private string[] DockerImagePlatforms => ["linux/amd64", "linux/arm", "linux/arm64"]; + Target AssertDockerPush => _ => _ + .Unlisted() + .Description("Asserts whether the built Docker image can be pushed.") + .Before(Restore) + .Executes(() => + { + if(this.PushImage && string.IsNullOrEmpty(this.GithubToken)) + { + Assert.Fail("Cannot push Docker image, when GitHub token is not set."); + } + }); + Target BuildImage => _ => _ + .Description("Builds the Docker image of Fetcharr, and optionally pushes it to GHCR.") + .DependsOn(AssertDockerPush) .DependsOn(Test) .DependsOn(Format) - .Requires(() => this.GithubToken) .Executes(() => DockerBuildxBuild(x => x .SetPath(".") .SetFile("Dockerfile") .SetTag(this.DockerImageTags) .SetPlatform(string.Join(",", this.DockerImagePlatforms)) - .SetPush(true) + .SetPush(this.PushImage && this.GithubToken is not null) .AddCacheFrom("type=gha") .AddCacheTo("type=gha,mode=max") .AddLabel("org.opencontainers.image.source=https://github.com/fetcharr/fetcharr") diff --git a/.build/Build.Format.cs b/.build/Build.Format.cs index 3808644..e341b90 100644 --- a/.build/Build.Format.cs +++ b/.build/Build.Format.cs @@ -6,6 +6,7 @@ partial class Build : NukeBuild { Target Format => _ => _ + .Description("Performs linting on the build tree") .DependsOn(Restore) .Executes(() => DotNetFormat(c => c diff --git a/.build/Build.Release.cs b/.build/Build.Release.cs index ccbe4e1..31b17d5 100644 --- a/.build/Build.Release.cs +++ b/.build/Build.Release.cs @@ -9,6 +9,7 @@ partial class Build : NukeBuild readonly bool PreRelease; Target Release => _ => _ + .Description("Creates and pushes a new release to GitHub") .DependsOn(BuildImage) .Requires(() => this.GithubToken) .Executes(async () => diff --git a/.build/Build.Test.cs b/.build/Build.Test.cs index 94e115c..d8e6a89 100644 --- a/.build/Build.Test.cs +++ b/.build/Build.Test.cs @@ -7,6 +7,7 @@ partial class Build : NukeBuild readonly bool IncludeIntegrationTests = false; Target Test => _ => _ + .Description("Runs test suites within the build tree") .DependsOn(Compile) .Executes(() => DotNetTasks.DotNetTest(c => c diff --git a/.build/Build.cs b/.build/Build.cs index 75a663a..7a06651 100644 --- a/.build/Build.cs +++ b/.build/Build.cs @@ -1,13 +1,9 @@ using Nuke.Common; +using Nuke.Common.Execution; +[UnsetVisualStudioEnvironmentVariables] partial class Build : NukeBuild { - /// Support plugins are available for: - /// - JetBrains ReSharper https://nuke.build/resharper - /// - JetBrains Rider https://nuke.build/rider - /// - Microsoft VisualStudio https://nuke.build/visualstudio - /// - Microsoft VSCode https://nuke.build/vscode - public static int Main() => Execute(x => x.Compile); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 734c915..78b50fb 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -51,6 +51,6 @@ jobs: - name: Push development image if: ${{ github.ref == 'refs/heads/develop' }} - run: ./build.cmd BuildImage + run: ./build.cmd BuildImage --include-integration-tests --push-image env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 8ffd33f..5c6c2b4 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -74,6 +74,10 @@ "type": "string" } }, + "PushImage": { + "type": "boolean", + "description": "Whether to push the built Docker image to GHCR" + }, "Root": { "type": "string", "description": "Root directory during build execution" @@ -84,6 +88,7 @@ "items": { "type": "string", "enum": [ + "AssertDockerPush", "BuildImage", "Clean", "Compile", @@ -100,6 +105,7 @@ "items": { "type": "string", "enum": [ + "AssertDockerPush", "BuildImage", "Clean", "Compile",