Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build system #15

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/Windows_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Make build.sh executable
run: chmod +x ./build.sh
- name: Make build.cmd executable
run: chmod +x ./build.cmd
- uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.*
Expand All @@ -44,4 +48,5 @@ jobs:
run: ./build.cmd NuGet
env:
Nuget_Key: ${{ secrets.NUGET_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJSON(github) }}
16 changes: 12 additions & 4 deletions .github/workflows/pr_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Make build.sh executable
run: chmod +x ./build.sh
- name: Make build.cmd executable
run: chmod +x ./build.cmd
- uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.*
Expand All @@ -45,15 +49,19 @@ jobs:
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd RunTests'
run: ./build.cmd RunTests
- name: Run './build.cmd All'
run: ./build.cmd All
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Make build.sh executable
run: chmod +x ./build.sh
- name: Make build.cmd executable
run: chmod +x ./build.cmd
- uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.*
Expand All @@ -67,7 +75,7 @@ jobs:
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd RunTests'
run: ./build.cmd RunTests
- name: Run './build.cmd All'
run: ./build.cmd All
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
10 changes: 8 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"GitHubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secret [profile]'"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
Expand Down Expand Up @@ -103,13 +107,15 @@
"enum": [
"All",
"AssemblyInfo",
"AuthenticatedGitHubClient",
"BuildRelease",
"Clean",
"Compile",
"CreateNuget",
"DocFx",
"DocsInit",
"DocsMetadata",
"GitHubRelease",
"Install",
"NBench",
"Nuget",
Expand All @@ -118,7 +124,6 @@
"Restore",
"RunTests",
"ServeDocs",
"SetFilePermission",
"SignClient"
]
}
Expand All @@ -134,13 +139,15 @@
"enum": [
"All",
"AssemblyInfo",
"AuthenticatedGitHubClient",
"BuildRelease",
"Clean",
"Compile",
"CreateNuget",
"DocFx",
"DocsInit",
"DocsMetadata",
"GitHubRelease",
"Install",
"NBench",
"Nuget",
Expand All @@ -149,7 +156,6 @@
"Restore",
"RunTests",
"ServeDocs",
"SetFilePermission",
"SignClient"
]
}
Expand Down
35 changes: 28 additions & 7 deletions build/Build.CI.GitHubActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
[CustomGitHubActions("pr_validation",
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
AutoGenerate = true,
AutoGenerate = false,
OnPushBranches = new[] { "master", "dev" },
OnPullRequestBranches = new[] { "master", "dev" },
InvokedTargets = new[] { nameof(RunTests) },
PublishArtifacts = false,
InvokedTargets = new[] { nameof(All) },
PublishArtifacts = true,
EnableGitHubContext = true)
]

[CustomGitHubActions("Windows_release",
GitHubActionsImage.WindowsLatest,
AutoGenerate = true,
OnPushBranches = new[] { "refs/tags/*" },
OnPushTags = new[] { "*" },
AutoGenerate = false,
InvokedTargets = new[] { nameof(NuGet) },
ImportSecrets = new[] { "Nuget_Key" },
ImportSecrets = new[] { "Nuget_Key", "GITHUB_TOKEN" },
EnableGitHubContext = true,
PublishArtifacts = true)
]
Expand All @@ -50,7 +50,14 @@ protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyC
Version = version
});
}

newSteps.Insert(1, new GitHubActionsSetupChmod
{
File = "build.cmd"
});
newSteps.Insert(1, new GitHubActionsSetupChmod
{
File = "build.sh"
});
job.Steps = newSteps.ToArray();
return job;
}
Expand All @@ -73,4 +80,18 @@ public override void Write(CustomFileWriter writer)
}
}
}
}

class GitHubActionsSetupChmod : GitHubActionsStep
{
public string File { get; init; }

public override void Write(CustomFileWriter writer)
{
writer.WriteLine($"- name: Make {File} executable");
using (writer.Indent())
{
writer.WriteLine($"run: chmod +x ./{File}");
}
}
}
122 changes: 84 additions & 38 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using static Nuke.Common.Tools.SignClient.SignClientTasks;
using Nuke.Common.Tools.SignClient;
using static Nuke.Common.Tools.Git.GitTasks;
using Octokit;
using Nuke.Common.Utilities;

