Skip to content

Commit

Permalink
Add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletKuro committed Oct 28, 2024
1 parent 7a32f9f commit c19ca7f
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 28 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# This code was generated.
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_continuous --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: continuous

on: [push]

jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: Compile, Pack'
run: ./build.cmd Compile Pack
- name: 'Publish: packages'
uses: actions/upload-artifact@v4
with:
name: packages
path: artifacts/packages
48 changes: 48 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# This code was generated.
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_release --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: release

on:
push:
tags:
- '\d+\.\d+\.\d+'

jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: Push, PushGithubNuget'
run: ./build.cmd Push PushGithubNuget
env:
NugetKey: ${{ secrets.NUGET_KEY }}
GithubToken: ${{ secrets.GITHUB_TOKEN }}
- name: 'Publish: packages'
uses: actions/upload-artifact@v4
with:
name: packages
path: artifacts/packages
130 changes: 130 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
]
},
"GithubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"NugetApiUrl": {
"type": "string"
},
"NugetKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
}
},
"definitions": {
"Host": {
"type": "string",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"ExecutableTarget": {
"type": "string",
"enum": [
"Clean",
"Compile",
"Pack",
"Push",
"PushGithubNuget",
"Restore",
"VerifyFormat"
]
},
"Verbosity": {
"type": "string",
"description": "",
"enum": [
"Verbose",
"Normal",
"Minimal",
"Quiet"
]
},
"NukeBuild": {
"properties": {
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
},
"Host": {
"description": "Host for execution. Default is 'automatic'",
"$ref": "#/definitions/Host"
},
"NoLogo": {
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"Partition": {
"type": "string",
"description": "Partition to use on CI"
},
"Plan": {
"type": "boolean",
"description": "Shows the execution plan (HTML)"
},
"Profile": {
"type": "array",
"description": "Defines the profiles to load",
"items": {
"type": "string"
}
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
},
"Skip": {
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"$ref": "#/definitions/ExecutableTarget"
}
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"$ref": "#/definitions/ExecutableTarget"
}
},
"Verbosity": {
"description": "Logging verbosity during build execution. Default is 'Normal'",
"$ref": "#/definitions/Verbosity"
}
}
}
},
"$ref": "#/definitions/NukeBuild"
}
52 changes: 34 additions & 18 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
"continuous",
GitHubActionsImage.UbuntuLatest,
FetchDepth = 0,
On = new[] { GitHubActionsTrigger.Push },
On = [GitHubActionsTrigger.Push],
PublishArtifacts = true,
InvokedTargets = new[] { nameof(Compile), nameof(Pack) })]
InvokedTargets = [nameof(Compile), nameof(Pack)])]
[GitHubActions(
"release",
GitHubActionsImage.UbuntuLatest,
FetchDepth = 0,
OnPushTags = new[] { @"\d+\.\d+\.\d+" },
OnPushTags = [@"\d+\.\d+\.\d+"],
PublishArtifacts = true,
InvokedTargets = new[] { nameof(Push), nameof(PushGithubNuget) },
ImportSecrets = new[] { nameof(NuGetApiKey), nameof(PersonalAccessToken) })]
InvokedTargets = [nameof(Push), nameof(PushGithubNuget)],
ImportSecrets = [nameof(NugetKey), nameof(GithubToken)])]
class Build : NukeBuild
{
/// Support plugins are available for:
Expand All @@ -40,19 +40,19 @@ class Build : NukeBuild
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode

public static int Main () => Execute<Build>(x => x.Compile);
public static int Main() => Execute<Build>(x => x.Compile);

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = Configuration.Release;

[Parameter] readonly string NugetApiUrl = "https://api.nuget.org/v3/index.json"; //default
[Parameter][Secret] readonly string NugetKey;
[Parameter][Secret] readonly string GithubToken;

[Parameter] string NugetApiUrl = "https://api.nuget.org/v3/index.json"; //default
bool RunFormatAnalyzers => false;

bool IsTag => GitHubActions.Instance?.Ref?.StartsWith("refs/tags/") ?? false;

[Parameter][Secret] readonly string NuGetApiKey;
[Parameter][Secret] readonly string PersonalAccessToken;

[Solution] readonly Solution Solution;
[GitRepository] readonly GitRepository GitRepository;

Expand All @@ -78,8 +78,23 @@ class Build : NukeBuild
.SetProjectFile(Solution));
});

