Skip to content

Commit

Permalink
Added build and release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Duco committed May 7, 2018
1 parent 3ebbb3a commit 2919fbd
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 47 deletions.
9 changes: 9 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,9 @@
Copyright 2018 Duco Winterwerp

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 changes: 31 additions & 0 deletions appveyor.yml
@@ -0,0 +1,31 @@
before_build:
- cmd: dotnet --version
- ps: Get-ChildItem -Path "C:\Program Files\dotnet\sdk"
- ps: scripts\patch_versions.ps1

environment:
access_token:
secure: Zcoti9GsS4Y1t12qVcWhfDXMJLW8QLt4SdeQi8VKUFBtd/gVyWsZlLXDOHLP8i5U

branches:
only:
- master
- dev

build_script:
- ps: scripts\build.ps1

test: off

artifacts:
- path: src\Placeholder\bin\release\netcoreapp2.0\win10-x64\publish\placeholder_*.exe
name: armyknife-windows
type: zip

deploy:
release: $(versionString)
provider: GitHub
auth_token: $(access_token)
draft: true
on:
branch: master
50 changes: 50 additions & 0 deletions scripts/build.ps1
@@ -0,0 +1,50 @@
$ErrorActionPreference = 'Stop'

$rootFolder = Join-Path -Path $PSScriptRoot ".."
$srcFolder = Join-Path -Path $rootFolder "src"
$mainProjectFile = Join-Path $srcFolder "Placeholder\Placeholder.csproj"
$solutionFile = Join-Path -Path $srcFolder "Placeholder.sln"

$nsisPath = "C:\Program Files (x86)\NSIS\Bin"

. "$PSScriptRoot\functions.ps1"

# Updating path variable
Write-Host "Updating path variable"
$env:PATH = "$env:PATH;$nsisPath"

# Remove all bin and obj folders
Write-Host "Cleaning the solution"
Get-ChildItem $srcFolder -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

# Perform a debug build
& dotnet build $solutionFile /p:DebugType=Full

# Run unit tests
$unitTestProjects = Get-ChildItem -Path $srcFolder -Filter *.Tests.csproj -Recurse
Write-Host "Running unit tests"
foreach($unitTest in $unitTestProjects)
{
Write-Host $unitTest

& dotnet restore $unitTest.FullName
Assert-Cmd-Ok

& dotnet test $unitTest.FullName
Assert-Cmd-Ok
}

# Release package build
Write-Host "Building a release package"

& dotnet restore $mainProjectFile
Assert-Cmd-Ok

# Reading version number
Write-Host "Reading version from $mainProjectFile"
[xml]$csproj = Get-Content $mainProjectFile
$propertyGroupNode = $csproj.SelectSingleNode("/Project/PropertyGroup[1]")
$version = [version]$propertyGroupNode.Version
Write-Host "Found version $version"

. "$PSScriptRoot\build_windows.ps1" -srcFolder $srcFolder
30 changes: 30 additions & 0 deletions scripts/build_windows.ps1
@@ -0,0 +1,30 @@
Param(
[Parameter(Mandatory = $True)]
[string]$srcFolder
)

$ErrorActionPreference = 'Stop'

. "$PSScriptRoot\functions.ps1"

$nsiPath = Join-Path $PSScriptRoot "placeholder.nsi"
$binDir = Join-Path $srcFolder "Placeholder\bin\release\netcoreapp2.0\win10-x64\publish"
$installScriptsPath = Join-Path -Path $PSScriptRoot "installscripts\windows"

# Create Windows package
Write-Host "Packing up for Windows" -ForegroundColor Green
& dotnet publish $mainProjectFile --configuration=release --runtime=win10-x64
Assert-Cmd-Ok

# Moving install scripts for Windows
Copy-Item (Join-Path $installScriptsPath "**") $binDir -Recurse

