Skip to content

Commit

Permalink
Update build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeago committed Nov 16, 2023
1 parent 45277b0 commit 6bc446c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
1 change: 1 addition & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#load "./build/process.cake"
#load "./build/public-api.cake"
#load "./build/setup-teardown.cake"
#load "./build/utilities.cake"
#load "./build/versioning.cake"
#load "./build/workspace.cake"

Expand Down
5 changes: 2 additions & 3 deletions build/git.cake
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ static (SemanticVersion? Latest, SemanticVersion? LatestStable) GitGetLatestVers
.Where(static x => x.StartsWith("tag: "))
.Select(static x => x.Substring(5))
.Select(static x => {
SemanticVersion? version = null;
var result = SemanticVersion.TryParse(x, out version);
_ = SemanticVersion.TryParse(x, out var version);
return version;
})
.Where(static x => x != null);
.WhereNotNull();

SemanticVersion? latest = null;
SemanticVersion? latestStable = null;
Expand Down
2 changes: 1 addition & 1 deletion build/nbgv.cake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static (string VersionStr, string Ref, bool IsPublicRelease, bool IsPrerelease)

var json = context.ParseJsonObject(nbgvOutput.ToString(), "The output of nbgv");
return (
VersionStr: context.GetJsonPropertyValue<string>(json, "NuGetPackageVersion", "the output of nbgv"),
VersionStr: context.GetJsonPropertyValue<string>(json, "SemVer2", "the output of nbgv"),
Ref: context.GetJsonPropertyValue<string>(json, "BuildingRef", "the output of nbgv"),
IsPublicRelease: context.GetJsonPropertyValue<bool>(json, "PublicRelease", "the output of nbgv"),
IsPrerelease: !string.IsNullOrEmpty(context.GetJsonPropertyValue<string>(json, "PrereleaseVersion", "the output of nbgv")));
Expand Down
41 changes: 41 additions & 0 deletions build/utilities.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) Tenacom and contributors. Licensed under the MIT license.
// See LICENSE file in the project root for full license information.

#nullable enable

// ---------------------------------------------------------------------------------------------
// Miscellaneous utilities
// ---------------------------------------------------------------------------------------------

using System;
using System.Linq;

/*
* Summary : Filters a sequence of nullable values, taking only those that are not null.
* Type params : T - The type of the elements of this.
* Params : this - An IEnumerable<T> to filter.</param>
* Returns : An IEnumerable<T> that contains elements from the input sequence that are not null.
*/
static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> @this)
where T : class
{
return @this.Where(IsNotNull) as IEnumerable<T>;

static bool IsNotNull(T? x) => x is not null;
}

/*
* Summary : Filters a sequence of nullable values, taking only those that are not null.
* Type params : T - The type of the elements of this.
* Params : this - An IEnumerable<T> to filter.</param>
* Returns : An IEnumerable<T> that contains elements from the input sequence that are not null.
*/
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> @this)
where T : struct
{
return @this.Where(IsNotNull).Select(GetValue);

static bool IsNotNull(T? x) => x.HasValue;

static T GetValue(T? x) => x!.Value;
}
10 changes: 6 additions & 4 deletions build/versioning.cake
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ static VersionSpecChange ComputeVersionSpecChange(
bool checkPublicApi)
{
// Determine how we are currently already incrementing version
var currentVersionIncrement = latestStableVersion == null ? VersionIncrement.Major
var currentVersionIncrement = latestStableVersion == null ? VersionIncrement.None
: currentVersion.Major > latestStableVersion.Major ? VersionIncrement.Major
: currentVersion.Minor > latestStableVersion.Minor ? VersionIncrement.Minor
: VersionIncrement.None;
Expand All @@ -348,10 +348,12 @@ static VersionSpecChange ComputeVersionSpecChange(
context.Information($"Public API change kind: {publicApiChangeKind}{(checkPublicApi ? null : " (not checked)")}");

// Determine the version increment required by SemVer rules
var isInitialDevelopmentPhase = latestStableVersion == null || latestStableVersion.Major == 0;
// When the major version is 0, "anything MAY change" according to SemVer;
// by convention, we increment the minor version for breaking changes (0.x -> 0.(x+1))
var isMajorVersionZero = latestStableVersion is { Major: 0 };
var semanticVersionIncrement = publicApiChangeKind switch {
ApiChangeKind.Breaking => isInitialDevelopmentPhase ? VersionIncrement.Minor : VersionIncrement.Major,
ApiChangeKind.Additive => isInitialDevelopmentPhase ? VersionIncrement.None : VersionIncrement.Minor,
ApiChangeKind.Breaking => isMajorVersionZero ? VersionIncrement.Minor : VersionIncrement.Major,
ApiChangeKind.Additive => isMajorVersionZero ? VersionIncrement.None : VersionIncrement.Minor,
_ => VersionIncrement.None,
};
context.Information($"Required version increment according to Semantic Versioning rules: {semanticVersionIncrement}");
Expand Down

0 comments on commit 6bc446c

Please sign in to comment.