forked from jasonmueller/Powerdeploy
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.ps1
More file actions
117 lines (98 loc) · 4.4 KB
/
build.ps1
File metadata and controls
117 lines (98 loc) · 4.4 KB
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
properties {
$buildFolder = Join-Path $PSScriptRoot '_build'
$packageFolder = Join-Path $PSScriptRoot '_package'
$sourceFolder = Join-Path $PSScriptRoot 'Source'
$acceptanceTestFolder = Join-Path $PSScriptRoot 'AcceptanceTests'
$chocolateyFolder = Join-Path $PSScriptRoot 'Package\Chocolatey'
$version = git describe --tags --always --dirty
$strippedVersion = &{$version -match '^v?(?<version>.+)$' | Out-Null; $matches.version}
$versionedZipName = "Powerdeploy-$strippedVersion.zip"
$changeset = 'n/a'
}
task default -depends Build
task Build -depends Clean, Test, Package
task Package -depends Version, Squirt, Unversion, AcceptanceTest, Zip, PackageChocolatey
task Zip {
Copy-Item $buildFolder $packageFolder\temp\Powerdeploy -Recurse
# Make the "obviously-named" package that can be dropped somewhere and
# will not conflict with other versions of the package.
exec { ."$sourceFolder\Tools\7za.exe" a -r "$packageFolder\$versionedZipName" "$packageFolder\temp\Powerdeploy" }
# Make the simply-named package that will be used for the GH release.
# TODO: We don't need this right now. We can just change the name when we upload to GitHub.
# New-Item $packageFolder\$version -ItemType Directory
# Copy-Item "$packageFolder\Powerdeploy-$strippedVersion.zip" "$packageFolder\$version"
# Rename-Item "$packageFolder\$version\PowerDeploy-$strippedVersion.zip" "Powerdeploy.zip"
}
task PackageChocolatey -depends Zip {
Copy-Item $chocolateyFolder $packageFolder\temp\Chocolatey -Recurse
$nuspec = "$packageFolder\temp\Chocolatey\powerdeploy.nuspec"
# Update the spec with our version.
$xml = [xml](Get-Content $nuspec -Raw -Encoding UTF8)
$xml.package.metadata.version = "$strippedVersion"
$xml.Save($nuspec)
# Update the installer to pull the binary from the right release in GitHub.
$contentFile = "$packageFolder\temp\Chocolatey\tools\chocolateyInstall.ps1"
cat $contentFile | write-host
(Get-Content "$contentFile" -Encoding UTF8) `
| % {$_ -replace "::version::", "$version" } `
| % {$_ -replace "::download_zip_name::", $versionedZipName} `
| Set-Content "$contentFile"
# cpack doesn't support -OutputDirectory on nuget pack, so we need to be in the directory
# we want our package in.
exec { cd "$packageFolder"; cpack "$packageFolder\temp\Chocolatey\powerdeploy.nuspec" }
}
task Publish -depends Package {
# Add the release for the current tag to GH (defer?).
# Push chocolotey package (defer?).
}
task Squirt {
Copy-Item $sourceFolder\* $buildFolder -Recurse -Exclude .git
Get-ChildItem $buildFolder *.Tests.ps1 -Recurse | Remove-Item
Get-ChildItem $buildFolder TestHelpers.ps1 | Remove-Item
Get-ChildItem $buildFolder Test.xml | Remove-Item
$version -match 'v(?<versionnum>[0-9]+\.[0-9]+(.[0-9]+)?)'
New-ModuleManifest `
-Author 'Jason Mueller' `
-CompanyName 'Suspended Gravity, LLC' `
-Path $buildFolder\Powerdeploy.psd1 `
-ModuleVersion $matches.versionnum `
-Guid 'cb196f97-00e0-416c-b201-a7b887b6d257' `
-RootModule Powerdeploy.psm1
}
task Test {
exec {."$PSScriptRoot\pester\bin\pester.bat" "$sourceFolder"}
}
task AcceptanceTest {
exec {."$PSScriptRoot\pester\bin\pester.bat" "$acceptanceTestFolder"}
}
task Version {
#$v = git describe --abbrev=0 --tags
#$changeset=(git log -1 $($v + '..') --pretty=format:%H)
if ($changeset -eq $null -or $changeset -eq '') {
throw 'No changeset. Files have been modified since commit.'
}
(Get-Content "$sourceFolder\PowerDeploy.psm1" -Encoding UTF8) `
| % {$_ -replace "\`$version\`$", "$version" } `
| % {$_ -replace "\`$sha\`$", "$changeset" } `
| Set-Content "$sourceFolder\PowerDeploy.psm1"
}
task Unversion {
#$v = git describe --abbrev=0 --tags
#$changeset=(git log -1 $($v + '..') --pretty=format:%H)
(Get-Content "$sourceFolder\PowerDeploy.psm1" -Encoding UTF8) `
| % {$_ -replace "$version", "`$version`$" } `
| % {$_ -replace "$changeset", "`$sha`$" } `
| Set-Content "$sourceFolder\PowerDeploy.psm1"
}
task Clean {
if (Test-Path $buildFolder) {
Remove-Item $buildFolder -Recurse -Force
}
if (Test-Path $packageFolder) {
Remove-Item $packageFolder -Recurse -Force
}
New-Item $buildFolder -ItemType Directory | Out-Null
}
task ? -Description "Helper to display task info" {
Write-Documentation
}