-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreate-Distribution.ps1
119 lines (93 loc) · 3.29 KB
/
Create-Distribution.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Copyright (c) 2011-2015, Rolf Michelsen
# All rights reserved.
#
# Create a binary distribution package. Run from the solution root. It will
# build the release configuration of the solution and package specific files
# in a ZIP archive.
#
# Requires an external program "zip" to be available for creating zip files.
# I'm using the InfoZIP utilities from http://info-zip.org/.
<#
.SYNOPSIS
Create a DragonTools binary distribution package.
.DESCRIPTION
Create-Distribution creates a DragonTools binary distribution as a ZIP archive.
The command must be run from the DragonTools solution root, and the binary
distribution file will also be written to this directory.
The script will first build the release version of the DragonTools solution
and then package a set of predefined files in the distribution archive.
.EXAMPLE
Create-Distribution
Build the Dragon Tools solution and create a binary release package.
.NOTES
Create-Distribution depends on an external program for creating the ZIP archive.
It has been tested with the Info-ZIP distribution. See http://info-zip.org/.
#>
$msbuildProjectFile = "Dragon Tools.sln"
$packageFiles = @{
"License.txt" = "License.txt";
"Dist Readme.txt" = "README.txt";
"DragonDosTools\bin\Release\DragonDos.exe" = "DragonDos.exe";
"DragonDosTools\bin\Release\DragonTools.dll" = "DragonTools.dll";
"File2VDK\bin\Release\File2VDK.exe" = "File2VDK.exe"
}
<#
Test the script prerequisites.
#>
function Test-Prerequisites
{
if (!(Test-Path $msbuildProjectFile))
{
Write-Output("Cannot find " + $msbuildProjectFile + " in current directory.")
Write-Output("This scrips can only be run from the solution root.")
exit 1
}
}
<#
Build a release version of the solution.
#>
function Build-Release
{
msbuild $msbuildProjectFile /p:Configuration=Release /t:Rebuild /verbosity:quiet
}
<#
Return the distribution version identifier. For a tagged commit, this
corresponds to the tag name. For an untagget commit, this corresponds to the
commit identifier.
#>
function Get-VersionId
{
$description = git describe --dirty
if ($description -match "-dirty$") {
Write-Output("Repository is dirty, cannot create distribution.")
exit 1
}
if ($description -match "-([a-z0-9]{8})$") {
return "snapshot-" + $Matches[1]
}
return $description
}
<#
Create a ZIP archive containing the binary distribution. The $packageFiles
array lists the files to include in the distribution.
#>
function Package-Release($version)
{
$targetPackageName = "DragonTools-" + $version + ".zip"
$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
$out = New-Item -Path $tmpDir -ItemType Directory
Write-Output ("Using temporary directory " + $tmpDir)
foreach ($sourceFile in $packageFiles.keys)
{
$destinationFile = Join-Path $tmpDir ($packageFiles[$sourceFile])
Copy-Item $sourceFile -Destination $destinationFile
}
Write-Output ("Creating binary distribution package " + $targetPackageName)
remove-item $targetPackageName -ErrorAction SilentlyContinue
zip -j $targetPackageName ($tmpDir + "\*.*")
Remove-Item -Recurse $tmpDir
}
Test-Prerequisites
$version = Get-VersionId
Build-Release
Package-Release $version