Skip to content

Commit

Permalink
Merge dab49f1 into 4dc411c
Browse files Browse the repository at this point in the history
  • Loading branch information
aivascu committed Jul 24, 2020
2 parents 4dc411c + dab49f1 commit c2637fd
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 106 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Run './build.cmd Test'
run: ./build.cmd Test
- name: Run './build.cmd Test Cover PublishCoverage DraftRelease'
run: ./build.cmd Test Cover PublishCoverage DraftRelease
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
CoverallsToken: ${{ secrets.CoverallsToken }}
- uses: actions/upload-artifact@v1
with:
name: testresults
path: testresults
- uses: actions/upload-artifact@v1
with:
name: coverage.zip
path: coverage/coverage.zip
- uses: actions/upload-artifact@v1
with:
name: artifacts
path: artifacts
8 changes: 6 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Run './build.cmd Test'
run: ./build.cmd Test
- name: Run './build.cmd Test Cover PublishCoverage'
run: ./build.cmd Test Cover PublishCoverage
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
CoverallsToken: ${{ secrets.CoverallsToken }}
- uses: actions/upload-artifact@v1
with:
name: testresults
path: testresults
- uses: actions/upload-artifact@v1
with:
name: coverage.zip
path: coverage/coverage.zip
15 changes: 0 additions & 15 deletions All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.cspr
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{D916DCA9-C70B-43FF-8773-6BB654007FA8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nuke.Community.GitHub", "src\Nuke.Community.GitHub\Nuke.Community.GitHub.csproj", "{C5338EE4-F28A-431B-B5F4-C54FD544257B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -137,18 +135,6 @@ Global
{214CB4C0-AB9E-4B88-9305-739FC0BEECD6}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{214CB4C0-AB9E-4B88-9305-739FC0BEECD6}.Release|x64.ActiveCfg = Debug|Any CPU
{214CB4C0-AB9E-4B88-9305-739FC0BEECD6}.Release|x86.ActiveCfg = Debug|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Debug|x64.ActiveCfg = Debug|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Debug|x64.Build.0 = Debug|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Debug|x86.ActiveCfg = Debug|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Debug|x86.Build.0 = Debug|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Release|Any CPU.Build.0 = Release|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Release|x64.ActiveCfg = Release|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Release|x64.Build.0 = Release|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Release|x86.ActiveCfg = Release|Any CPU
{C5338EE4-F28A-431B-B5F4-C54FD544257B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -159,7 +145,6 @@ Global
{E508C161-471A-43F6-BA1C-3E03BCF37291} = {77856585-BBC0-4268-8FAF-AE66F8706127}
{B83A9097-8D31-4488-8422-9DC66C2C1CE6} = {77856585-BBC0-4268-8FAF-AE66F8706127}
{214CB4C0-AB9E-4B88-9305-739FC0BEECD6} = {D916DCA9-C70B-43FF-8773-6BB654007FA8}
{C5338EE4-F28A-431B-B5F4-C54FD544257B} = {D916DCA9-C70B-43FF-8773-6BB654007FA8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {47E8857C-BBAB-4EC3-894A-CB6EBA7BB3E5}
Expand Down
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Initial implementation
## [vNext]
- Added initial implementation
- Implements CI build
22 changes: 16 additions & 6 deletions build/Build.Coveralls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,44 @@
using Nuke.Common.CI;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.CoverallsNet;
using Nuke.Common.Tools.GitHub;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using Nuke.Community.GitHub;
using static Nuke.Common.ControlFlow;
using static Nuke.Common.Tools.CoverallsNet.CoverallsNetTasks;
using static Nuke.Common.Tools.Git.GitTasks;
using static Nuke.Community.GitHub.GitHubTasks;

partial class Build
{
[Parameter("Coveralls.io repo token")] readonly string CoverallsToken;
[Parameter("Coveralls.io repo token")] private readonly string CoverallsToken;

private Target PublishCoverage => _ => _
.DependsOn(Cover)
.Consumes(Cover)
.Executes(() =>
{
var commit = GetLastCommit();
var pullRequest = GitHubGetPullRequests(x => x
.SetAuthToken(GitHubToken)
.SetRepositoryName(GitRepository.GetGitHubName())
.SetRepositoryOwner(GitRepository.GetGitHubOwner()))
.FirstOrDefault(x => x.MergeCommitSha.EqualsOrdinalIgnoreCase(GitVersion.Sha));
CoverallsNet(_ => _
.SetDryRun(IsLocalBuild)
.SetRepoToken(CoverallsToken)
.SetArgumentConfigurator(x => x.Add("--lcov"))
.SetInput(CoverageDirectory / "lcov.info")
.SetCommitBranch(GitRepository.Branch)
.SetCommitId(commit.Hash)
.SetCommitAuthor(commit.Name)
.SetCommitEmail(commit.Email)
.SetCommitMessage(commit.Message));
.SetCommitMessage(commit.Message)
.When(pullRequest != null,
_ => _.SetPullRequest((int)pullRequest.Id))
.When(IsLocalBuild,
_ => _.EnableDryRun()));
});

private CommitInfo GetLastCommit() => new[] { RootDirectory / ".git" }
Expand All @@ -37,9 +49,7 @@ partial class Build
workingDirectory: RootDirectory,
logOutput: false))
.Take(1)
.Select(x => x.Text)
.ToList()
.Select(x => x.Split('|'))
.Select(x => x.Text.Split('|'))
.ForEachLazy(x => Assert(x.Length == 4, "Unexpected number of sections"))
.Select(x => new CommitInfo(x[0], x[1], x[2], x[3]))
.Single();
Expand Down
45 changes: 28 additions & 17 deletions build/Build.GitHub.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
using System.Linq;
using System.Text;
using Nuke.Common;
using Nuke.Common.Git;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.GitHub;
using Nuke.Community.GitHub;
using static Nuke.Common.ChangeLog.ChangelogTasks;
using static Nuke.Community.GitHub.GitHubTasks;

internal partial class Build
{
[Parameter("GitHub auth token")] private readonly string GitHubToken;

Target DraftRelease => _ => _
.DependsOn(Publish)
.Requires(() => GitRepository.IsGitHubRepository())
.Executes(() =>
{
GitHubPublishRelease(s => s
.SetAuthToken(GitHubToken)
.EnableDraft()
.SetTag(GitVersion.NuGetVersionV2)
.SetReleaseName($"Version {GitVersion.NuGetVersionV2}")
.SetReleaseBody("# Changes ")
.SetTargetCommitish(GitVersion.Sha)
.When(GitRepository.IsOnDevelopBranch(),
_ => _.EnablePrerelease())
.When(GitRepository.IsOnMasterBranch(),
_ => _.DisablePrerelease()));
});
private Target DraftRelease => _ => _
.DependsOn(Publish)
.Requires(() => GitRepository.IsGitHubRepository())
.Executes(() =>
{
var releaseBody = ExtractChangelogSectionNotes(ChangelogFile)
.Aggregate(
new StringBuilder("# Changes").AppendLine().AppendLine(),
(b, s) => b.AppendLine(s))
.ToString();
GitHubPublishRelease(s => s
.SetAuthToken(GitHubToken)
.SetRepositoryName(GitRepository.GetGitHubName())
.SetRepositoryOwner(GitRepository.GetGitHubOwner())
.EnableDraft()
.SetTag($"v{GitVersion.NuGetVersionV2}")
.SetReleaseName($"Version {GitVersion.NuGetVersionV2}")
.SetReleaseBody(releaseBody)
.SetTargetCommitish(GitVersion.Sha)
.When(GitRepository.IsOnDevelopBranch(),
_ => _.EnablePrerelease())
.When(GitRepository.IsOnMasterBranch(),
_ => _.DisablePrerelease()));
});
}
37 changes: 25 additions & 12 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Nuke.Common;
using Nuke.Common.CI;
Expand All @@ -16,24 +17,27 @@
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.ControlFlow;
using static Nuke.Common.IO.CompressionTasks;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.Git.GitTasks;
using static Nuke.Common.Tools.ReportGenerator.ReportGeneratorTasks;
using static Nuke.Common.ChangeLog.ChangelogTasks;

[CheckBuildProjectConfigurations]
[UnsetVisualStudioEnvironmentVariables]
[DotNetVerbosityMapping]
[ShutdownDotNetBuildServerOnFinish]
[GitHubActions("pull_request",
GitHubActionsImage.WindowsLatest,
OnPullRequestBranches = new[] { MasterBranch, DevelopBranch },
InvokedTargets = new[] { nameof(Test) },
InvokedTargets = new[] { nameof(Test), nameof(Cover), nameof(PublishCoverage) },
ImportGitHubTokenAs = nameof(GitHubToken),
ImportSecrets = new[] { nameof(CoverallsToken) })]
[GitHubActions("continuous",
GitHubActionsImage.WindowsLatest,
OnPushBranches = new[] { MasterBranch },
InvokedTargets = new[] { nameof(Test) },
InvokedTargets = new[] { nameof(Test), nameof(Cover), nameof(PublishCoverage), nameof(DraftRelease) },
ImportGitHubTokenAs = nameof(GitHubToken),
ImportSecrets = new[] { nameof(CoverallsToken) })]
internal partial class Build : NukeBuild
Expand Down Expand Up @@ -62,7 +66,7 @@ internal partial class Build : NukeBuild

[Required] [GitRepository] private readonly GitRepository GitRepository;

[Required] [GitVersion] readonly GitVersion GitVersion;
[Required] [GitVersion] private readonly GitVersion GitVersion;

[Partition(2)] private readonly Partition TestPartition;

Expand All @@ -76,10 +80,12 @@ internal partial class Build : NukeBuild

private List<AbsolutePath> PackageFiles => ArtifactsDirectory.GlobFiles("*.nupkg").ToList();

private string ChangelogFile => RootDirectory / "CHANGELOG.md";
private AbsolutePath SourceDirectory => RootDirectory / "src";
private AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
private AbsolutePath TestResultsDirectory => RootDirectory / "testresults";
private AbsolutePath CoverageDirectory => RootDirectory / "coverage";
private AbsolutePath CoverageArchive => CoverageDirectory / "coverage.zip";

private Target Clean => _ => _
.Before(Restore)
Expand Down Expand Up @@ -123,14 +129,14 @@ internal partial class Build : NukeBuild
.Executes(() =>
{
DotNetTest(s => s
.ResetVerbosity()
.SetConfiguration(Configuration)
.SetNoBuild(InvokedTargets.Contains(Compile))
.ResetVerbosity()
.SetResultsDirectory(TestResultsDirectory)
.When(InvokedTargets.Contains(Cover), _ => _
.When(InvokedTargets.Contains(Cover) || IsServerBuild, _ => _
.EnableCollectCoverage()
.SetArgumentConfigurator(x => x.Add("/p:Exclude={0}", "[TestClasses]*"))
.SetCoverletOutputFormat(CoverletOutputFormat.cobertura)
.SetExcludeByFile("**/TestClasses/**")
.When(IsServerBuild, _ => _.EnableUseSourceLink()))
.CombineWith(TestProjects, (_, v) => _
.SetProjectFile(v)
Expand All @@ -142,16 +148,19 @@ internal partial class Build : NukeBuild
private Target Cover => _ => _
.DependsOn(Test)
.Consumes(Test)
.Produces(CoverageDirectory / "lcov.info")
.Produces(CoverageArchive)
.Executes(() =>
{
ReportGenerator(_ => _
.SetFramework("netcoreapp3.0")
.SetReports(TestResultsDirectory / "*.xml")
.SetTargetDirectory(CoverageDirectory)
.SetReportTypes((ReportTypes)"lcov")
.When(IsLocalBuild, _ => _
.AddReportTypes(ReportTypes.HtmlInline)));
.SetReportTypes((ReportTypes)"lcov", ReportTypes.HtmlInline));
CompressZip(
directory: CoverageDirectory,
archiveFile: CoverageArchive,
fileMode: FileMode.Create);
});

private Target Pack => _ => _
Expand All @@ -161,13 +170,16 @@ internal partial class Build : NukeBuild
.Executes(() =>
{
DotNetPack(s => s
.EnableNoLogo()
.SetConfiguration(Configuration)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetOutputDirectory(ArtifactsDirectory)
.SetVersion(GitVersion.NuGetVersionV2)
.SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg)
.SetPackageReleaseNotes(GetNuGetReleaseNotes(ChangelogFile, GitRepository))
.EnableIncludeSymbols()
.CombineWith(LibProjects, (_, p) => _.SetProject(p)));
.CombineWith(LibProjects,
(_, p) => _.SetProject(p)));
});

private Target Publish => _ => _
Expand All @@ -189,7 +201,8 @@ internal partial class Build : NukeBuild
.SetSource(NuGetSource)
.SetApiKey(NuGetApiKey)
.EnableSkipDuplicate()
.CombineWith(PackageFiles, (_, p) => _.SetTargetPath(p)),
.CombineWith(PackageFiles,
(_, p) => _.SetTargetPath(p)),
degreeOfParallelism: 5,
completeOnFailure: true);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;

namespace Nuke.Community.GitHub
{
[Serializable]
public class GitHubReleaseSettings : GitHubSettings
{
public string ReleaseName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Nuke.Community.GitHub
{
[Serializable]
public class GitHubSettings : ToolSettings
{
public string AuthToken { get; set; }
Expand Down

0 comments on commit c2637fd

Please sign in to comment.