# Making installer
$env:VersionMajor = $version.Major
$env:VersionMinor = $version.Minor
$env:VersionBuild = $version.Build
$env:BuildOutputBinDirectory = $binDir
$env:BuildOutputDirectory = $binDir
Write-Host "Building installer $nsiPath"
& makensis $nsiPath
Assert-Cmd-Ok
8 changes: 8 additions & 0 deletions scripts/functions.ps1
@@ -0,0 +1,8 @@
function Assert-Cmd-Ok
{
if($LASTEXITCODE -ne 0)
{
Write-Error "Build not succeeded... See errors"
Exit -1
}
}
14 changes: 14 additions & 0 deletions scripts/installscripts/windows/add_path_var.ps1
@@ -0,0 +1,14 @@
# Make sure the install folder is added to the system path variable after install.
Param(
[Parameter(Mandatory=$True)]
[string]$installFolder
)

$environmentLocation = "hklm:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$environment = Get-ItemProperty $environmentLocation
$pathVar = $environment.Path
if(!($pathVar -like "*$installFolder*"))
{
$pathVar = "$pathVar;$installFolder"
New-ItemProperty -Path $environmentLocation -Name "Path" -Value $pathVar -Force
}
11 changes: 11 additions & 0 deletions scripts/installscripts/windows/remove_path_var.ps1
@@ -0,0 +1,11 @@
# Make sure the install folder is removed from the path variable after deinstallation.
Param(
[Parameter(Mandatory=$True)]
[string]$installFolder
)

$environmentLocation = "hklm:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$environment = Get-ItemProperty $environmentLocation
$pathVar = $environment.Path
$pathVar = $pathVar.Replace(";$installFolder", "")
New-ItemProperty -Path $environmentLocation -Name "Path" -Value $pathVar -Force
4 changes: 4 additions & 0 deletions scripts/local_build.bat
@@ -0,0 +1,4 @@
SET APPVEYOR_BUILD_NUMBER=0
PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& %~dp0patch_versions.ps1"
PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& %~dp0build.ps1"
pause
32 changes: 32 additions & 0 deletions scripts/patch_versions.ps1
@@ -0,0 +1,32 @@
$ErrorActionPreference = 'Stop'

. "$PSScriptRoot\functions.ps1"

$rootFolder = Join-Path -Path $PSScriptRoot ".."
$srcFolder = Join-Path -Path $rootFolder "src"
$csprojPath = Join-Path -Path $srcFolder "Placeholder\Placeholder.csproj"

Write-Host "Reading file '$csprojPath'"
[xml]$mainCsproj = Get-Content $csprojPath
$propertyGroupNode = $mainCsproj.SelectSingleNode("/Project/PropertyGroup[1]")
$version = [version]$propertyGroupNode.Version

Write-Host "Current version number: '$version'"

$versionString = "{0}.{1}.{2}.{3}" -f $version.Major, $version.Minor, $version.Build, $env:APPVEYOR_BUILD_NUMBER

Write-Host "New version number: '$versionString'"

$env:versionString = $versionString

$csprojFiles = Get-ChildItem -Path $srcFolder -Filter *.csproj -Recurse
foreach($csprojFile in $csprojFiles)
{
Write-Host "Parsing .csproj file $($csprojFile.FullName)"
[xml]$csprojContents = Get-Content $csprojFile.FullName
$propertyGroupNode = $csprojContents.SelectSingleNode("/Project/PropertyGroup[1]")
$propertyGroupNode.Version = $versionString
$propertyGroupNode.AssemblyVersion = $versionString
$propertyGroupNode.FileVersion = $versionString
$csprojContents.Save($csprojFile.FullName)
}
93 changes: 93 additions & 0 deletions scripts/placeholder.nsi
@@ -0,0 +1,93 @@
!include "FileFunc.nsh"

!define APPNAME "Placeholder"
!define COMPANYNAME "Ducode"
!define DESCRIPTION "A very flexible cross platform HTTP stub application."
!define VERSIONMAJOR "$%VersionMajor%"
!define VERSIONMINOR "$%VersionMinor%"
!define VERSIONBUILD "$%VersionBuild%"
!define BINDIRECTORY "$%BuildOutputBinDirectory%"
!define HELPURL "https://ducode.org"
!define UPDATEURL "https://ducode.org"
!define ABOUTURL "https://ducode.org"

RequestExecutionLevel admin

