Add build script
This commit is contained in:
parent
2a642faecd
commit
5d554ea58d
7 changed files with 240 additions and 0 deletions
1
.nuke
Normal file
1
.nuke
Normal file
|
@ -0,0 +1 @@
|
||||||
|
src/Robware.Api.Blog.sln
|
68
build.ps1
Normal file
68
build.ps1
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
Param(
|
||||||
|
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
|
||||||
|
[string[]]$BuildArguments
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Output "Windows PowerShell $($Host.Version)"
|
||||||
|
|
||||||
|
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { exit 1 }
|
||||||
|
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
# CONFIGURATION
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
|
||||||
|
$TempDirectory = "$PSScriptRoot\\.tmp"
|
||||||
|
|
||||||
|
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
|
||||||
|
$DotNetInstallUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1"
|
||||||
|
$DotNetChannel = "Current"
|
||||||
|
|
||||||
|
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
|
||||||
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
# EXECUTION
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
function ExecSafe([scriptblock] $cmd) {
|
||||||
|
& $cmd
|
||||||
|
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
|
||||||
|
if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -ne $null -and `
|
||||||
|
(!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) {
|
||||||
|
$env:DOTNET_EXE = (Get-Command "dotnet").Path
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$DotNetDirectory = "$TempDirectory\dotnet-win"
|
||||||
|
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
|
||||||
|
|
||||||
|
# Download install script
|
||||||
|
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
|
||||||
|
md -force $TempDirectory > $null
|
||||||
|
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
|
||||||
|
|
||||||
|
# Install by channel or version
|
||||||
|
if (!(Test-Path variable:DotNetVersion)) {
|
||||||
|
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
|
||||||
|
} else {
|
||||||
|
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"
|
||||||
|
|
||||||
|
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false }
|
||||||
|
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
|
62
build.sh
Normal file
62
build.sh
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo $(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//.tmp"
|
||||||
|
|
||||||
|
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
|
||||||
|
DOTNET_INSTALL_URL="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh"
|
||||||
|
DOTNET_CHANNEL="Current"
|
||||||
|
|
||||||
|
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||||
|
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
# EXECUTION
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
function FirstJsonValue {
|
||||||
|
perl -nle 'print $1 if m{"'$1'": "([^"\-]+)",?}' <<< ${@:2}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
|
||||||
|
if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then
|
||||||
|
export DOTNET_EXE="$(command -v dotnet)"
|
||||||
|
else
|
||||||
|
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
|
||||||
|
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
# Install by channel or version
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"
|
||||||
|
|
||||||
|
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false
|
||||||
|
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
|
10
build/.editorconfig
Normal file
10
build/.editorconfig
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[*.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_properties = true:warning
|
||||||
|
csharp_style_expression_bodied_indexers = true:warning
|
||||||
|
csharp_style_expression_bodied_accessors = true:warning
|
61
build/Build.cs
Normal file
61
build/Build.cs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
using Nuke.Common;
|
||||||
|
using Nuke.Common.Execution;
|
||||||
|
using Nuke.Common.IO;
|
||||||
|
using Nuke.Common.ProjectModel;
|
||||||
|
using Nuke.Common.Tools.DotNet;
|
||||||
|
using Nuke.Common.Utilities.Collections;
|
||||||
|
using static Nuke.Common.IO.FileSystemTasks;
|
||||||
|
using static Nuke.Common.Tools.DotNet.DotNetTasks;
|
||||||
|
|
||||||
|
[CheckBuildProjectConfigurations]
|
||||||
|
[UnsetVisualStudioEnvironmentVariables]
|
||||||
|
class Build : NukeBuild {
|
||||||
|
public static int Main() => Execute<Build>(x => x.Publish);
|
||||||
|
|
||||||
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
||||||
|
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
|
||||||
|
|
||||||
|
[Solution] readonly Solution Solution;
|
||||||
|
|
||||||
|
AbsolutePath SourceDirectory => RootDirectory / "src";
|
||||||
|
AbsolutePath OutputDirectory => RootDirectory / "output";
|
||||||
|
|
||||||
|
Target Clean => _ => _
|
||||||
|
.Before(Restore)
|
||||||
|
.Executes(() => {
|
||||||
|
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
|
||||||
|
EnsureCleanDirectory(OutputDirectory);
|
||||||
|
});
|
||||||
|
|
||||||
|
Target Restore => _ => _
|
||||||
|
.Executes(() => {
|
||||||
|
DotNetRestore(s => s
|
||||||
|
.SetProjectFile(Solution));
|
||||||
|
});
|
||||||
|
|
||||||
|
Target Compile => _ => _
|
||||||
|
.DependsOn(Restore)
|
||||||
|
.Executes(() => {
|
||||||
|
DotNetBuild(s => s
|
||||||
|
.SetProjectFile(Solution)
|
||||||
|
.SetConfiguration(Configuration)
|
||||||
|
.EnableNoRestore());
|
||||||
|
});
|
||||||
|
|
||||||
|
Target Test => _ => _
|
||||||
|
.DependsOn(Compile)
|
||||||
|
.Executes(() => {
|
||||||
|
DotNetTest(s => s
|
||||||
|
.SetProjectFile(Solution)
|
||||||
|
.EnableNoRestore());
|
||||||
|
});
|
||||||
|
|
||||||
|
Target Publish => _ => _
|
||||||
|
.DependsOn(Test)
|
||||||
|
.Executes(() => {
|
||||||
|
DotNetPublish(s => s
|
||||||
|
.SetProject(SourceDirectory / "Robware.Api.Blog/Robware.Api.Blog.csproj")
|
||||||
|
.SetConfiguration(Configuration)
|
||||||
|
.SetOutput(OutputDirectory));
|
||||||
|
});
|
||||||
|
}
|
34
build/_build.csproj
Normal file
34
build/_build.csproj
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
|
<RootNamespace></RootNamespace>
|
||||||
|
<IsPackable>False</IsPackable>
|
||||||
|
<NoWarn>CS0649;CS0169</NoWarn>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Nuke.Common" Version="0.24.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<NukeSpecificationFiles Include="**\*.json" Exclude="bin\**;obj\**" />
|
||||||
|
<NukeExternalFiles Include="**\*.*.ext" Exclude="bin\**;obj\**" />
|
||||||
|
<None Remove="*.csproj.DotSettings;*.ref.*.txt" />
|
||||||
|
|
||||||
|
<!-- Common build related files -->
|
||||||
|
<None Include="..\build.ps1" />
|
||||||
|
<None Include="..\build.sh" />
|
||||||
|
<None Include="..\.nuke" />
|
||||||
|
<None Include="..\global.json" Condition="Exists('..\global.json')" />
|
||||||
|
<None Include="..\nuget.config" Condition="Exists('..\nuget.config')" />
|
||||||
|
<None Include="..\azure-pipelines.yml" Condition="Exists('..\azure-pipelines.yml')" />
|
||||||
|
<None Include="..\Jenkinsfile" Condition="Exists('..\Jenkinsfile')" />
|
||||||
|
<None Include="..\appveyor.yml" Condition="Exists('..\appveyor.yml')" />
|
||||||
|
<None Include="..\.travis.yml" Condition="Exists('..\.travis.yml')" />
|
||||||
|
<None Include="..\GitVersion.yml" Condition="Exists('..\GitVersion.yml')" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -18,12 +18,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robware.Api.Blog.Tests", "Robware.Api.Blog.Tests\Robware.Api.Blog.Tests.csproj", "{54DEC274-5F28-42FB-9B60-1E4BAF3D7BF9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robware.Api.Blog.Tests", "Robware.Api.Blog.Tests\Robware.Api.Blog.Tests.csproj", "{54DEC274-5F28-42FB-9B60-1E4BAF3D7BF9}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "..\build\_build.csproj", "{9F55FA01-FEC9-4326-8338-4EF014E127A4}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{9F55FA01-FEC9-4326-8338-4EF014E127A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9F55FA01-FEC9-4326-8338-4EF014E127A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C5B2C08C-423C-494D-8C2B-77F2C73F36CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{C5B2C08C-423C-494D-8C2B-77F2C73F36CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{C5B2C08C-423C-494D-8C2B-77F2C73F36CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C5B2C08C-423C-494D-8C2B-77F2C73F36CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C5B2C08C-423C-494D-8C2B-77F2C73F36CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C5B2C08C-423C-494D-8C2B-77F2C73F36CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue