Skip to content

Commit d8ff2f1

Browse files
Raphael HoppeMastergammler
Raphael Hoppe
authored andcommitted
Cake Setup
1 parent 4141418 commit d8ff2f1

39 files changed

+909
-17
lines changed

Diff for: .github/workflows/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Cake Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
9+
branches:
10+
- develop
11+
- master
12+
13+
jobs:
14+
build:
15+
runs-on: windows-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
# this is required for the gitversion.tool to be able to work correctly
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Run Script
25+
shell: pwsh
26+
run: |
27+
.\build.ps1 --target=BuildAndTest

Diff for: Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Authors>queo/software/csharp</Authors>
55
<Company>queo GmbH</Company>
66
<Copyright>2023 queo GmbH</Copyright>
7-
<Product>Queo Commons ModelBuilder</Product>
7+
<Product>Queo Commons ModelBuilder Library</Product>
88
<AssemblyVersion>0.1.0</AssemblyVersion>
99
<FileVersion>$(AssemblyVersion)</FileVersion>
1010
<version>$(AssemblyVersion)-Beta</version>

Diff for: build.ps1

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env pwsh
2+
$DotNetInstallerUri = 'https://dot.net/v1/dotnet-install.ps1';
3+
$DotNetUnixInstallerUri = 'https://dot.net/v1/dotnet-install.sh'
4+
$DotNetChannel = 'LTS'
5+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
6+
7+
[string] $DotNetVersion = ''
8+
foreach ($line in Get-Content (Join-Path $PSScriptRoot 'build/build.config')) {
9+
if ($line -like 'DOTNET_VERSION=*') {
10+
$DotNetVersion = $line.SubString(15)
11+
}
12+
}
13+
14+
if ([string]::IsNullOrEmpty($DotNetVersion)) {
15+
'Failed to parse .NET Core SDK Version'
16+
exit 1
17+
}
18+
19+
$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";
20+
21+
# Make sure tools folder exists
22+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
23+
$ToolPath = Join-Path $PSScriptRoot "tools"
24+
if (!(Test-Path $ToolPath)) {
25+
Write-Verbose "Creating tools directory..."
26+
New-Item -Path $ToolPath -Type directory | out-null
27+
}
28+
29+
###########################################################################
30+
# INSTALL .NET CORE CLI
31+
###########################################################################
32+
33+
Function Remove-PathVariable([string]$VariableToRemove) {
34+
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
35+
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
36+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
37+
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
38+
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
39+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
40+
}
41+
42+
# Get .NET Core CLI path if installed.
43+
$FoundDotNetCliVersion = $null;
44+
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
45+
$FoundDotNetCliVersion = dotnet --version;
46+
}
47+
48+
Write-Verbose "Checking for .net..."
49+
if ($FoundDotNetCliVersion -ne $DotNetVersion) {
50+
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
51+
if (!(Test-Path $InstallPath)) {
52+
mkdir -Force $InstallPath | Out-Null;
53+
}
54+
Write-Verbose "Downloading .net..."
55+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
56+
& $InstallPath\dotnet-install.ps1 -Version $DotNetVersion -InstallDir $InstallPath;
57+
58+
Remove-PathVariable "$InstallPath"
59+
$env:PATH = "$InstallPath;$env:PATH"
60+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
61+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
62+
}
63+
64+
$dotnetVersionString = "DOTNET VERSION: " + (dotnet --version)
65+
Write-Host $dotnetVersionString -BackgroundColor DarkGreen -ForegroundColor Black -NoNewLine
66+
67+
###########################################################################
68+
# RUN BUILD SCRIPT
69+
###########################################################################
70+
71+
dotnet run --project build/Build/Build.csproj -- $args
72+
exit $LASTEXITCODE;

Diff for: build/Build.Common/Build.Common.csproj

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Cake.Common" Version="$(CakeVersion)" />
9+
<PackageReference Include="Cake.Core" Version="$(CakeVersion)" />
10+
<PackageReference Include="Cake.SemVer" Version="$(CakeVersion)" />
11+
</ItemGroup>
12+
13+
</Project>

Diff for: build/Build.Common/Enums/Branches.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Build.Common.Enums
2+
{
3+
public enum Branches
4+
{
5+
Main,
6+
Develop,
7+
Feature,
8+
Hotfix,
9+
Other
10+
}
11+
}