[CheckBuildProjectConfigurations]
[ShutdownDotNetAfterServerBuild]
Expand All @@ -42,7 +44,9 @@ partial class Build : NukeBuild
[GitRepository] readonly GitRepository GitRepository;

[Parameter] string NugetPublishUrl = "https://api.nuget.org/v3/index.json";
[Parameter] [Secret] string NugetKey;

[Parameter][Secret] string GitHubToken;
[Parameter][Secret] string NugetKey;

[Parameter] int Port = 8090;

Expand All @@ -57,8 +61,8 @@ partial class Build : NukeBuild
[Parameter] string SigningDescription = "My REALLY COOL Library";
[Parameter] string SigningUrl = "https://signing.is.cool/";

[Parameter] [Secret] string SignClientSecret;
[Parameter] [Secret] string SignClientUser;
[Parameter][Secret] string SignClientSecret;
[Parameter][Secret] string SignClientUser;
// Directories
AbsolutePath ToolsDir => RootDirectory / "tools";
AbsolutePath Output => RootDirectory / "bin";
Expand Down Expand Up @@ -88,7 +92,7 @@ partial class Build : NukeBuild
private string VersionFromReleaseNotes => ReleaseNotes.Version.IsPrerelease ? ReleaseNotes.Version.OriginalVersion : "";
private string VersionSuffix => NugetPrerelease == "dev" ? PreReleaseVersionSuffix : NugetPrerelease == "" ? VersionFromReleaseNotes : NugetPrerelease;
public string ReleaseVersion => ReleaseNotes.Version?.ToString() ?? throw new ArgumentException("Bad Changelog File. Define at least one version");

GitHubClient GitHubClient;
Target Clean => _ => _
.Description("Cleans all the output directories")
.Before(Restore)
Expand Down Expand Up @@ -133,8 +137,6 @@ partial class Build : NukeBuild
.SetVersionPrefix(version)
.SetVersionSuffix(VersionSuffix)
.SetPackageReleaseNotes(releaseNotes)
.SetDescription("YOUR_DESCRIPTION_HERE")
.SetPackageProjectUrl("YOUR_PACKAGE_URL_HERE")
.SetOutputDirectory(OutputNuget));
}
});
Expand All @@ -144,35 +146,88 @@ partial class Build : NukeBuild
.After(CreateNuget, SignClient)
.OnlyWhenDynamic(() => !NugetPublishUrl.IsNullOrEmpty())
.OnlyWhenDynamic(() => !NugetKey.IsNullOrEmpty())
.Triggers(GitHubRelease)
.Executes(() =>
{
var packages = OutputNuget.GlobFiles("*.nupkg", "*.symbols.nupkg").NotNull();
var shouldPublishSymbolsPackages = !string.IsNullOrWhiteSpace(SymbolsPublishUrl);
if (!string.IsNullOrWhiteSpace(NugetPublishUrl))
foreach (var package in packages)
{
foreach (var package in packages)
if (shouldPublishSymbolsPackages)
{
if (shouldPublishSymbolsPackages)
{
DotNetNuGetPush(s => s
.SetTimeout(TimeSpan.FromMinutes(10).Minutes)
.SetTargetPath(package)
.SetSource(NugetPublishUrl)
.SetSymbolSource(SymbolsPublishUrl)
.SetApiKey(NugetKey));
}
else
{
DotNetNuGetPush(s => s
.SetTimeout(TimeSpan.FromMinutes(10).Minutes)
.SetTargetPath(package)
.SetSource(NugetPublishUrl)
.SetApiKey(NugetKey)
);
}
DotNetNuGetPush(s => s
.SetTimeout(TimeSpan.FromMinutes(10).Minutes)
.SetTargetPath(package)
.SetSource(NugetPublishUrl)
.SetSymbolSource(SymbolsPublishUrl)
.SetApiKey(NugetKey));
}
else
{
DotNetNuGetPush(s => s
.SetTimeout(TimeSpan.FromMinutes(10).Minutes)
.SetTargetPath(package)
.SetSource(NugetPublishUrl)
.SetApiKey(NugetKey));
}

}
});
Target AuthenticatedGitHubClient => _ => _
.Unlisted()
.OnlyWhenDynamic(() => !string.IsNullOrWhiteSpace(GitHubToken))
.Executes(() =>
{
GitHubClient = new GitHubClient(new ProductHeaderValue("nuke-build"))
{
Credentials = new Credentials(GitHubToken, AuthenticationType.Bearer)
};
});
Target GitHubRelease => _ => _
.Unlisted()
.Description("Creates a GitHub release (or amends existing) and uploads the artifact")
.OnlyWhenDynamic(() => !string.IsNullOrWhiteSpace(GitHubToken))
.DependsOn(AuthenticatedGitHubClient)
.Executes(async () =>
{
var version = ReleaseNotes.Version.ToString();
var releaseNotes = GetNuGetReleaseNotes(ChangelogFile);
Release release;
var releaseName = $"{version}";
if (!VersionSuffix.IsNullOrWhiteSpace())
releaseName = $"{version}-{VersionSuffix}";
var identifier = GitRepository.Identifier.Split("/");
var (gitHubOwner, repoName) = (identifier[0], identifier[1]);
try
{
release = await GitHubClient.Repository.Release.Get(gitHubOwner, repoName, releaseName);
}
catch (NotFoundException)
{
var newRelease = new NewRelease(releaseName)
{
Body = releaseNotes,
Name = releaseName,
Draft = false,
Prerelease = GitRepository.IsOnReleaseBranch()
};
release = await GitHubClient.Repository.Release.Create(gitHubOwner, repoName, newRelease);
}

foreach (var existingAsset in release.Assets)
{
await GitHubClient.Repository.Release.DeleteAsset(gitHubOwner, repoName, existingAsset.Id);
}

Information($"GitHub Release {releaseName}");
var packages = OutputNuget.GlobFiles("*.nupkg", "*.symbols.nupkg").NotNull();
foreach (var artifact in packages)
{
var releaseAssetUpload = new ReleaseAssetUpload(artifact.Name, "application/zip", File.OpenRead(artifact), null);
var releaseAsset = await GitHubClient.Repository.Release.UploadAsset(release, releaseAssetUpload);
Information($" {releaseAsset.BrowserDownloadUrl}");
}
});
Target RunTests => _ => _
.Description("Runs all the unit tests")
.DependsOn(Compile)
Expand Down Expand Up @@ -306,37 +361,28 @@ private AbsolutePath[] GetDockerProjects()

