Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Dec 4, 2024
1 parent 771f719 commit b05c7b1
Show file tree
Hide file tree
Showing 21 changed files with 1,517 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ------------------------------------------------------------------------------
# Build.yml
# ------------------------------------------------------------------------------

name: Build

on:
push:
pull_request:
branches-ignore:
- master
- main
workflow_dispatch:

jobs:
Build:
name: Build
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Run './Build/build.cmd'
run: ./Build/build.cmd --root ./Build
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
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
147 changes: 147 additions & 0 deletions Build/.nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"Host": {
"type": "string",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"ExecutableTarget": {
"type": "string",
"enum": [
"Build",
"Clean",
"Compile",
"GitRelease",
"Release",
"Sign",
"Test"
]
},
"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"
}
}
}
},
"allOf": [
{
"properties": {
"Folder": {
"type": "string"
},
"GitHubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"MainName": {
"type": "string"
},
"ReleaseFolder": {
"type": "string"
},
"ReleaseNameVersion": {
"type": "boolean"
},
"SignFile": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"SignPassword": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"TestBuildStopWhenFailed": {
"type": "boolean"
},
"TestResults": {
"type": "boolean"
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
]
}
4 changes: 4 additions & 0 deletions Build/.nuke/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "./build.schema.json",
"Solution": "../Nuke.NuGetKeyVaultSignTool.sln"
}
10 changes: 10 additions & 0 deletions Build/Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Nuke.Common;
using Nuke.Common.Execution;
using ricaun.Nuke;
using ricaun.Nuke.Components;

class Build : NukeBuild, IPublish, ITest //,IShowNuGetKeyVaultSign
{
string ITest.TestProjectName => "Nuke.NuGetKeyVaultSignTool";
public static int Main() => Execute<Build>(x => x.From<IPublish>().Build);
}
36 changes: 36 additions & 0 deletions Build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>.</NukeRootDirectory>
<NukeScriptDirectory>.</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ricaun.Nuke" Version="*" />
</ItemGroup>

<ItemGroup>
<None Include="..\.github\workflows\*.yml" LinkBase="ci" />
<None Include=".github\**\*" />
<None Include=".nuke\*" />
</ItemGroup>

<!--<ItemGroup>
<ProjectReference Include="..\Nuke.NuGetKeyVaultSignTool\Nuke.NuGetKeyVaultSignTool.csproj" />
</ItemGroup>
<ItemGroup>
<PackageDownload Include="AzureSignTool" Version="[6.0.0]" />
<PackageDownload Include="AzureSignTool" Version="[5.0.0]" />
<PackageDownload Include="NuGetKeyVaultSignTool" Version="[3.2.3]" />
</ItemGroup>
<PropertyGroup>
<NoWarn>$(NoWarn);NU1505</NoWarn>
</PropertyGroup>-->

</Project>
74 changes: 74 additions & 0 deletions Build/IShowNuGetKeyVaultSign.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//using Nuke.Common;
//using ricaun.Nuke.Components;
//using Nuke.Common.Tools.AzureSignTool;
//using System;
//using Newtonsoft.Json;
//using Nuke.Common.IO;
//using System.IO;
//using System.Reflection;

//public interface IShowNuGetKeyVaultSign : IClean, ICompile
//{
// private static string AZURE_KEY_VAULT_FILE => Environment.GetEnvironmentVariable("AZURE_KEY_VAULT_FILE");
// private static string AZURE_KEY_VAULT_PASSWORD => Environment.GetEnvironmentVariable("AZURE_KEY_VAULT_PASSWORD");

// Target ShowNuGetKeyVaultSign => _ => _
// .TriggeredBy(Clean)
// .Before(Compile)
// .Executes(() =>
// {
// Serilog.Log.Information(NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath);

// if (string.IsNullOrEmpty(AZURE_KEY_VAULT_FILE))
// {
// Serilog.Log.Warning("AZURE_KEY_VAULT_FILE is null");
// return;
// }

// if (string.IsNullOrEmpty(AZURE_KEY_VAULT_PASSWORD))
// {
// Serilog.Log.Warning("AZURE_KEY_VAULT_PASSWORD is null");
// return;
// }

// var azureKeyVaultFile = JsonConvert.DeserializeObject<AzureKeyVaultConfig>(AZURE_KEY_VAULT_FILE);
// var azureKeyVaultClientSecret = AZURE_KEY_VAULT_PASSWORD;

// if (azureKeyVaultFile is null)
// {
// Serilog.Log.Warning("AzureKeyVaultConfig is null");
// return;
// }

// if (azureKeyVaultFile.IsValid() == false)
// {
// Serilog.Log.Warning($"{azureKeyVaultFile} is not valid");
// return;
// }

// Serilog.Log.Information($"Sign package using AzureKeyVaultCertificate {azureKeyVaultFile.AzureKeyVaultCertificate}");

// AbsolutePath rootAssembly = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
// var fileNameToSign = "file.nupkg";
// var fullPath = Path.Combine(rootAssembly, fileNameToSign);

// var length = (double) new System.IO.FileInfo(fullPath).Length;

// NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x
// .SetFile(fullPath)
// .SetKeyVaultCertificateName(azureKeyVaultFile.AzureKeyVaultCertificate)
// .SetKeyVaultUrl(azureKeyVaultFile.AzureKeyVaultUrl)
// .SetKeyVaultClientId(azureKeyVaultFile.AzureKeyVaultClientId)
// .SetKeyVaultTenantId(azureKeyVaultFile.AzureKeyVaultTenantId)
// .SetKeyVaultClientSecret(azureKeyVaultClientSecret)
// .SetTimestampRfc3161Url(azureKeyVaultFile.TimestampUrl ?? "http://timestamp.digicert.com")
// .SetTimestampDigest(azureKeyVaultFile.TimestampDigest ?? NuGetKeyVaultSignToolDigestAlgorithm.sha256)
// .SetForce(true)
// );

// var lengthAfter = (double) new System.IO.FileInfo(fullPath).Length;

// Serilog.Log.Warning($"Sign package {fileNameToSign} - {lengthAfter} {length}");

// });
//}
7 changes: 7 additions & 0 deletions Build/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" %*
69 changes: 69 additions & 0 deletions Build/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[CmdletBinding()]
Param(
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$BuildArguments
)

Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"

Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent

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

$BuildProjectFile = "$PSScriptRoot\Build.csproj"
$TempDirectory = "$PSScriptRoot\\.nuke\temp"

$DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "LTS"

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_MULTILEVEL_LOOKUP = 0

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

function ExecSafe([scriptblock] $cmd) {
& $cmd
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}

# If dotnet CLI is installed globally and it matches requested version, use for execution
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
$env:DOTNET_EXE = (Get-Command "dotnet").Path
}
else {
# Download install script
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)

# If global.json exists, load expected version
if (Test-Path $DotNetGlobalFile) {
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
$DotNetVersion = $DotNetGlobal.sdk.version
}
}

# Install by channel or version
$DotNetDirectory = "$TempDirectory\dotnet-win"
if (!(Test-Path variable:DotNetVersion)) {
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
} else {
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
}
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
}

Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"

ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
Loading

0 comments on commit b05c7b1

Please sign in to comment.