-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from JeremiahSanders/release/1.11.0
Release/1.11.0
- Loading branch information
Showing
15 changed files
with
294 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Set Version in Project Metadata | ||
|
||
Sets the `.version` property in a [project metadata][project-structure] file to a SemVer version (e.g., `2.3.1`). | ||
|
||
> Project metadata JSON files are _modified_, unless `dry-run` option is enabled. This may reformat the document. | ||
For example: | ||
|
||
> **Note:** When CICEE is installed as a .NET local tool (i.e., your `${PROJECT_ROOT}/.config/dotnet-tools.json` contains a reference to `cicee`), all `$ cicee ..arguments..` commands become `$ dotnet cicee ..arguments..`. Additionally, you may need to run `dotnet tool restore`, to ensure the tool is installed. | ||
```bash | ||
$ cicee meta version set --help | ||
Description: | ||
Sets version in project metadata. | ||
|
||
Usage: | ||
cicee meta version set [options] | ||
|
||
Options: | ||
-m, --metadata <metadata> (REQUIRED) Project metadata file path. [default: $(pwd)/.project-metadata.json] | ||
-d, --dry-run Execute a 'dry run', i.e., skip writing files and similar destructive steps. [default: False] | ||
-v, --version <version> (REQUIRED) New version in SemVer 2.0 release format. E.g., '2.3.1'. [] | ||
-?, -h, --help Show help and usage information | ||
``` | ||
|
||
[project-structure]: ./project-structure.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.CommandLine; | ||
using System.CommandLine.Parsing; | ||
using System.Linq; | ||
using Cicee.Dependencies; | ||
|
||
namespace Cicee.Commands.Meta.Version.Set; | ||
|
||
public static class MetaVersionSetCommand | ||
{ | ||
public const string CommandName = "set"; | ||
public const string CommandDescription = "Sets version in project metadata."; | ||
|
||
private static Option<System.Version> IncrementOption() | ||
{ | ||
return new Option<System.Version>(new[] {"--version", "-v"}, | ||
"New version in SemVer 2.0 release format. E.g., '2.3.1'.") {IsRequired = true}; | ||
} | ||
|
||
private static Option<System.Version?> CreateVersionOption() | ||
{ | ||
return new Option<System.Version?>( | ||
new[] {"--version", "-v"}, | ||
ParseArgument, | ||
isDefault: true, | ||
"New version in SemVer 2.0 release format. E.g., '2.3.1'." | ||
) {IsRequired = true}; | ||
|
||
System.Version? ParseArgument(ArgumentResult result) | ||
{ | ||
var initialTokenValue = result.Tokens.Count > 0 ? result.Tokens[index: 0].Value : string.Empty; | ||
var tokenValue = initialTokenValue; | ||
var countOfPeriods = tokenValue.Count(c => c == '.'); | ||
|
||
if (tokenValue != string.Empty) | ||
{ | ||
switch (countOfPeriods) | ||
{ | ||
case 0: | ||
if (int.TryParse(tokenValue, out _)) | ||
{ | ||
tokenValue += ".0.0"; // Single integer value | ||
} | ||
|
||
break; | ||
case 1: | ||
tokenValue += ".0"; // Two-field version value | ||
break; | ||
} | ||
} | ||
|
||
if (System.Version.TryParse(tokenValue, out var version)) | ||
{ | ||
return version; | ||
} | ||
|
||
result.ErrorMessage = | ||
$"Invalid version format '{initialTokenValue}'. Use complete Major.Minor.Patch, e.g., '2.3.1' or '4.0.0'."; | ||
return null; | ||
} | ||
} | ||
|
||
public static Command Create(CommandDependencies dependencies) | ||
{ | ||
var projectMetadata = ProjectMetadataOption.Create(dependencies); | ||
var dryRun = DryRunOption.Create(); | ||
var versionOption = CreateVersionOption(); | ||
var command = new Command(CommandName, CommandDescription) {projectMetadata, dryRun, versionOption}; | ||
command.SetHandler(MetaVersionSetEntrypoint.CreateHandler(dependencies), projectMetadata, dryRun, versionOption); | ||
|
||
return command; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Cicee.Dependencies; | ||
|
||
namespace Cicee.Commands.Meta.Version.Set; | ||
|
||
public static class MetaVersionSetEntrypoint | ||
{ | ||
public static Func<string, bool, System.Version?, Task<int>> CreateHandler(CommandDependencies dependencies) | ||
{ | ||
return Handle; | ||
|
||
async Task<int> Handle(string projectMetadataPath, bool isDryRun, System.Version? version) | ||
{ | ||
// NOTE: Use of version! should be safe due to parameter being required. | ||
return (await MetaVersionSetHandling.Handle(dependencies, projectMetadataPath, isDryRun, version!)) | ||
.TapSuccess(dependencies.StandardOutWriteLine) | ||
.TapFailure(exception => | ||
{ | ||
dependencies.StandardErrorWriteLine(exception.ToExecutionFailureMessage()); | ||
}) | ||
.ToExitCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Text.Json.Nodes; | ||
using System.Threading.Tasks; | ||
using Cicee.CiEnv; | ||
using Cicee.Dependencies; | ||
using LanguageExt.Common; | ||
|
||
namespace Cicee.Commands.Meta.Version.Set; | ||
|
||
public static class MetaVersionSetHandling | ||
{ | ||
internal static string GetVersionString(this System.Version version) | ||
{ | ||
return version.ToString(fieldCount: 3); | ||
} | ||
|
||
public static Result<(System.Version Version, ProjectMetadata ProjectMetadata, JsonObject MetadataJson)> | ||
TrySetProjectVersion( | ||
Func<string, Result<string>> tryLoadFileString, | ||
Func<string, Result<string>> ensureFileExists, | ||
string projectMetadataPath, | ||
System.Version version | ||
) | ||
{ | ||
Result<JsonObject> TryIncrementVersionInProjectMetadata(System.Version incrementedVersion) | ||
{ | ||
return tryLoadFileString(projectMetadataPath) | ||
.MapSafe(content => | ||
{ | ||
var jsonObject = JsonNode.Parse(content)!.AsObject(); | ||
jsonObject["version"] = incrementedVersion.GetVersionString(); | ||
return jsonObject; | ||
}); | ||
} | ||
|
||
return ProjectMetadataLoader.TryLoadFromFile( | ||
ensureFileExists, | ||
tryLoadFileString, | ||
projectMetadataPath | ||
) | ||
.Bind(metadata => | ||
TryIncrementVersionInProjectMetadata(version) | ||
.Map(jsonObject => | ||
(version, metadata with {Version = version.GetVersionString()}, jsonObject) | ||
) | ||
); | ||
} | ||
|
||
public static Task<Result<string>> Handle( | ||
CommandDependencies dependencies, | ||
string projectMetadataPath, | ||
bool isDryRun, | ||
System.Version version | ||
) | ||
{ | ||
async Task<Result<string>> ConditionallyModifyProjectMetadata( | ||
(System.Version SetedVersion, ProjectMetadata ProjectMetadata, JsonObject MetadataJson) tuple | ||
) | ||
{ | ||
var versionString = tuple.SetedVersion.GetVersionString(); | ||
return isDryRun | ||
? new Result<string>(versionString) | ||
: (await ProjectMetadataManipulation.UpdateVersionInMetadata(dependencies, projectMetadataPath, | ||
tuple.SetedVersion)).Map(_ => versionString); | ||
} | ||
|
||
return TrySetProjectVersion( | ||
dependencies.TryLoadFileString, | ||
dependencies.EnsureFileExists, | ||
projectMetadataPath, | ||
version | ||
) | ||
.BindAsync(ConditionallyModifyProjectMetadata); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
...nit/Commands/Meta/Version/Bump/MetaVersionBumpHandlingTests/TryBumpProjectVersionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.