Skip to content

Commit

Permalink
WIP: AppVeyor artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Jul 1, 2020
1 parent 3cbd1bc commit e22dab8
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 17 deletions.
7 changes: 7 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ artifacts:
- path: output/test-results/*.xml
- path: output/coverage-report.zip
- path: output/packages/*.nupkg

environment:
SignPathApiToken:
secure: A7xODEf8xLS3iaUyZScRx2NNCDWaODbWHk30FmncIH3NtXU77bR74FAsTQGwRCIe
SignPathOrganizationId: 09e500c8-00f7-4f3b-95f6-e33f77e67410
SignPathProjectKey: nuke
SignPathPolicyKey: test-signing
22 changes: 22 additions & 0 deletions build/Build.SignPackages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2020 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Utilities;
using Nuke.Components;

partial class Build : ISignPackages
{
public IEnumerable<AbsolutePath> SignPathPackages => PackageFiles
.Where(x => Path.GetFileName(x).StartsWithAny("Nuke.Common", "Nuke.Components", "Nuke.CodeGeneration"));

public Target SignPackages => _ => _
.Inherit<ISignPackages>(x => x.SignPackages)
.TriggeredBy(Pack);
}
23 changes: 12 additions & 11 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AppVeyor;
Expand Down Expand Up @@ -84,17 +91,9 @@ partial class Build : NukeBuild
/// - Microsoft VSCode https://nuke.build/vscode
public static int Main() => Execute<Build>(x => x.Pack);

Target Foo => _ => _
.Executes(() =>
{
Console.WriteLine(Configuration);
Console.WriteLine(MyPath);
});

[Parameter] readonly AbsolutePath MyPath;

[CI] readonly TeamCity TeamCity;
[CI] readonly AzurePipelines AzurePipelines;
[CI] readonly AppVeyor AppVeyor;

[GitRepository] readonly GitRepository GitRepository;
[GitVersion(NoFetch = true)] readonly GitVersion GitVersion;
Expand Down Expand Up @@ -162,7 +161,7 @@ from framework in project.GetTargetFrameworks()
});

string ChangelogFile => RootDirectory / "CHANGELOG.md";
AbsolutePath PackageDirectory => OutputDirectory / "packages";
public AbsolutePath PackageDirectory => OutputDirectory / "packages";
IEnumerable<string> ChangelogSectionNotes => ExtractChangelogSectionNotes(ChangelogFile);

Target Pack => _ => _
Expand Down Expand Up @@ -272,7 +271,7 @@ from framework in project.GetTargetFrameworks()
GitRepository.Branch.StartsWithOrdinalIgnoreCase(HotfixBranchPrefix))
.Executes(() =>
{
var packages = PackageDirectory.GlobFiles("*.nupkg");
var packages = PackageFiles;
Assert(packages.Count == 5, "packages.Count == 5");

DotNetNuGetPush(_ => _
Expand All @@ -284,6 +283,8 @@ from framework in project.GetTargetFrameworks()
completeOnFailure: true);
});

IReadOnlyCollection<AbsolutePath> PackageFiles => PackageDirectory.GlobFiles("*.nupkg");

Target Install => _ => _
.DependsOn(Pack)
.Executes(() =>
Expand Down
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\source\Nuke.Common\Nuke.Common.csproj" />
<ProjectReference Include="..\source\Nuke.Components\Nuke.Components.csproj" />
<ProjectReference Include="..\source\Nuke.CodeGeneration\Nuke.CodeGeneration.csproj" />
</ItemGroup>

Expand Down
9 changes: 9 additions & 0 deletions source/Nuke.Common/CI/AppVeyor/AppVeyor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Nuke.Common.Tooling;
Expand Down Expand Up @@ -49,6 +50,7 @@ internal AppVeyor()

private readonly Tool _cli;

public string Url => EnvironmentInfo.GetVariable<string>("APPVEYOR_URL");
public string ApiUrl => EnvironmentInfo.GetVariable<string>("APPVEYOR_API_URL");
public string AccountName => EnvironmentInfo.GetVariable<string>("APPVEYOR_ACCOUNT_NAME");
public int ProjectId => EnvironmentInfo.GetVariable<int>("APPVEYOR_PROJECT_ID");
Expand Down Expand Up @@ -85,6 +87,13 @@ internal AppVeyor()
public void UpdateBuildNumber(string version)
{
_cli.Invoke($"UpdateBuild -Version {version.DoubleQuote()}");
EnvironmentInfo.SetVariable("APPVEYOR_BUILD_VERSION", version);
}

public void PushArtifact(string path, string name = null)
{
name ??= Path.GetFileName(path);
_cli.Invoke($"PushArtifact {path} -FileName {name}");
}

public void WriteInformation(string message, string details = null)
Expand Down
19 changes: 14 additions & 5 deletions source/Nuke.Common/ControlFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,14 @@ public static void ExecuteWithRetry(
[InstantHandle] Action action,
[InstantHandle] Action cleanup = null,
int retryAttempts = 3,
int waitInSeconds = 0)
int waitInSeconds = 0,
Action<string> logAction = null)
{
Assert(retryAttempts > 0, "retryAttempts > 0");

logAction ??= Logger.Warn;
Exception lastException = null;

for (var attempt = 0; attempt < retryAttempts; attempt++)
{
try
Expand All @@ -212,13 +216,14 @@ public static void ExecuteWithRetry(
}
catch (Exception exception)
{
Logger.Warn($"Attempt #{attempt + 1} failed with:");
Logger.Warn(exception.Message);
lastException = exception;
logAction($"Attempt #{attempt + 1} failed with:");
logAction(exception.Message);

if (waitInSeconds <= 0 || attempt + 1 >= retryAttempts)
continue;

Logger.Warn($"Waiting {waitInSeconds} seconds before next attempt...");
logAction($"Waiting {waitInSeconds} seconds before next attempt...");
Task.Delay(TimeSpan.FromSeconds(waitInSeconds)).Wait();
}
finally
Expand All @@ -227,7 +232,11 @@ public static void ExecuteWithRetry(
}
}

Fail($"Executing failed permanently after {retryAttempts} attempts.");
Fail(new[]
{
$"Executing failed permanently after {retryAttempts} attempts.",
$"Last attempt failed with: {lastException!.Message}"
}.JoinNewLine());
}
}
}
Loading

0 comments on commit e22dab8

Please sign in to comment.