Skip to content
Permalink
Browse files

Added build and release scripts

  • Loading branch information...
Duco
Duco committed May 7, 2018
1 parent 3ebbb3a commit 2919fbd2b6f158398b1207be6d6b14327f01fa16
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,8 @@
function Assert-Cmd-Ok
{
if($LASTEXITCODE -ne 0)
{
Write-Error "Build not succeeded... See errors"
Exit -1
}
}
@@ -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
}
@@ -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
@@ -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
@@ -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)
}
@@ -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
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

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

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

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

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

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

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

</Project>
</Project>
@@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

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

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

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

</Project>
</Project>
Oops, something went wrong.

0 comments on commit 2919fbd

Please sign in to comment.
You can’t perform that action at this time.