Diff for: build/Build.Common/Extensions/StringExtensions.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
using Cake.Core.IO;
4+
5+
namespace Build.Common.Extensions
6+
{
7+
public static class StringExtensions
8+
{
9+
public static DirectoryPath AsDirectoryPath(this string pathAsString) => new DirectoryPath(pathAsString);
10+
11+
public static FilePath AsFilePath(this string pathAsString) => new FilePath(pathAsString);
12+
13+
public static int AsInt(this string intValue) => int.Parse(intValue);
14+
15+
public static Uri AsUri(this string uriValue) => new Uri(uriValue);
16+
}
17+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Semver;
2+
3+
namespace Build.Common.Interfaces
4+
{
5+
public interface IWithArtifactVersion
6+
{
7+
SemVersion ArtifactVersion { get; set; }
8+
}
9+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
using Build.Common.Enums;
4+
5+
using Semver;
6+
7+
namespace Build.Common.Services
8+
{
9+
public interface IArtifactVersionService
10+
{
11+
SemVersion GetArtifactVersion(
12+
bool isLocalBuild, Branches branch, string branchName, string buildNumber, Action<string> logInformation,
13+
string assemblyInfo);
14+
}
15+
}

Diff for: build/Build.Common/Services/IBranchService.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Build.Common.Enums;
2+
3+
namespace Build.Common.Services
4+
{
5+
public interface IBranchService
6+
{
7+
string Clean(string branchName);
8+
Branches GetBranch(string branchName);
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
3+
using Build.Common.Enums;
4+
using Build.Common.Extensions;
5+
6+
using Semver;
7+
8+
namespace Build.Common.Services.Impl
9+
{
10+
public class ArtifactVersionService : IArtifactVersionService
11+
{
12+
private readonly IBranchService _branchService;
13+
14+
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
15+
public ArtifactVersionService(IBranchService branchService) => _branchService = branchService;
16+
17+
public SemVersion GetArtifactVersion(
18+
bool isLocalBuild, Branches branch, string branchName,
19+
string buildNumber, Action<string> logInformation, string assemblyInfo)
20+
{
21+
string[] versionParts = assemblyInfo.Split('.');
22+
string tag;
23+
string build;
24+
if (!isLocalBuild)
25+
{
26+
switch (branch)
27+
{
28+
case Branches.Main:
29+
logInformation.Invoke("Remote Master Branch - es werden keine Tags an die Version angefügt.");
30+
tag = string.Empty;
31+
build = string.Empty;
32+
break;
33+
default:
34+
logInformation.Invoke("Remote Branch - es wird der Branchname + Buildnummer angefügt.");
35+
tag = _branchService.Clean(branchName);
36+
build = buildNumber;
37+
break;
38+
}
39+
}
40+
else
41+
{
42+
logInformation.Invoke("Lokaler Branch - es werden Datum + Uhrzeit für lokalen Build angefügt.");
43+
tag = $"local-{_branchService.Clean(branchName)}";
44+
build = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
45+
}
46+
47+
return new SemVersion(versionParts[0].AsInt(), versionParts[1].AsInt(), versionParts[2].AsInt(), tag,
48+
build);
49+
}
50+
}
51+
}

Diff for: build/Build.Common/Services/Impl/BranchService.cs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Build.Common.Enums;
2+
3+
namespace Build.Common.Services.Impl
4+
{
5+
public class BranchService : IBranchService
6+
{
7+
public string Clean(string branchName) =>
8+
branchName.ToLower()
9+
.Replace("/", "-")
10+
.Replace("_", "-")
11+
.Replace("#", "")
12+
.Replace("ä", "ae")
13+
.Replace("ö", "oe")
14+
.Replace("ü", "ue");
15+
16+
public Branches GetBranch(string branchName)
17+
{
18+
if (branchName == "master" || branchName == "main")
19+
{
20+
return Branches.Main;
21+
}
22+
23+
if (branchName == "develop" || branchName == "dev")
24+
{
25+
return Branches.Develop;
26+
}
27+
28+
if (branchName.StartsWith("feature/"))
29+
{
30+
return Branches.Feature;
31+
}
32+
33+
if (branchName.StartsWith("hotfix") || branchName.StartsWith("fix"))
34+
{
35+
return Branches.Hotfix;
36+
}
37+
38+
return Branches.Other;
39+
}
40+
}
41+
}

Diff for: build/Build.sln

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30503.244
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "Build\Build.csproj", "{500D27E4-FE13-4BD0-B744-4C8B9A09FA4D}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build.Common", "Build.Common\Build.Common.csproj", "{7CF65C7F-AF41-4FCC-957F-F1EEE2441256}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3089C840-CAFD-417F-98C8-BF892A714B51}"
11+
ProjectSection(SolutionItems) = preProject
12+
..\azure-pipelines.yml = ..\azure-pipelines.yml
13+
nuget.config.template = nuget.config.template
14+
EndProjectSection
15+
EndProject
16+
Global
17+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18+
Debug|Any CPU = Debug|Any CPU
19+
Release|Any CPU = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{500D27E4-FE13-4BD0-B744-4C8B9A09FA4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{500D27E4-FE13-4BD0-B744-4C8B9A09FA4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{500D27E4-FE13-4BD0-B744-4C8B9A09FA4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{500D27E4-FE13-4BD0-B744-4C8B9A09FA4D}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{7CF65C7F-AF41-4FCC-957F-F1EEE2441256}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{7CF65C7F-AF41-4FCC-957F-F1EEE2441256}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{7CF65C7F-AF41-4FCC-957F-F1EEE2441256}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{7CF65C7F-AF41-4FCC-957F-F1EEE2441256}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {A2AEE95F-D625-4FE6-B2CD-06B544B53637}
36+
EndGlobalSection
37+
EndGlobal

Diff for: build/Build/Build.csproj

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<PackAsTool>true</PackAsTool>
7+
8+
<!-- Make sure start same folder .NET Core CLI and Visual Studio -->
9+
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Cake.Frosting" Version="$(CakeVersion)" />
14+
<PackageReference Include="Cake.NuGet" Version="$(CakeVersion)" />
15+
<PackageReference Include="WinSCP" Version="5.19.5" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\Build.Common\Build.Common.csproj" />
20+
</ItemGroup>
21+
22+
</Project>

Diff for: build/Build/Build.csproj.DotSettings

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=deploymenttasks/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=flow/@EntryIndexedValue">True</s:Boolean>
4+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=targets/@EntryIndexedValue">True</s:Boolean>
5+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 commit comments

Comments
 (0)