Skip to content

Commit

Permalink
Merge branch 'hotfix/5.1.2' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed May 18, 2021
2 parents 0a3884e + f4e58ba commit 3f80440
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 31 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [vNext]

## [5.1.2] / 2021-05-18
- Fixed target duration to be measured immediately after execution
- Fixed build script invocation from global tool
- Fixed `AddPackage` command to allow explicit version parameter
- Fixed navigation methods to not be included in command list
- Fixed `StronglyTypedSolutionGenerator` to resolve root directory only on demand
- Fixed `EnvironmentInfo.Framework` to use entry assembly
- Fixed parsing of `GitRepository` remote
- Fixed missing pull-request properties in TeamCity
- Fixed `RunNumber` and `RunId` in `GitHubActions` to be of type `long`
- Fixed `GitVersionAttribute` to automatically populate `Git_Branch` on TeamCity

## [5.1.1] / 2021-04-23
- Fixed parameter loading with missing default parameters file
- Fixed visibility of `Directory.Build` files
Expand Down Expand Up @@ -775,7 +787,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added CLT tasks for Git
- Fixed background color in console output

[vNext]: https://github.com/nuke-build/nuke.git/compare/5.1.1...HEAD
[vNext]: https://github.com/nuke-build/nuke.git/compare/5.1.2...HEAD
[5.1.2]: https://github.com/nuke-build/nuke.git/compare/5.1.1...5.1.2
[5.1.1]: https://github.com/nuke-build/nuke.git/compare/5.1.0...5.1.1
[5.1.0]: https://github.com/nuke-build/nuke.git/compare/5.0.2...5.1.0
[5.0.2]: https://github.com/nuke-build/nuke.git/compare/5.0.1...5.0.2
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mode: ContinuousDelivery
mode: ContinuousDeployment

assembly-versioning-scheme: MajorMinor
assembly-file-versioning-scheme: MajorMinorPatch
Expand Down
4 changes: 2 additions & 2 deletions source/Nuke.Common/CI/GitHubActions/GitHubActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ internal GitHubActions()
///<summary>Only set for forked repositories. The branch of the base repository.</summary>
public string GitHubBaseRef => EnvironmentInfo.GetVariable<string>("GITHUB_BASE_REF");

public string GitHubRunNumber => EnvironmentInfo.GetVariable<string>("GITHUB_RUN_NUMBER");
public string GitHubRunId => EnvironmentInfo.GetVariable<string>("GITHUB_RUN_ID");
public long GitHubRunNumber => EnvironmentInfo.GetVariable<long>("GITHUB_RUN_NUMBER");
public long GitHubRunId => EnvironmentInfo.GetVariable<long>("GITHUB_RUN_ID");
public string GitHubServerUrl => EnvironmentInfo.GetVariable<string>("GITHUB_SERVER_URL");
public string GitHubJob => EnvironmentInfo.GetVariable<string>("GITHUB_JOB");

Expand Down
5 changes: 5 additions & 0 deletions source/Nuke.Common/CI/TeamCity/TeamCity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public T CreateRestClient<T>()
public string ProjectId => ConfigurationProperties?["teamcity.project.id"];
public long BuildId => long.Parse(ConfigurationProperties?["teamcity.build.id"] ?? 0.ToString());
public bool IsBuildPersonal => bool.Parse(SystemProperties?.GetValueOrDefault("build.is.personal") ?? bool.FalseString);
public bool IsPullRequest => ConfigurationProperties?.GetValueOrDefault("teamcity.pullRequest.number") != null;
[CanBeNull] public long? PullRequestNumber => IsPullRequest ? long.Parse(ConfigurationProperties["teamcity.pullRequest.number"]) : null;
[CanBeNull] public string PullRequestSourceBranch => IsPullRequest ? ConfigurationProperties["teamcity.pullRequest.source.branch"] : null;
[CanBeNull] public string PullRequestTargetBranch => IsPullRequest ? ConfigurationProperties["teamcity.pullRequest.target.branch"] : null;
[CanBeNull] public string PullRequestTitle => IsPullRequest ? ConfigurationProperties["teamcity.pullRequest.title"] : null;

[NoConvert] public string BranchName => ConfigurationProperties?.GetValueOrDefault("teamcity.build.branch")
.NotNull("Configuration property 'teamcity.build.branch' is null. See https://youtrack.jetbrains.com/issue/TW-62888.");
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common/EnvironmentInfo.Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static bool GetIsWsl()
/// Returns the framework the build is running on.
/// </summary>
public static FrameworkName Framework
=> new FrameworkName(typeof(NukeBuild).Assembly.GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName);
=> new FrameworkName(Assembly.GetEntryAssembly().NotNull().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName);

