-
Notifications
You must be signed in to change notification settings - Fork 23
/
build-release-only.ps1
94 lines (82 loc) · 3.62 KB
/
build-release-only.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
[cmdletbinding()]
param(
[ValidateSet('Debug','Release')]
[string]
$Configuration = 'Release'
)
if ($PSEdition -eq 'Desktop') {
throw "Build process must be run using PowerShell 7"
}
if ($MyInvocation.ScriptName -notlike '*Invoke-Build.ps1') {
$InvokeBuildVersion = '5.8.4'
$ErrorActionPreference = 'Stop'
try {
Import-Module InvokeBuild -RequiredVersion $InvokeBuildVersion
} catch {
Install-Module InvokeBuild -RequiredVersion $InvokeBuildVersion -Scope AllUsers -Force
Import-Module InvokeBuild -RequiredVersion $InvokeBuildVersion
}
Invoke-Build -Task $Tasks -File $MyInvocation.MyCommand.Path @PSBoundParameters
return
}
$moduleName = 'Thycotic.SecretServer'
$moduleManifest = [IO.Path]::Combine($PSScriptRoot,'src',"$ModuleName.psd1")
$libraryFolderName = 'Thycotic.SecretServer'
$staging = [IO.Path]::Combine($PSScriptRoot, 'release_dir')
$libraryBuildScript = [IO.Path]::Combine($PSScriptRoot, 'build.library.ps1')
$zipFilePath = Join-Path $staging "$moduleName.zip"
$moduleTempPath = Join-Path $staging $moduleName
task UpdateManifest -Before stage, build {
$manifestData = Import-PowerShellDataFile $moduleManifest
$functionsToExportList = Get-ChildItem .\src\functions -File -Recurse | Select-Object -ExpandProperty BaseName | Sort-Object
$updateManifestParams = @{
Path = $moduleManifest
CompatiblePSEditions = $manifestData.CompatiblePSEditions
RootModule = $manifestData.RootModule
Guid = $manifestData.Guid
TypesToProcess = $manifestData.TypesToProcess
CmdletsToExport = $manifestData.CmdletsToExport
PowerShellVersion = $manifestData.PowerShellVersion
CompanyName = $manifestData.CompanyName
ModuleVersion = $manifestData.ModuleVersion
FunctionsToExport = $functionsToExportList
Author = $manifestData.Author
Description = $manifestData.Description
FormatsToProcess = $manifestData.FormatsToProcess
Copyright = $manifestData.Copyright
Tags = $manifestData.PrivateData.PSData.Tags
IconUri = $manifestData.PrivateData.PSData.IconUri
ProjectUri = $manifestData.PrivateData.PSData.ProjectUri
LicenseUri = $manifestData.PrivateData.PSData.LicenseUri
ReleaseNotes = $manifestData.PrivateData.PSData.ReleaseNotes
}
Update-ModuleManifest @updateManifestParams
}
task library -Before stage, build {
Invoke-Build -File $libraryBuildScript
}
task stage -Before build {
if ($Configuration -ne 'Debug') {
if (Test-Path $staging) {
Remove-Item -Recurse -Force $staging
New-Item -ItemType Directory -Force -Path $staging >$null
} else {
New-Item -ItemType Directory -Force -Path $staging >$null
}
$script:imported = Import-Module $moduleManifest -Force -PassThru
Write-Output "Staging directory: $moduleTempPath"
$imported | Split-Path | Copy-Item -Destination $moduleTempPath -Recurse
# remove project files
Remove-Item -Recurse "$moduleTempPath\$libraryFolderName" -Force
$script:moduleData = Import-PowerShellDataFile $moduleManifest
} else {
Write-Output "Debug mode, skipping staging"
}
}
task build {
Write-Output "Build started: $(Get-Date -Format FileDateTime)"
if ($Configuration -ne 'Debug') {
Compress-Archive "$staging\$moduleName\*" -DestinationPath $zipFilePath -CompressionLevel Fastest -Force
}
}
task . build