Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Jun 22, 2021
2 parents e72406f + 349bea2 commit 06adfa2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 8 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ jobs:
steps:
- name: Get the sources
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install .NET Core SDK 3.1.407
- name: Install .NET Core SDK 3.1.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.407'
dotnet-version: '3.1.x'

- name: Install .NET Core SDK
uses: actions/setup-dotnet@v1
Expand All @@ -31,11 +33,15 @@ jobs:
env:
NuGetReportSettings_SharedKey: ${{ secrets.NUGETREPORTSETTINGS_SHAREDKEY }}
NuGetReportSettings_WorkspaceId: ${{ secrets.NUGETREPORTSETTINGS_WORKSPACEID }}
GH_PACKAGES_NUGET_SOURCE: ${{ secrets.GH_PACKAGES_NUGET_SOURCE }}
GH_PACKAGES_NUGET_APIKEY: ${{ secrets.GH_PACKAGES_NUGET_APIKEY }}
NUGET_SOURCE: ${{ secrets.NUGET_SOURCE }}
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
run: |
echo ::group::".NET Tool Restore"
dotnet tool restore
echo ::endgroup::
dotnet cake
dotnet cake --target=GitHub-Actions
- name: Upload Artifacts
uses: actions/upload-artifact@v2
Expand Down
47 changes: 46 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#tool "dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=5.6.10"
#addin nuget:?package=System.Text.Json&version=5.0.1&loaddependencies=true
#load "build/records.cake"
#load "build/helpers.cake"
Expand All @@ -7,6 +8,14 @@
*****************************/
Setup(
static context => {
var assertedVersions = context.GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json
});

var branchName = assertedVersions.BranchName;
var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName);

var gh = context.GitHubActions();
var buildDate = DateTime.UtcNow;
var runNumber = gh.IsRunningOnGitHubActions
Expand All @@ -16,13 +25,18 @@ Setup(
var version = FormattableString
.Invariant($"{buildDate:yyyy.M.d}.{runNumber}");

context.Information("Building version {0}", version);
context.Information("Building version {0} (Branch: {1}, IsMain: {2})",
version,
branchName,
isMainBranch);

var artifactsPath = context
.MakeAbsolute(context.Directory("./artifacts"));

return new BuildData(
version,
isMainBranch,
!context.IsRunningOnWindows(),
"src",
new DotNetCoreMSBuildSettings()
.SetConfiguration("Release")
Expand Down Expand Up @@ -181,4 +195,35 @@ Task("Clean")
)
.Then("Integration-Tests")
.Default()
.Then("Push-GitHub-Packages")
.WithCriteria<BuildData>( (context, data) => data.ShouldPushGitHubPackages())
.DoesForEach<BuildData, FilePath>(
static (data, context)
=> context.GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg"),
static (data, item, context)
=> context.DotNetCoreNuGetPush(
item.FullPath,
new DotNetCoreNuGetPushSettings
{
Source = data.GitHubNuGetSource,
ApiKey = data.GitHubNuGetApiKey
}
)
)
.Then("Push-NuGet-Packages")
.WithCriteria<BuildData>( (context, data) => data.ShouldPushNuGetPackages())
.DoesForEach<BuildData, FilePath>(
static (data, context)
=> context.GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg"),
static (data, item, context)
=> context.DotNetCoreNuGetPush(
item.FullPath,
new DotNetCoreNuGetPushSettings
{
Source = data.NuGetSource,
ApiKey = data.NuGetApiKey
}
)
)
.Then("GitHub-Actions")
.Run();
20 changes: 18 additions & 2 deletions build/records.cake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using System.Text.Json.Serialization;
*****************************/
public record BuildData(
string Version,
bool IsMainBranch,
bool ShouldNotPublish,
DirectoryPath ProjectRoot,
DotNetCoreMSBuildSettings MSBuildSettings,
DirectoryPath ArtifactsPath,
Expand All @@ -14,14 +16,28 @@ public record BuildData(
{
private const string IntegrationTest = "integrationtest";
public DirectoryPath NuGetOutputPath { get; } = OutputPath.Combine("nuget");
public DirectoryPath BinaryOutputPath { get; } = OutputPath.Combine("bin");
public DirectoryPath IntegrationTestPath { get; } = OutputPath.Combine(IntegrationTest);

public string GitHubNuGetSource { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
public string GitHubNuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_APIKEY");

public bool ShouldPushGitHubPackages() => !ShouldNotPublish
&& !string.IsNullOrWhiteSpace(GitHubNuGetSource)
&& !string.IsNullOrWhiteSpace(GitHubNuGetApiKey);

public string NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
public string NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
public bool ShouldPushNuGetPackages() => IsMainBranch &&
!ShouldNotPublish &&
!string.IsNullOrWhiteSpace(NuGetSource) &&
!string.IsNullOrWhiteSpace(NuGetApiKey);

public ICollection<DirectoryPath> DirectoryPathsToClean = new []{
ArtifactsPath,
OutputPath,
OutputPath.Combine(IntegrationTest)
};


}

private record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);
Expand Down
5 changes: 3 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"sdk": {
"version": "5.0.201",
"rollForward": "latestFeature"
"version": "5.0.301",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
8 changes: 8 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>

0 comments on commit 06adfa2

Please sign in to comment.