Target VerifyFormat => _ => _
.After(Restore)
.Description("Verify code formatting for the solution.")
.Executes(() =>
{
DotNet($"format whitespace {Solution.Path} --verify-no-changes ");

DotNet($"format style {Solution.Path} --verify-no-changes ");

if (RunFormatAnalyzers)
{
DotNet($"format analyzers {Solution.Path} --verify-no-changes ");
}
});

Target Compile => _ => _
.DependsOn(Restore)
.DependsOn(Restore, VerifyFormat)
.Executes(() =>
{
DotNetBuild(s => s
Expand All @@ -93,7 +108,8 @@ class Build : NukeBuild
.Produces(PackagesDirectory / "*.nupkg")
.Produces(PackagesDirectory / "*.snupkg")
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() => {
.Executes(() =>
{
DotNetPack(_ => _
.Apply(PackSettings));

Expand All @@ -104,13 +120,13 @@ class Build : NukeBuild
Target Push => _ => _
.DependsOn(Pack)
.OnlyWhenStatic(() => IsTag && IsServerBuild)
.Requires(() => NuGetApiKey)
.Requires(() => NugetKey)
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() =>
{
Log.Information("Running push to packages directory.");

Assert.True(!string.IsNullOrEmpty(NuGetApiKey));
Assert.True(!string.IsNullOrEmpty(NugetKey));

PackagesDirectory.GlobFiles("*.nupkg")
.ForEach(x =>
Expand All @@ -120,7 +136,7 @@ class Build : NukeBuild
DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource(NugetApiUrl)
.SetApiKey(NuGetApiKey)
.SetApiKey(NugetKey)
.EnableSkipDuplicate()
);
});
Expand All @@ -130,7 +146,7 @@ class Build : NukeBuild
Target PushGithubNuget => _ => _
.DependsOn(Pack)
.OnlyWhenStatic(() => IsTag && IsServerBuild)
.Requires(() => PersonalAccessToken)
.Requires(() => GithubToken)
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() =>
{
Expand All @@ -141,12 +157,12 @@ class Build : NukeBuild
{
x.NotNull();

Assert.True(!string.IsNullOrEmpty(PersonalAccessToken));
Assert.True(!string.IsNullOrEmpty(GithubToken));

DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource($"https://nuget.pkg.github.com/{GitHubActions.Instance.RepositoryOwner}/index.json")
.SetApiKey(PersonalAccessToken)
.SetApiKey(GithubToken)
.EnableSkipDuplicate()
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Scarlet.System.Text.Json.DateTimeConverter.Converters;
/// <summary>
/// Converts <see cref="DateTime"/> objects to and from JSON using a specified date format.
/// </summary>
internal class DateTimeConverter : JsonConverter<DateTime>
internal sealed class DateTimeConverter : JsonConverter<DateTime>
{
private readonly string _format;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Scarlet.System.Text.Json.DateTimeConverter.Converters;
/// <summary>
/// Converts nullable <see cref="DateTime"/> objects to and from JSON using a specified date format.
/// </summary>
internal class DateTimeNullableConverter : JsonConverter<DateTime?>
internal sealed class DateTimeNullableConverter : JsonConverter<DateTime?>
{
private readonly string _format;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Scarlet.System.Text.Json.DateTimeConverter.Converters;
/// <summary>
/// Converts <see cref="DateTimeOffsetConverter"/> objects to and from JSON using a specified date format.
/// </summary>
internal class DateTimeOffsetConverter : JsonConverter<DateTimeOffset>
internal sealed class DateTimeOffsetConverter : JsonConverter<DateTimeOffset>
{
private readonly string _format;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Scarlet.System.Text.Json.DateTimeConverter.Converters;
/// <summary>
/// Converts nullable <see cref="DateTimeOffset"/> objects to and from JSON using a specified date format.
/// </summary>
internal class DateTimeOffsetNullableConverter : JsonConverter<DateTimeOffset?>
internal sealed class DateTimeOffsetNullableConverter : JsonConverter<DateTimeOffset?>
{
private readonly string _format;

Expand Down
Loading

0 comments on commit c19ca7f

Please sign in to comment.