Skip to content

Commit

Permalink
Added nuke
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisGerretzen committed Mar 11, 2024
1 parent 29442e9 commit b093cb2
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# This code was generated.
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_publish --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: publish

on: [ workflow_dispatch ]

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

name: test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 10000
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v3
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: Test'
run: ./TorznabClient.Demo/build.cmd Test
11 changes: 11 additions & 0 deletions Gitversion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mode: Mainline
branches:
develop:
is-mainline: true
source-branches: [ ]
increment: Patch
tag: beta
regex: (origin/)?development$
ignore:
sha: [ ]
merge-message-formats: { }
7 changes: 7 additions & 0 deletions TorznabClient.Demo/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:; set -eo pipefail
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
:; ${SCRIPT_DIR}/build.sh "$@"
:; exit $?

@ECHO OFF
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*
67 changes: 67 additions & 0 deletions TorznabClient.Demo/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

bash --version 2>&1 | head -n 1

set -eo pipefail
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)

###########################################################################
# CONFIGURATION
###########################################################################

BUILD_PROJECT_FILE="$SCRIPT_DIR/../build/_build.csproj"
TEMP_DIRECTORY="$SCRIPT_DIR/../.nuke/temp"

DOTNET_GLOBAL_FILE="$SCRIPT_DIR/../global.json"
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="STS"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_NOLOGO=1

###########################################################################
# EXECUTION
###########################################################################

function FirstJsonValue {
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
}

# If dotnet CLI is installed globally and it matches requested version, use for execution
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
export DOTNET_EXE="$(command -v dotnet)"
else
# Download install script
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
mkdir -p "$TEMP_DIRECTORY"
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
chmod +x "$DOTNET_INSTALL_FILE"

# If global.json exists, load expected version
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
if [[ "$DOTNET_VERSION" == "" ]]; then
unset DOTNET_VERSION
fi
fi

# Install by channel or version
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
if [[ -z ${DOTNET_VERSION+x} ]]; then
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
else
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
fi
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
export PATH="$DOTNET_DIRECTORY:$PATH"
fi

echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"

if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then
"$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true
"$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true
fi

"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
4 changes: 4 additions & 0 deletions TorznabClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TorznabClient.Test", "Torzn
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TorznabClient.Demo", "TorznabClient.Demo\TorznabClient.Demo.csproj", "{FADAC85F-8EB1-4603-9BB8-AC34B19D4E90}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{E6B41559-8E39-4CC7-A328-77F6E8B8D8E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E6B41559-8E39-4CC7-A328-77F6E8B8D8E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6B41559-8E39-4CC7-A328-77F6E8B8D8E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{195AEDC3-8D37-4F09-8038-E9CD23549F41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{195AEDC3-8D37-4F09-8038-E9CD23549F41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{195AEDC3-8D37-4F09-8038-E9CD23549F41}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
11 changes: 11 additions & 0 deletions build/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[*.cs]
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning
dotnet_style_require_accessibility_modifiers = never:warning

csharp_style_expression_bodied_methods = true:silent
csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_accessors = true:warning
126 changes: 126 additions & 0 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Serilog;

[GitHubActions(
"test",
GitHubActionsImage.UbuntuLatest,
// On = [GitHubActionsTrigger.PullRequest, GitHubActionsTrigger.WorkflowDispatch, GitHubActionsTrigger.Push],
InvokedTargets = [nameof(Test)],
FetchDepth = 10000,
OnPushBranches = ["main"],
OnPullRequestBranches = ["main"]
)]
[GitHubActions(
"publish",
GitHubActionsImage.UbuntuLatest,
On = [GitHubActionsTrigger.WorkflowDispatch],
// InvokedTargets = [nameof(Pack), nameof(Push)],
InvokedTargets = [nameof(Pack)],
ImportSecrets = [nameof(NugetApiKey)],
FetchDepth = 10000
)]
class Build : NukeBuild
{
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

[GitVersion] readonly GitVersion GitVersion;
[Parameter("API Key for the NuGet server.")] [Secret] readonly string NugetApiKey;
[Parameter("NuGet server URL.")] readonly string NugetSource = "https://api.nuget.org/v3/index.json";
[Parameter("NuGet package version.")] readonly string PackageVersion;
[Solution] readonly Solution Solution;
Project PublishProject => Solution.GetProject("TorznabClient");

AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";

// ReSharper disable once AllUnderscoreLocalParameterName
Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
ArtifactsDirectory.CreateOrCleanDirectory();
DotNetTasks.DotNetClean(s => s
.SetProject(Solution)
);
});

// ReSharper disable once AllUnderscoreLocalParameterName
Target Restore => _ => _
.Executes(() =>
{
DotNetTasks.DotNetRestore(s => s
.SetProjectFile(Solution)
);
});

// ReSharper disable once AllUnderscoreLocalParameterName
Target Compile => _ => _
.DependsOn(Restore)
.Executes(() =>
{
Log.Information("GitVersion = {Value}", GitVersion.MajorMinorPatch);
DotNetTasks.DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.EnableNoRestore()
);
});

// ReSharper disable once AllUnderscoreLocalParameterName
Target Test => _ => _
.DependsOn(Compile)
.Executes(() =>
{
DotNetTasks.DotNetTest(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.EnableNoRestore()
.EnableNoBuild()
);
});

// ReSharper disable once AllUnderscoreLocalParameterName
Target Pack => _ => _
.DependsOn(Clean, Test)
.Before(Push)
.Requires(() => Configuration == Configuration.Release)
.Executes(() =>
{
DotNetTasks.DotNetPack(s => s
.EnableNoRestore()
.EnableNoBuild()
.SetProject(PublishProject)
.SetConfiguration(Configuration)
.SetOutputDirectory(ArtifactsDirectory)
.SetProperty("PackageVersion", PackageVersion ?? GitVersion.NuGetVersionV2)
);
});

// ReSharper disable once AllUnderscoreLocalParameterName
Target Push => _ => _
.Executes(() =>
{
DotNetTasks.DotNetNuGetPush(s => s
.SetSource(NugetSource)
.SetApiKey(NugetApiKey)
.CombineWith(ArtifactsDirectory.GlobFiles("*.nupkg"), (s, v) => s
.SetTargetPath(v)
)
);
});

/// Support plugins are available for:
/// - JetBrains ReSharper https://nuke.build/resharper
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
public static int Main() => Execute<Build>(x => x.Compile);
}
11 changes: 11 additions & 0 deletions build/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel;
using Nuke.Common.Tooling;

[TypeConverter(typeof(TypeConverter<Configuration>))]
public class Configuration : Enumeration
{
public static Configuration Debug = new() { Value = nameof(Debug) };
public static Configuration Release = new() { Value = nameof(Release) };

public static implicit operator string(Configuration configuration) => configuration.Value;
}
8 changes: 8 additions & 0 deletions build/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- This file prevents unintended imports of unrelated MSBuild files -->
<!-- Uncomment to include parent Directory.Build.props file -->
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />-->

</Project>
8 changes: 8 additions & 0 deletions build/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- This file prevents unintended imports of unrelated MSBuild files -->
<!-- Uncomment to include parent Directory.Build.targets file -->
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />-->

</Project>
22 changes: 22 additions & 0 deletions build/_build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..\TorznabClient.Demo</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="8.0.0"/>
</ItemGroup>

<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.12.0]"/>
</ItemGroup>

</Project>

0 comments on commit b093cb2

Please sign in to comment.