InstallDir "$PROGRAMFILES\${COMPANYNAME}\${APPNAME}"

LicenseData "..\LICENSE.txt"
Name "${COMPANYNAME} - ${APPNAME}"
outFile "$%BuildOutputDirectory%\placeholder_install.exe"

!include LogicLib.nsh

page license
page directory
Page instfiles

!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin"
messageBox mb_iconstop "Administrator rights required!"
setErrorLevel 740
quit
${EndIf}
!macroend

function .onInit
setShellVarContext all
!insertmacro VerifyUserIsAdmin
functionEnd

section "install"
setOutPath $INSTDIR
file /r "${BINDIRECTORY}\*"
writeUninstaller "$INSTDIR\uninstall.exe"

createDirectory "$SMPROGRAMS\${COMPANYNAME}"
createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\Placeholder.exe"
createShortCut "$SMPROGRAMS\${COMPANYNAME}\Uninstall ${APPNAME}.lnk" "$INSTDIR\uninstall.exe"

# Calculate installed size
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0

WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$INSTDIR\Placeholder.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "${COMPANYNAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "${HELPURL}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "${UPDATEURL}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "${ABOUTURL}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMinor" ${VERSIONMINOR}
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoRepair" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" $0

ExecWait 'powershell.exe -NoProfile -ExecutionPolicy Unrestricted -Command "& \"$INSTDIR\add_path_var.ps1\"" -installFolder \"$INSTDIR\"'
sectionEnd

function un.onInit
SetShellVarContext all

MessageBox MB_YESNO "Permanantly remove ${APPNAME}?" /SD IDYES IDYES next IDNO abort
abort:
Abort
next:
!insertmacro VerifyUserIsAdmin
functionEnd

section "uninstall"
ExecWait 'powershell.exe -NoProfile -ExecutionPolicy Unrestricted -Command "& \"$INSTDIR\remove_path_var.ps1\"" -installFolder \"$INSTDIR\"'

rmDir /r "$SMPROGRAMS\${COMPANYNAME}"

rmDir /r $INSTDIR

DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}"
sectionEnd
7 changes: 4 additions & 3 deletions src/Placeholder.Exceptions/Placeholder.Exceptions.csproj
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup> </PropertyGroup>

</Project>
</Project>
@@ -1,30 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<Version>1.0.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup> </PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors /> <WarningsAsErrors />
</PropertyGroup> </PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors /> <WarningsAsErrors />
</PropertyGroup> </PropertyGroup>

<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Moq" Version="4.8.2" /> <PackageReference Include="Moq" Version="4.8.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.1" /> <PackageReference Include="MSTest.TestAdapter" Version="1.2.1" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.1" /> <PackageReference Include="MSTest.TestFramework" Version="1.2.1" />
</ItemGroup> </ItemGroup>

<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Placeholder.Implementation\Placeholder.Implementation.csproj" /> <ProjectReference Include="..\Placeholder.Implementation\Placeholder.Implementation.csproj" />
</ItemGroup> </ItemGroup>

</Project>
</Project>
11 changes: 4 additions & 7 deletions src/Placeholder.Implementation/Placeholder.Implementation.csproj
@@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup> </PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors /> <WarningsAsErrors />
</PropertyGroup> </PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors /> <WarningsAsErrors />
</PropertyGroup> </PropertyGroup>

<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.2" /> <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.2" /> <PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.2" />
Expand All @@ -22,11 +21,9 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup> </ItemGroup>

<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Placeholder.Exceptions\Placeholder.Exceptions.csproj" /> <ProjectReference Include="..\Placeholder.Exceptions\Placeholder.Exceptions.csproj" />
<ProjectReference Include="..\Placeholder.Models\Placeholder.Models.csproj" /> <ProjectReference Include="..\Placeholder.Models\Placeholder.Models.csproj" />
<ProjectReference Include="..\Placeholder.Utilities\Placeholder.Utilities.csproj" /> <ProjectReference Include="..\Placeholder.Utilities\Placeholder.Utilities.csproj" />
</ItemGroup> </ItemGroup>

</Project>
</Project>

0 comments on commit 2919fbd

Please sign in to comment.