Skip to content

Commit aa5cb7b

Browse files
committed
Add nuke and appveyor for building
1 parent 6e709c6 commit aa5cb7b

16 files changed

Lines changed: 582 additions & 0 deletions

.nuke/parameters.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./build.schema.json",
3+
"Solution": "Abstract.FileSystem.sln"
4+
}

Abstract.FileSystem.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{AC210C33
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Abstract.FileSystem.Test", "Tests\Abstract.FileSystem.Test\Abstract.FileSystem.Test.csproj", "{80DED7E1-90C4-43D1-8043-1B7693FCB42B}"
1111
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{A77E2487-9254-4819-905B-1721F147D704}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
1517
Release|Any CPU = Release|Any CPU
1618
EndGlobalSection
1719
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{A77E2487-9254-4819-905B-1721F147D704}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{A77E2487-9254-4819-905B-1721F147D704}.Release|Any CPU.ActiveCfg = Release|Any CPU
1822
{3305D6E6-D721-48AA-AA78-1F05361F8257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1923
{3305D6E6-D721-48AA-AA78-1F05361F8257}.Debug|Any CPU.Build.0 = Debug|Any CPU
2024
{3305D6E6-D721-48AA-AA78-1F05361F8257}.Release|Any CPU.ActiveCfg = Release|Any CPU

Abstract.FileSystem/OsType.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+

2+
namespace Abstract.FileSystem
3+
{
4+
public enum OsType
5+
{
6+
Unix,
7+
Windows
8+
}
9+
}

Abstract.FileSystem/SystemPath.cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Globalization;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Runtime.InteropServices;
8+
using System.Text;
9+
10+
namespace Abstract.FileSystem
11+
{
12+
public class SystemPath
13+
{
14+
internal const char WinSeparator = '\\';
15+
internal const char UncSeparator = '\\';
16+
internal const char UnixSeparator = '/';
17+
18+
public static SystemPath Create(string path)
19+
{
20+
return new SystemPath(path);
21+
}
22+
23+
static SystemPath()
24+
{
25+
OsType = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? OsType.Windows : OsType.Unix;
26+
}
27+
28+
private readonly string _path;
29+
30+
private SystemPath(string path)
31+
{
32+
_path = NormalizePath(path);
33+
}
34+
35+
public static implicit operator SystemPath(string path)
36+
{
37+
if (path is null)
38+
{
39+
return null;
40+
}
41+
42+
return new SystemPath(path);
43+
}
44+
45+
public static implicit operator string(SystemPath path)
46+
{
47+
return path?.ToString();
48+
}
49+
50+
public static OsType OsType { get; }
51+
52+
public static SystemPath operator /(SystemPath left, string right)
53+
{
54+
return new SystemPath(Combine(left, right));
55+
}
56+
57+
public static SystemPath operator +(SystemPath left, string right)
58+
{
59+
return new SystemPath(left.ToString() + right);
60+
}
61+
62+
public static bool operator ==(SystemPath a, SystemPath b)
63+
{
64+
return EqualityComparer<SystemPath>.Default.Equals(a, b);
65+
}
66+
67+
public static bool operator !=(SystemPath a, SystemPath b)
68+
{
69+
return !EqualityComparer<SystemPath>.Default.Equals(a, b);
70+
}
71+
72+
protected bool Equals(SystemPath other)
73+
{
74+
var stringComparison = OsType == OsType.Unix ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
75+
return string.Equals(_path, other._path, stringComparison);
76+
}
77+
78+
public override bool Equals(object obj)
79+
{
80+
if (ReferenceEquals(objA: null, obj))
81+
return false;
82+
if (ReferenceEquals(this, obj))
83+
return true;
84+
if (obj.GetType() != GetType())
85+
return false;
86+
return Equals((SystemPath)obj);
87+
}
88+
89+
public override int GetHashCode()
90+
{
91+
return _path?.GetHashCode() ?? 0;
92+
}
93+
94+
public override string ToString()
95+
{
96+
return ((IFormattable)this).ToString(format: null, formatProvider: null);
97+
}
98+
99+
public static string NormalizePath(string path)
100+
{
101+
if (OsType == OsType.Unix)
102+
{
103+
return path.Replace(WinSeparator, UnixSeparator);
104+
}
105+
106+
return path.Replace(UnixSeparator, WinSeparator);
107+
}
108+
109+
public static string Combine(SystemPath path, params string[] elements)
110+
{
111+
throw new NotImplementedException();
112+
}
113+
114+
internal static bool IsWinRoot(string root)
115+
=> root?.Length == 2 &&
116+
char.IsLetter(root[index: 0]) &&
117+
root[index: 1] == ':';
118+
119+
internal static bool IsUnixRoot(string root)
120+
=> root?.Length == 1 &&
121+
root[index: 0] == UnixSeparator;
122+
123+
internal static bool IsUncRoot(string root)
124+
=> root?.Length >= 3 &&
125+
root[index: 0] == UncSeparator &&
126+
root[index: 1] == UncSeparator &&
127+
root.Skip(count: 2).All(char.IsLetterOrDigit);
128+
}
129+
130+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 wickedflame development
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

appveyor.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# http://www.appveyor.com/docs/appveyor-yml
2+
3+
environment:
4+
base_version: 1.0.0
5+
6+
# version format
7+
version: $(base_version).{build}
8+
9+
image:
10+
- Visual Studio 2022
11+
12+
skip_tags: true
13+
branches:
14+
only:
15+
- master
16+
- dev
17+
18+
for:
19+
-
20+
# branches to build
21+
branches:
22+
# whitelist
23+
only:
24+
- dev
25+
26+
# Do not build on tags (GitHub only)
27+
skip_tags: true
28+
29+
install:
30+
- dotnet tool install Nuke.GlobalTool --global --version 7.0.6 --no-cache
31+
32+
before_build:
33+
- dotnet restore ./build/_build.csproj
34+
35+
build_script:
36+
- nuke Release --isrc true --version "%base_version%" --buildno "%APPVEYOR_BUILD_NUMBER%" --configuration Release
37+
38+
-
39+
# branches to build
40+
branches:
41+
# whitelist
42+
only:
43+
- master
44+
45+
# Do not build on tags (GitHub only)
46+
skip_tags: true
47+
48+
install:
49+
- dotnet tool install Nuke.GlobalTool --global --version 7.0.6 --no-cache
50+
51+
before_build:
52+
- dotnet restore ./build/_build.csproj
53+
54+
build_script:
55+
- nuke Release --isrc false --version "%base_version%" --buildno "%APPVEYOR_BUILD_NUMBER%" --configuration Release
56+
57+
artifacts:
58+
- path: src\Abstract.FileSystem\bin\Release\netstandard2.0\Abstract.FileSystem.dll
59+
name: Abstract.FileSystem.dll
60+
- path: src\Abstract.FileSystem\bin\Release\netstandard2.0\Abstract.FileSystem.xml
61+
name: Abstract.FileSystem.xml
62+
# pushing all *.nupkg files in directory
63+
- path: 'src\**\*.nupkg'

build.cmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:; set -eo pipefail
2+
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3+
:; ${SCRIPT_DIR}/build.sh "$@"
4+
:; exit $?
5+
6+
@ECHO OFF
7+
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*

build.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[CmdletBinding()]
2+
Param(
3+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
4+
[string[]]$BuildArguments
5+
)
6+
7+
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"
8+
9+
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
10+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
11+
12+
###########################################################################
13+
# CONFIGURATION
14+
###########################################################################
15+
16+
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
17+
$TempDirectory = "$PSScriptRoot\\.nuke\temp"
18+
19+
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
20+
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
21+
$DotNetChannel = "STS"
22+
23+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
24+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
25+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
26+
27+
###########################################################################
28+
# EXECUTION
29+
###########################################################################
30+
31+
function ExecSafe([scriptblock] $cmd) {
32+
& $cmd
33+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
34+
}
35+
36+
# If dotnet CLI is installed globally and it matches requested version, use for execution
37+
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
38+
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
39+
$env:DOTNET_EXE = (Get-Command "dotnet").Path
40+
}
41+
else {
42+
# Download install script
43+
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
44+
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
45+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
46+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
47+
48+
# If global.json exists, load expected version
49+
if (Test-Path $DotNetGlobalFile) {
50+
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
51+
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
52+
$DotNetVersion = $DotNetGlobal.sdk.version
53+
}
54+
}
55+
56+
# Install by channel or version
57+
$DotNetDirectory = "$TempDirectory\dotnet-win"
58+
if (!(Test-Path variable:DotNetVersion)) {
59+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
60+
} else {
61+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
62+
}
63+
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
64+
}
65+
66+
Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"
67+
68+
if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
69+
& $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null
70+
& $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null
71+
}
72+
73+
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
74+
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }

build.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
bash --version 2>&1 | head -n 1
4+
5+
set -eo pipefail
6+
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
7+
8+
###########################################################################
9+
# CONFIGURATION
10+
###########################################################################
11+
12+
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
13+
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
14+
15+
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
16+
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
17+
DOTNET_CHANNEL="STS"
18+
19+
export DOTNET_CLI_TELEMETRY_OPTOUT=1
20+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21+
export DOTNET_MULTILEVEL_LOOKUP=0
22+
23+
###########################################################################
24+
# EXECUTION
25+
###########################################################################
26+
27+
function FirstJsonValue {
28+
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
29+
}
30+
31+
# If dotnet CLI is installed globally and it matches requested version, use for execution
32+
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
33+
export DOTNET_EXE="$(command -v dotnet)"
34+
else
35+
# Download install script
36+
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
37+
mkdir -p "$TEMP_DIRECTORY"
38+
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
39+
chmod +x "$DOTNET_INSTALL_FILE"
40+
41+
# If global.json exists, load expected version
42+
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
43+
DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
44+
if [[ "$DOTNET_VERSION" == "" ]]; then
45+
unset DOTNET_VERSION
46+
fi
47+
fi
48+
49+
# Install by channel or version
50+
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
51+
if [[ -z ${DOTNET_VERSION+x} ]]; then
52+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
53+
else
54+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
55+
fi
56+
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
57+
fi
58+
59+
echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"
60+
61+
if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then
62+
"$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true
63+
"$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
64+
fi
65+
66+
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
67+
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"

0 commit comments

Comments
 (0)