Skip to content

Commit

Permalink
Merge pull request #193 from JeremiahSanders/release/1.11.0
Browse files Browse the repository at this point in the history
Release/1.11.0
  • Loading branch information
JeremiahSanders authored Nov 22, 2023
2 parents 9877384 + 0954946 commit b3627e9
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 63 deletions.
57 changes: 5 additions & 52 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ indent_size = 2
[*.sh]
indent_size = 2

# CSharp code style settings:
[*.cs]

dotnet_diagnostic.cs1591.severity = none # Missing XML comment for publicly visible type or member.

# IDE0055: Fix formatting
dotnet_diagnostic.ide0055.severity = warning

Expand Down Expand Up @@ -159,8 +164,6 @@ dotnet_diagnostic.rs2008.severity = none
dotnet_diagnostic.ide0073.severity = warning
file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.\nSee the LICENSE file in the project root for more information.

# CSharp code style settings:
[*.cs]
# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
Expand Down Expand Up @@ -235,53 +238,3 @@ dotnet_diagnostic.rs0037.severity = none
[src/CodeStyle/**.{cs,vb}]
# warning RS0005: Do not use generic CodeAction.Create to create CodeAction
dotnet_diagnostic.rs0005.severity = none

[src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures, VisualStudio}/**/*.{cs,vb}]

# IDE0011: Add braces
csharp_prefer_braces = when_multiline:warning
# NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201
dotnet_diagnostic.ide0011.severity = warning

# IDE0035: Remove unreachable code
dotnet_diagnostic.ide0035.severity = warning

# IDE0036: Order modifiers
dotnet_diagnostic.ide0036.severity = warning

# IDE0040: Add accessibility modifiers
dotnet_diagnostic.ide0040.severity = warning

# IDE0043: Format string contains invalid placeholder
dotnet_diagnostic.ide0043.severity = warning

# IDE0044: Make field readonly
dotnet_diagnostic.ide0044.severity = warning

# CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings?
# IDE0051: Remove unused private member
dotnet_diagnostic.ide0051.severity = warning

# IDE0052: Remove unread private member
dotnet_diagnostic.ide0052.severity = warning

# IDE0059: Unnecessary assignment to a value
dotnet_diagnostic.ide0059.severity = warning

# IDE0060: Remove unused parameter
dotnet_diagnostic.ide0060.severity = warning

# CA1822: Make member static
dotnet_diagnostic.ca1822.severity = warning

# Prefer "var" everywhere
dotnet_diagnostic.ide0007.severity = warning
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning
csharp_style_var_elsewhere = true:warning

[src/{VisualStudio}/**/*.{cs,vb}]
# CA1822: Make member static
# Not enforced as a build 'warning' for 'VisualStudio' layer due to large number of false positives from https://github.com/dotnet/roslyn-analyzers/issues/3857 and https://github.com/dotnet/roslyn-analyzers/issues/3858
# Additionally, there is a risk of accidentally breaking an internal API that partners rely on though IVT.
dotnet_diagnostic.ca1822.severity = suggestion
2 changes: 1 addition & 1 deletion .project-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cicee",
"description": "Runs continuous integration workloads via docker-compose, locally or on a build server.",
"title": "Continuous Integration Containerized Execution Environment (CICEE)",
"version": "1.10.0",
"version": "1.11.0",
"ciEnvironment": {
"variables": [
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CICEE also provides a [continuous integration shell function library][cicee-lib]
* `bash`: bash shell
* `docker`: Docker command-line interface
* `docker-compose`: Docker Compose command-line interface (compose file version `3.7` support required)
* `dotnet`: .NET runtime (`6.x` and `7.x` supported)
* `dotnet`: .NET SDK (`6.x`, `7.x`, and `8.x` supported)

## Why use CICEE?

Expand Down
12 changes: 10 additions & 2 deletions ci/libexec/ci-workflows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ ci-compose() {
--configuration Release \
--output "${BUILD_UNPACKAGED_DIST}/net7.0" \
-p:Version="${PROJECT_VERSION_DIST}" \
--framework net7.0 \
--framework net7.0 &&
printf "\nBeginning 'dotnet publish' targeting .NET 8...\n\n" &&
dotnet publish "${PROJECT_ROOT}/src" \
--configuration Release \
--output "${BUILD_UNPACKAGED_DIST}/net8.0" \
-p:Version="${PROJECT_VERSION_DIST}" \
--framework net8.0 \
-p:GenerateDocumentationFile=true &&
printf "\nCompleted 'dotnet publish' targeting .NET 8.\n\n" &&
printf "\nBeginning 'dotnet pack'...\n\n" &&
ci-dotnet-pack -p:GenerateDocumentationFile=true
ci-dotnet-pack -p:GenerateDocumentationFile=true &&
printf "\nCompleted 'dotnet pack'.\n\n"
}

#--
Expand Down
26 changes: 26 additions & 0 deletions docs/use/meta-version-set.md
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
2 changes: 2 additions & 0 deletions docs/use/using-cicee.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Commands:
* [`update`][meta-cienv-variables] - Update a CI environment variable.
* [`version`][meta-version] - Gets `.version` in project metadata.
* [`bump`][meta-version-bump] - Bumps the `.version` in project metadata by a SemVer increment.
* [`set`][meta-version-set] - Sets the `.version` in project metadata to a SemVer version.
* `template` - Commands working with project continuous integration templates.
* [`init`][template-init] - Initialize a project repository with continuous integration workflow scripts.
* [`lib`][template-lib] - Initialize project CI with CICEE execution library. Supports `cicee exec`-like behavior without CICEE installation.
Expand All @@ -54,6 +55,7 @@ Commands:
[lib]: ./ci-library.md
[meta-cienv-variables]: ./meta-cienv-variables.md
[meta-version-bump]: ./meta-version-bump.md
[meta-version-set]: ./meta-version-set.md
[meta-version]: ./meta-version.md
[template-init]: ./template-init.md
[template-lib]: ./template-lib.md
2 changes: 1 addition & 1 deletion src/Cicee.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Meta/Version/Bump/MetaVersionBumpEntrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public static class MetaVersionBumpEntrypoint
{
public static Func<string, bool, SemVerIncrement, Task<int>> CreateHandler(CommandDependencies dependencies)
{
return Handle;

async Task<int> Handle(string projectMetadataPath, bool isDryRun, SemVerIncrement semVerIncrement)
{
return (await MetaVersionBumpHandling.Handle(dependencies, projectMetadataPath, isDryRun, semVerIncrement))
Expand All @@ -18,7 +20,5 @@ async Task<int> Handle(string projectMetadataPath, bool isDryRun, SemVerIncremen
})
.ToExitCode();
}

return Handle;
}
}
}
2 changes: 2 additions & 0 deletions src/Commands/Meta/Version/MetaVersionCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.CommandLine;
using Cicee.Commands.Meta.Version.Bump;
using Cicee.Commands.Meta.Version.Set;
using Cicee.Dependencies;

namespace Cicee.Commands.Meta.Version;
Expand All @@ -16,6 +17,7 @@ public static Command Create(CommandDependencies dependencies)
command.SetHandler(MetaVersionEntrypoint.CreateHandler(dependencies), projectMetadata);

command.AddCommand(MetaVersionBumpCommand.Create(dependencies));
command.AddCommand(MetaVersionSetCommand.Create(dependencies));

return command;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Meta/Version/MetaVersionEntrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public static class MetaVersionEntrypoint
{
public static Func<string, Task<int>> CreateHandler(CommandDependencies dependencies)
{
return Handle;

Task<int> Handle(string projectMetadataPath)
{
return MetaVersionHandling.HandleMetaVersionRequest(dependencies, projectMetadataPath)
Expand All @@ -20,7 +22,5 @@ Task<int> Handle(string projectMetadataPath)
.ToExitCode()
.AsTask();
}

return Handle;
}
}
72 changes: 72 additions & 0 deletions src/Commands/Meta/Version/Set/MetaVersionSetCommand.cs
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;
}
}
25 changes: 25 additions & 0 deletions src/Commands/Meta/Version/Set/MetaVersionSetEntrypoint.cs
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();
}
}
}
75 changes: 75 additions & 0 deletions src/Commands/Meta/Version/Set/MetaVersionSetHandling.cs
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Cicee.CiEnv;
using Cicee.Commands;
using Cicee.Commands.Meta.Version.Bump;
using Cicee.Dependencies;
using Jds.LanguageExt.Extras;
Expand Down
Loading

0 comments on commit b3627e9

Please sign in to comment.