/// <summary>
/// Returns the platform the build is running on.
Expand Down
12 changes: 6 additions & 6 deletions source/Nuke.Common/Execution/BuildExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ private static void Execute(

using (Logger.Block(target.Name))
{
target.Stopwatch.Start();
target.Status = ExecutionStatus.Running;
build.ExecuteExtension<IOnTargetRunning>(x => x.OnTargetRunning(build, target));
var stopwatch = Stopwatch.StartNew();
try
{
target.Actions.ForEach(x => x());
target.Stopwatch.Stop();
target.Status = ExecutionStatus.Succeeded;
build.ExecuteExtension<IOnTargetSucceeded>(x => x.OnTargetSucceeded(build, target));

AppendToBuildAttemptFile(target.Name);
}
catch (Exception exception)
Expand All @@ -120,16 +122,14 @@ private static void Execute(
: _.AddPair(exception.GetType().Name, exception.Message.SplitLineBreaks().First()));

Logger.Error(exception);
target.Status = ExecutionStatus.Failed;

target.Stopwatch.Stop();
target.Status = ExecutionStatus.Failed;
build.ExecuteExtension<IOnTargetFailed>(x => x.OnTargetFailed(build, target));

if (!target.ProceedAfterFailure && !failureMode)
throw new TargetExecutionException(target.Name, exception);
}
finally
{
target.Duration = stopwatch.Elapsed;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/Execution/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void Finish()
{
foreach (var target in build.ExecutionPlan)
{
target.Stopwatch.Stop();
target.Status = target.Status switch
{
ExecutionStatus.Running => ExecutionStatus.Aborted,
Expand Down
5 changes: 4 additions & 1 deletion source/Nuke.Common/Execution/ExecutableTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
using System.Linq.Expressions;
using System.Reflection;
using Nuke.Common.Utilities.Collections;
// ReSharper disable MissingBaseTypeHighlighting

namespace Nuke.Common.Execution
{
[DebuggerDisplay("{" + nameof(Name) + "}")]
public class ExecutableTarget
{
internal TargetDefinition Definition { get; set; }
internal Stopwatch Stopwatch { get; } = new Stopwatch();

public MemberInfo Member { get; set; }
public string Name { get; set; }
public string Description { get; set; }
Expand All @@ -36,9 +39,9 @@ public class ExecutableTarget
public IReadOnlyCollection<ExecutableTarget> AllDependencies
=> ExecutionDependencies.Concat(OrderDependencies).Concat(TriggerDependencies).ToList();

public TimeSpan Duration => Stopwatch.Elapsed;
public bool IsDefault { get; set; }
public ExecutionStatus Status { get; set; }
public TimeSpan Duration { get; set; }
public bool Invoked { get; set; }
public Dictionary<string, string> SummaryInformation { get; internal set; } = new Dictionary<string, string>();

Expand Down
4 changes: 2 additions & 2 deletions source/Nuke.Common/Git/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private static (string Name, string Branch) GetRemoteNameAndBranch(string gitDir
.TakeWhile(x => !x.StartsWith("["))
.Select(x => x.Split('='))
.ToDictionary(x => x.ElementAt(0).Trim(), x => x.ElementAt(1).Trim());
return data.Count == 2
? (data["remote"], data["merge"].TrimStart("refs/heads/"))
return data.TryGetValue("remote", out var remote) && data.TryGetValue("merge", out var merge)
? (remote, merge.TrimStart("refs/heads/"))
: (null, null);
}

Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common/Tooling/ToolPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ from packageVersion in
{
"Missing package reference/download.",
"Run one of the following commands:"
}.Concat(packageCombinations.Distinct().Select(x => $" - nuke :add-package {x.Id} {x.Version}"))
}.Concat(packageCombinations.Distinct().Select(x => $" - nuke :add-package {x.Id} --version {x.Version}"))
.JoinNewLine(),
exception);
throw new Exception("Not reachable");
Expand Down
6 changes: 5 additions & 1 deletion source/Nuke.Common/Tools/GitVersion/GitVersionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public override object GetValue(MemberInfo member, object instance)
.SetNoFetch(NoFetch)
.SetNoCache(NoCache)
.DisableProcessLogOutput()
.SetUpdateAssemblyInfo(UpdateAssemblyInfo))
.SetUpdateAssemblyInfo(UpdateAssemblyInfo)
.When(TeamCity.Instance is { IsPullRequest: true } && !EnvironmentInfo.Variables.ContainsKey("Git_Branch"), _ => _
.AddProcessEnvironmentVariable(
"Git_Branch",
TeamCity.Instance.ConfigurationProperties.Single(x => x.Key.StartsWith("teamcity.build.vcs.branch")).Value)))
.Result;

if (UpdateBuildNumber)
Expand Down
3 changes: 2 additions & 1 deletion source/Nuke.GlobalTool/Program.AddPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static int AddPackage(string[] args, [CanBeNull] AbsolutePath rootDirecto
{
var packageId = args.ElementAt(0);
var packageVersion =
(args.ElementAtOrDefault(1) ??
(EnvironmentInfo.GetParameter<string>("version") ??
args.ElementAtOrDefault(1) ??
NuGetPackageResolver.GetLatestPackageVersion(packageId, includePrereleases: false).GetAwaiter().GetResult() ??
NuGetPackageResolver.GetGlobalInstalledPackage(packageId, version: null, packagesConfigFile: null)?.Version.ToString())
.NotNull("packageVersion != null");
Expand Down
10 changes: 5 additions & 5 deletions source/Nuke.GlobalTool/Program.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static string SessionId
private static string SessionFile => GlobalTemporaryDirectory / $"nuke-{SessionId}.dat";

[UsedImplicitly]
public static int GetNextDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
private static int GetNextDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
{
var content = File.Exists(SessionFile) ? File.ReadAllLines(SessionFile) : null;
if (content == null || string.IsNullOrWhiteSpace(content[0]))
Expand All @@ -49,7 +49,7 @@ public static int GetNextDirectory(string[] args, [CanBeNull] AbsolutePath rootD
}

[UsedImplicitly]
public static int PopDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
private static int PopDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
{
var content = File.Exists(SessionFile) ? File.ReadAllLines(SessionFile).ToList() : null;
if (content == null || content.Count <= 1)
Expand All @@ -65,13 +65,13 @@ public static int PopDirectory(string[] args, [CanBeNull] AbsolutePath rootDirec
}

[UsedImplicitly]
public static int PushWithCurrentRootDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
private static int PushWithCurrentRootDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
{
return PushAndSetNext(() => rootDirectory.NotNull("No root directory found."));
}

[UsedImplicitly]
public static int PushWithParentRootDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
private static int PushWithParentRootDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
{
return PushAndSetNext(() =>
{
Expand All @@ -81,7 +81,7 @@ public static int PushWithParentRootDirectory(string[] args, [CanBeNull] Absolut
}

[UsedImplicitly]
public static int PushWithChosenRootDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
private static int PushWithChosenRootDirectory(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
{
return PushAndSetNext(() =>
{
Expand Down
11 changes: 5 additions & 6 deletions source/Nuke.GlobalTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static int Main(string[] args)
var buildScript = rootDirectory != null
? (AbsolutePath) new DirectoryInfo(rootDirectory)
.EnumerateFiles(CurrentBuildScriptName, maxDepth: 2)
.FirstOrDefault()?.FullName.DoubleQuoteIfNeeded()
.FirstOrDefault()?.FullName
: null;

return Handle(args, rootDirectory, buildScript);
Expand Down Expand Up @@ -70,16 +70,15 @@ private static int Handle(string[] args, [CanBeNull] AbsolutePath rootDirectory,
if (string.IsNullOrWhiteSpace(command))
ControlFlow.Fail($"No command specified. Usage is: nuke {CommandPrefix}<command> [args]");

var availableCommands = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.Public);
var commandHandler = availableCommands
.SingleOrDefault(x => x.Name.EqualsOrdinalIgnoreCase(command));
var availableCommands = typeof(Program).GetMethods(ReflectionUtility.Static);
var commandHandler = availableCommands.SingleOrDefault(x => x.Name.EqualsOrdinalIgnoreCase(command));
ControlFlow.Assert(commandHandler != null,
new[]
{
$"Command '{command}' is not supported.",
"Available commands are:"
}
.Concat(availableCommands.Select(x => $" - {x.Name}").OrderBy(x => x)).JoinNewLine());
.Concat(availableCommands.Where(x => x.IsPublic).Select(x => $" - {x.Name}").OrderBy(x => x)).JoinNewLine());
// TODO: add assertions about return type and parameters

var commandArguments = new object[] { args.Skip(count: 1).ToArray(), rootDirectory, buildScript };
Expand Down Expand Up @@ -114,7 +113,7 @@ private static Process Build(string buildScript, string arguments)
? ToolPathResolver.GetPathExecutable("powershell")
: ToolPathResolver.GetPathExecutable("bash"),
Arguments = EnvironmentInfo.IsWin
? $"-ExecutionPolicy ByPass -NoProfile -File {buildScript} {arguments}"
? $"-ExecutionPolicy ByPass -NoProfile -File {buildScript.DoubleQuoteIfNeeded()} {arguments}"
: $"{buildScript} {arguments}"
}).NotNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public void Execute(GeneratorExecutionContext context)
var membersWithAttributes = allTypes.SelectMany(x => x.GetMembers())
.Where(x => x is IPropertySymbol || x is IFieldSymbol)
.Select(x => (Member: x, AttributeData: x.GetAttributeData("global::Nuke.Common.ProjectModel.SolutionAttribute")))
.Where(x => x.AttributeData != null);
.Where(x => x.AttributeData != null).ToList();
if (membersWithAttributes.Count == 0)
return;

var rootDirectory = TryGetRootDirectoryFrom(compilation);
var rootDirectory = GetRootDirectoryFrom(compilation);
var compilationUnit = CompilationUnit()
.AddUsings(UsingDirective(IdentifierName("Nuke.Common.ProjectModel")));

Expand Down Expand Up @@ -114,7 +116,7 @@ private static string GetSolutionFileFromParametersFile(AbsolutePath rootDirecto
return Path.Combine(rootDirectory, solutionRelativePath);
}

private static AbsolutePath TryGetRootDirectoryFrom(Compilation compilation)
private static AbsolutePath GetRootDirectoryFrom(Compilation compilation)
{
var syntaxPath = compilation.SyntaxTrees.First().FilePath;
var startDirectory = Path.GetDirectoryName(File.Exists(syntaxPath)
Expand Down

0 comments on commit 3f80440

Please sign in to comment.