diff --git a/.build/Build.Clean.cs b/.build/Build.Clean.cs index 3e39cd3..b902c7b 100644 --- a/.build/Build.Clean.cs +++ b/.build/Build.Clean.cs @@ -1,12 +1,10 @@ -using JetBrains.Annotations; - using Nuke.Common; using Nuke.Common.Tools.DotNet; partial class Build : NukeBuild { Target Clean => _ => _ - .Description("Cleans the build tree") + .Description("Cleans the build tree.\n") .Before(Restore) .Executes(() => DotNetTasks.DotNetClean(c => c.SetProject(SolutionFilePath))); diff --git a/.build/Build.Compile.cs b/.build/Build.Compile.cs index 490beca..e2f3cbf 100644 --- a/.build/Build.Compile.cs +++ b/.build/Build.Compile.cs @@ -4,12 +4,12 @@ partial class Build : NukeBuild { Target Restore => _ => _ - .Description("Downloads and install .NET packages") + .Description("Downloads and install .NET packages.\n") .Executes(() => DotNetTasks.DotNetRestore(c => c.SetProjectFile(SolutionFilePath))); Target Compile => _ => _ - .Description("Compiles the entire build tree") + .Description("Compiles the entire build tree.\n") .DependsOn(Restore) .Executes(() => DotNetTasks.DotNetBuild(c => c diff --git a/.build/Build.Docker.cs b/.build/Build.Docker.cs index b3490c0..796d2e9 100644 --- a/.build/Build.Docker.cs +++ b/.build/Build.Docker.cs @@ -11,19 +11,12 @@ 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) - ? ["latest", $"{GitVersion.Major}", $"{GitVersion.Major}.{GitVersion.Minor}", $"{GitVersion.MajorMinorPatch}"] - : ["develop", $"develop-{GitVersion.MajorMinorPatch}.{GitVersion.PreReleaseNumber}"]; - - private string[] DockerImageTags => DockerVersionTags.Select(version => $"{DockerImage}:{version}").ToArray(); - - private string[] DockerImagePlatforms => ["linux/amd64", "linux/arm", "linux/arm64"]; + [Parameter("List of platforms to build the Docker image for")] + readonly string[] ImagePlatforms = ["linux/amd64", "linux/arm", "linux/arm64"]; Target AssertDockerPush => _ => _ .Unlisted() - .Description("Asserts whether the built Docker image can be pushed.") + .Description("Asserts whether the built Docker image can be pushed.\n") .Before(Restore) .Executes(() => { @@ -34,7 +27,7 @@ partial class Build : NukeBuild }); Target BuildImage => _ => _ - .Description("Builds the Docker image of Fetcharr, and optionally pushes it to GHCR.") + .Description("Builds the Docker image of Fetcharr, and optionally pushes it to GHCR.\n") .DependsOn(AssertDockerPush) .DependsOn(Test) .DependsOn(Format) @@ -42,15 +35,15 @@ partial class Build : NukeBuild DockerBuildxBuild(x => x .SetPath(".") .SetFile("Dockerfile") - .SetTag(this.DockerImageTags) - .SetPlatform(string.Join(",", this.DockerImagePlatforms)) + .SetTag(this.VersionTags.Select(version => $"{DockerImage}:{version}").ToArray()) + .SetPlatform(string.Join(",", this.ImagePlatforms)) .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") - .AddLabel("org.opencontainers.image.url=https://github.com/fetcharr/fetcharr") - .AddLabel("org.opencontainers.image.description=Automatically sync Plex watchlist to your Sonarr and Radarr instances.") - .AddLabel("org.opencontainers.image.licenses=MIT") + .AddLabel($"org.opencontainers.image.source={RepositoryUrl}") + .AddLabel($"org.opencontainers.image.url={RepositoryUrl}") + .AddLabel($"org.opencontainers.image.description={RepositoryDescription}") + .AddLabel($"org.opencontainers.image.licenses={RepositoryLicense}") .SetProcessLogger((outputType, output) => { // Workaround for all Docker messages being logged as errors. diff --git a/.build/Build.Environment.cs b/.build/Build.Environment.cs index 303c66b..76e9437 100644 --- a/.build/Build.Environment.cs +++ b/.build/Build.Environment.cs @@ -1,10 +1,19 @@ using Nuke.Common; +using Nuke.Common.CI.GitHubActions; using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.Tools.GitVersion; partial class Build : NukeBuild { + private const string RepositoryUrl = "https://github.com/fetcharr/fetcharr"; + + private const string RepositoryDescription = "Automatically sync Plex watchlist to your Sonarr and Radarr instances."; + + private const string RepositoryLicense = "MIT"; + + private const string DockerImage = "ghcr.io/fetcharr/fetcharr"; + private AbsolutePath SourceDirectory => RootDirectory / "src"; private AbsolutePath SolutionFilePath => SourceDirectory / "Fetcharr.sln"; @@ -14,4 +23,35 @@ partial class Build : NukeBuild [GitRepository] readonly GitRepository Repository; + + GitHubActions GitHubActions => GitHubActions.Instance; + + /// + /// Gets whether NUKE is building a release build or not. + /// + private bool IsReleaseBuild => GitVersion.BranchName.Equals("main", StringComparison.InvariantCultureIgnoreCase); + + /// + /// Gets the version tag for the current build, with release version numbering. + /// + private string ReleaseVersionTag => GitVersion.MajorMinorPatch; + + /// + /// Gets the version tag for the current build, with development version numbering. + /// + private string DevelopmentVersionTag => $"develop-{GitVersion.MajorMinorPatch}.{GitVersion.PreReleaseNumber}"; + + /// + /// Gets the primary version tag for the current version. + /// + private string VersionTag => this.IsReleaseBuild + ? ReleaseVersionTag + : DevelopmentVersionTag; + + /// + /// Gets the version tags for the current version. + /// + private string[] VersionTags => this.IsReleaseBuild + ? ["latest", $"{GitVersion.Major}", $"{GitVersion.Major}.{GitVersion.Minor}", ReleaseVersionTag] + : ["develop", DevelopmentVersionTag]; } \ No newline at end of file diff --git a/.build/Build.Format.cs b/.build/Build.Format.cs index e341b90..e098e3e 100644 --- a/.build/Build.Format.cs +++ b/.build/Build.Format.cs @@ -6,7 +6,7 @@ partial class Build : NukeBuild { Target Format => _ => _ - .Description("Performs linting on the build tree") + .Description("Performs linting on the build tree.\n") .DependsOn(Restore) .Executes(() => DotNetFormat(c => c diff --git a/.build/Build.Release.cs b/.build/Build.Release.cs index 31b17d5..dfe0d80 100644 --- a/.build/Build.Release.cs +++ b/.build/Build.Release.cs @@ -5,11 +5,8 @@ partial class Build : NukeBuild { - [Parameter("Whether the release is a pre-release or not.")] - readonly bool PreRelease; - Target Release => _ => _ - .Description("Creates and pushes a new release to GitHub") + .Description("Creates and pushes a new release to GitHub.\n") .DependsOn(BuildImage) .Requires(() => this.GithubToken) .Executes(async () => @@ -20,10 +17,10 @@ partial class Build : NukeBuild Credentials = new Credentials(this.GithubToken) }; - NewRelease release = new(GitVersion.MajorMinorPatch) + NewRelease release = new(this.VersionTag) { - Name = GitVersion.MajorMinorPatch, - Prerelease = this.PreRelease, + Name = this.VersionTag, + Prerelease = !this.IsReleaseBuild, Draft = false, GenerateReleaseNotes = true, MakeLatest = MakeLatestQualifier.True, diff --git a/.build/Build.Test.cs b/.build/Build.Test.cs index d8e6a89..f27bdfd 100644 --- a/.build/Build.Test.cs +++ b/.build/Build.Test.cs @@ -7,7 +7,7 @@ partial class Build : NukeBuild readonly bool IncludeIntegrationTests = false; Target Test => _ => _ - .Description("Runs test suites within the build tree") + .Description("Runs test suites within the build tree.\n") .DependsOn(Compile) .Executes(() => DotNetTasks.DotNetTest(c => c diff --git a/.build/Build.cs b/.build/Build.cs index 7a06651..fa8d7cd 100644 --- a/.build/Build.cs +++ b/.build/Build.cs @@ -11,13 +11,23 @@ partial class Build : NukeBuild ? Configuration.Debug : Configuration.Release; - [Parameter] [Secret] + [Parameter("GitHub Token for pushing Docker images to GHCR")] readonly string GithubToken; protected override void OnBuildInitialized() { Serilog.Log.Information("🔥 Build process started"); + Serilog.Log.Information(" Repository: {Repository}", this.Repository.HttpsUrl); + Serilog.Log.Information(" Version: {Version}", this.VersionTag); + Serilog.Log.Information(" Tags: {VersionTags}", this.VersionTags); + Serilog.Log.Information(" IsRelease: {IsReleaseBuild}", this.IsReleaseBuild); + + if(this.GitHubActions is not null) + { + Serilog.Log.Information(" Branch: {BranchName}", this.GitHubActions.Ref); + Serilog.Log.Information(" Commit: {CommitSha}", this.GitHubActions.Sha); + } base.OnBuildInitialized(); } diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 5c6c2b4..bfe9896 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -20,6 +20,7 @@ }, "GithubToken": { "type": "string", + "description": "GitHub Token for pushing Docker images to GHCR", "default": "Secrets must be entered via 'nuke :secrets [profile]'" }, "Help": { @@ -47,6 +48,13 @@ "VSCode" ] }, + "ImagePlatforms": { + "type": "array", + "description": "List of platforms to build the Docker image for", + "items": { + "type": "string" + } + }, "IncludeIntegrationTests": { "type": "boolean", "description": "Whether to include integration tests (default: false)" @@ -63,10 +71,6 @@ "type": "boolean", "description": "Shows the execution plan (HTML)" }, - "PreRelease": { - "type": "boolean", - "description": "Whether the release is a pre-release or not" - }, "Profile": { "type": "array", "description": "Defines the profiles to load",