Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.7.0
**Features**
- Added the configuration file name as an argument
- Merged the project and solution configuration files
- Separated archive naming from project names
- Added ability to add arbitrary substitutions

## 0.6.0
**Other**
- Upgraded to .NET 10
Expand Down
7 changes: 0 additions & 7 deletions Common.Build.Generator/buildConfig.json

This file was deleted.

7 changes: 4 additions & 3 deletions Common.Build/Config/ProjectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace Common.Build.Config;
[UsedImplicitly(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.Members)]
public class ProjectConfig
{
public required string? Name { get; init; }
public required string? OutputSubdir { get; init; }
public required List<string> Substitute { get; init; }
public required string Name { get; init; }
public required string? ArchiveSuffix { get; init; }
public required string? OutputSubdirectory { get; init; }
public required List<string> SubstitutionTargets { get; init; }
}
4 changes: 3 additions & 1 deletion Common.Build/Config/SolutionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Common.Build.Config;
[UsedImplicitly(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.Members)]
public class SolutionConfig
{
public required string Name { get; init; }
public required string? ArchiveName { get; init; }
public required string? DefaultProject { get; init; }
public required List<ProjectConfig> Projects { get; init; }
public required Dictionary<string, string>? Substitutions { get; init; }
}
14 changes: 4 additions & 10 deletions Common.Build/Core/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ public class BuildContext : FrostingContext
public BuildContext(ICakeContext context) : base(context)
{
// General
var configFile = context.Argument<string>("general-config", "buildConfig.json");
var project = context.Argument<string?>("general-project", null);
var profile = context.Argument<string>("general-profile", "Release");
var version = context.Argument<string>("general-version", "12.34.56");
var skipSubstitution = context.Argument("general-skipSubstitution", false);
var solutionConfigFile = context.Argument<string>("config-solution", "buildConfig.json");
var projectConfigFile = context.Argument<string>("config-project", "buildConfig.json");

// Internal config
{
Expand All @@ -38,7 +37,7 @@ public BuildContext(ICakeContext context) : base(context)

// Solution config
{
SolutionConfig = LoadConfig<SolutionConfig>(context, Path.Combine("..", solutionConfigFile));
SolutionConfig = LoadConfig<SolutionConfig>(context, Path.Combine("..", configFile));
}

// Project picking
Expand All @@ -47,7 +46,7 @@ public BuildContext(ICakeContext context) : base(context)
{
if (SolutionConfig.DefaultProject is null)
{
throw new InvalidOperationException("No project specified as an argument and no default project specified in the solution config");
throw new InvalidOperationException("No project specified as an argument and no default project specified in the build config");
}

InternalConfig.Project = SolutionConfig.DefaultProject;
Expand All @@ -57,12 +56,7 @@ public BuildContext(ICakeContext context) : base(context)
InternalConfig.Project = project;
}

InternalConfig.ProjectFilePath = Path.Combine("..", InternalConfig.Project, $"{InternalConfig.Project}.csproj");
}

// Project config
{
ProjectConfig = LoadConfig<ProjectConfig>(context, Path.Combine("..", InternalConfig.Project, projectConfigFile));
ProjectConfig = SolutionConfig.Projects.First(projectConfig => projectConfig.Name == InternalConfig.Project);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Common.Build/Core/PathHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public static string InputPath(BuildContext context, string? path = null)
{
var inputPath = Path.Combine("..", context.InternalConfig.Project, "bin", context.InternalConfig.Profile);

if (!string.IsNullOrWhiteSpace(context.ProjectConfig.OutputSubdir))
if (!string.IsNullOrWhiteSpace(context.ProjectConfig.OutputSubdirectory))
{
inputPath = Path.Combine(inputPath, context.ProjectConfig.OutputSubdir);
inputPath = Path.Combine(inputPath, context.ProjectConfig.OutputSubdirectory);
}

inputPath = Path.Combine(inputPath, "publish");
Expand Down
11 changes: 8 additions & 3 deletions Common.Build/Tasks/ArchiveTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ public class ArchiveTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var archiveName = new StringBuilder(context.SolutionConfig.Name.ToLowerInvariant());
if (!string.IsNullOrWhiteSpace(context.ProjectConfig.Name))
if (string.IsNullOrWhiteSpace(context.SolutionConfig.ArchiveName))
{
throw new InvalidOperationException("Archival task invoked without specifying an archive name in the build config");
}

var archiveName = new StringBuilder(context.SolutionConfig.ArchiveName);
if (!string.IsNullOrWhiteSpace(context.ProjectConfig.ArchiveSuffix))
{
archiveName.Append('_');
archiveName.Append(context.ProjectConfig.Name.ToLowerInvariant());
archiveName.Append(context.ProjectConfig.ArchiveSuffix);
}

archiveName.Append('_');
Expand Down
8 changes: 6 additions & 2 deletions Common.Build/Tasks/SubstituteTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class SubstituteTask : FrostingTask<BuildContext>

public override void Run(BuildContext context)
{
foreach (var substitute in context.ProjectConfig.Substitute)
foreach (var substitutionTarget in context.ProjectConfig.SubstitutionTargets)
{
var path = Path.Combine("..", context.InternalConfig.Project, substitute);
var path = Path.Combine("..", context.InternalConfig.Project, substitutionTarget);
if (!File.Exists(path))
{
throw new ApplicationException($"File for substitution \"{path}\" does not exist");
Expand All @@ -24,6 +24,10 @@ public override void Run(BuildContext context)
var contents = File.ReadAllText(path);

contents = contents.Replace(VersionPlaceholder, context.InternalConfig.Version);
foreach (var substitution in context.SolutionConfig.Substitutions ?? [])
{
contents = contents.Replace(substitution.Key, substitution.Value);
}

File.WriteAllText(path, contents);
}
Expand Down
6 changes: 0 additions & 6 deletions Common.Build/buildConfig.json

This file was deleted.

21 changes: 18 additions & 3 deletions buildConfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
{
"$schema": "schemas/solution.schema.json",
"name": "CommonBuild",
"defaultProject": "Common.Build"
"$schema": "schemas/config.schema.json",
"archiveName": "commonbuild",
"defaultProject": "Common.Build",
"projects": [
{
"name": "Common.Build",
"substitutionTargets": [
"Common.Build.csproj"
]
},
{
"name": "Common.Build.Generator",
"archiveSuffix": "generator",
"substitutionTargets": [
"Common.Build.Generator.csproj"
]
}
]
}
79 changes: 79 additions & 0 deletions schemas/config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://raw.githubusercontent.com/devpikachu/Common.Build/refs/heads/main/schemas/config.schema.json",
"title": "Configuration",
"description": "Build configuration",
"type": "object",
"required": [
"projects"
],
"properties": {
"$schema": {
"type": "string"
},
"archiveName": {
"type": "string",
"description": "The name of the archive emitted by the archival task.",
"minLength": 1,
"pattern": "^[a-zA-Z0-9]+$"
},
"defaultProject": {
"type": [
"string",
"null"
],
"description": "The default project to use when none is specified.",
"minLength": 1,
"pattern": "^[a-zA-Z0-9\\.]+$"
},
"projects": {
"type": "array",
"description": "The list of projects that can be built.",
"items": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"description": "The project name. Must match the subdirectory and csproj file name exactly.",
"minLength": 1,
"pattern": "^[a-zA-Z0-9\\.]+$"
},
"archiveSuffix": {
"type": "string",
"description": "The suffix to append to the archive name emitted by the archival task.",
"minLength": 1,
"pattern": "^[a-zA-Z0-9]+$"
},
"outputSubdirectory": {
"type": [
"string",
"null"
],
"description": "Used by path handling, primarily by the archival task. Specify if the files to be archived are in a subdirectory of the output.",
"minLength": 1
},
"substitutionTargets": {
"type": "array",
"description": "A list of relative file paths to perform substitution on.",
"items": {
"type": "string",
"minLength": 1
}
}
},
"additionalProperties": false
}
},
"substitutions": {
"type": "object",
"description": "Key-value pairs of substitution to be performed, in addition to the built-in ones.",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
}
37 changes: 0 additions & 37 deletions schemas/project.schema.json

This file was deleted.

30 changes: 0 additions & 30 deletions schemas/solution.schema.json

This file was deleted.