Target Compile => _ => _
.Description("Builds all the projects in the solution")
.DependsOn(Restore)
.DependsOn(AssemblyInfo, Restore)
.Executes(() =>
{
var version = ReleaseNotes.Version.ToString();
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetAssemblyVersion(version)
.SetFileVersion(version)
.SetVersion(version)
.EnableNoRestore());
});

Target BuildRelease => _ => _
.DependsOn(Clean, AssemblyInfo, Compile);
.DependsOn(Compile);

Target AssemblyInfo => _ => _
.After(Restore)
.Executes(() =>
{
XmlTasks.XmlPoke(SourceDirectory / "Directory.Build.props", "//Project/PropertyGroup/PackageReleaseNotes", GetNuGetReleaseNotes(ChangelogFile));
XmlTasks.XmlPoke(SourceDirectory / "Directory.Build.props", "//Project/PropertyGroup/VersionPrefix", ReleaseVersion);

});

Target SetFilePermission => _ => _
.Description("User may experience PERMISSION issues - this target be used to fix that!")
.Executes(() =>
{
Git($"update-index --chmod=+x {RootDirectory}/build.cmd");
Git($"update-index --chmod=+x {RootDirectory}/build.sh");
});
Target Install => _ => _
.Description("Install `Nuke.GlobalTool` and SignClient")
.Executes(() =>
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<Copyright>Copyright © 2013-2022 Akka.NET Team</Copyright>
<Authors>Akka.NET Team</Authors>
<VersionPrefix>0.3.0</VersionPrefix>
<PackageReleaseNotes>• Fixed bugs</PackageReleaseNotes>
<VersionPrefix>0.1.0</VersionPrefix>
<PackageReleaseNotes>• Initial release of Akka.Hosting%2C Akka.Remote.Hosting%2C Akka.Cluster.Hosting%2C and Akka.Persistence.SqlServer.Hosting</PackageReleaseNotes>
<PackageIconUrl>
</PackageIconUrl>
<PackageProjectUrl>
Expand Down