-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.ps1
115 lines (106 loc) · 4.5 KB
/
build.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
<#
.SYNOPSIS
Used to start the build of a PowerShell Module
.DESCRIPTION
This script will install dependencies using PSDepend module and start the build tasks using InvokeBuild module
.NOTES
Change History
-1.0 | 2019/06/17 | Francois-Xavier Cat
Initial version
TODO
-Check if we can fetch the information in the "Edit" part with BuildHelpers (see below)
-Conditional deploy "task deploy -if ($BHCommitMessage -match '!deploy')"
-publish release to github
-Make this file appraoch easily clonable
-Improve agnostic approach so it can work on any CI
-Minimalize files present in the root, possibly move build.ps1 ?
-Make the Build script flexible so we can call different tasks at different stages (build, deploy, tests..)
-Speed up dependencies installation
-Add more verbose/output messages
-Use invokebuild header ?
#>
[CmdletBinding()]
Param(
#[string[]]$tasks,
[string]$GalleryRepository,
[pscredential]$GalleryCredential,
[string]$GalleryProxy,
[string[]]$tasks, # @('build','test','deploy')
[switch]$InstallDependencies
)
try{
################
# EDIT THIS PART
$moduleName = "SpaceX" # get from source control or module ?
$author = 'Francois-Xavier Cat' # fetch from source or module
$description = 'SpaceX is a module wrapped around the spacex API (github.com/r-spacex/SpaceX-API)' # fetch from module ?
$companyName = 'lazywinadmin.com' # fetch from module ?
$projectUri = "https://github.com/lazywinadmin/$moduleName" # get from module of from source control, env var
$licenseUri = "https://github.com/lazywinadmin/$moduleName/blob/master/LICENSE.md"
$tags = @('PSEdition_Core','PSEdition_Desktop','SpaceX', 'Falcon', 'Space', 'Rocket', 'ElonMusk')
################
#$rootpath = Split-Path -path $PSScriptRoot -parent
$rootpath = $PSScriptRoot
$buildOutputPath = "$rootpath\buildoutput"
$buildPath = "$rootpath\build"
$srcPath = "$rootpath\src"
$testPath = Join-Path -Path $rootpath -ChildPath "tests"
$modulePath = "$buildoutputPath\$moduleName"
$dependenciesPath = "$rootpath\dependencies" # folder to store modules
$testResult = "Test-Results.xml"
$env:moduleName = $moduleName
$env:modulePath = $modulePath
$requirementsFilePath = "$buildPath\requirements.psd1" # contains dependencies
$buildTasksFilePath = "$buildPath\tasks.build.ps1" # contains tasks to execute
if($InstallDependencies)
{
# Setup PowerShell Gallery as PSrepository & Install PSDepend module
if (-not(Get-PackageProvider -Name NuGet -ForceBootstrap)) {
$providerBootstrapParams = @{
Name = 'nuget'
force = $true
ForceBootstrap = $true
}
if($PSBoundParameters['verbose']) {$providerBootstrapParams.add('verbose',$verbose)}
if($GalleryProxy) { $providerBootstrapParams.Add('Proxy',$GalleryProxy) }
$null = Install-PackageProvider @providerBootstrapParams
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
}
if (-not(Get-Module -Listavailable -Name PSDepend)) {
Write-verbose "BootStrapping PSDepend"
"Parameter $buildOutputPath"| Write-verbose
$InstallPSDependParams = @{
Name = 'PSDepend'
AllowClobber = $true
Confirm = $false
Force = $true
Scope = 'CurrentUser'
}
if($PSBoundParameters['verbose']) { $InstallPSDependParams.add('verbose',$verbose)}
if ($GalleryRepository) { $InstallPSDependParams.Add('Repository',$GalleryRepository) }
if ($GalleryProxy) { $InstallPSDependParams.Add('Proxy',$GalleryProxy) }
if ($GalleryCredential) { $InstallPSDependParams.Add('ProxyCredential',$GalleryCredential) }
Install-Module @InstallPSDependParams
}
# Install module dependencies with PSDepend
$PSDependParams = @{
Force = $true
Path = $requirementsFilePath
}
if($PSBoundParameters['verbose']) { $PSDependParams.add('verbose',$verbose)}
Invoke-PSDepend @PSDependParams -Target $dependenciesPath
Write-Verbose -Message "Project Bootstrapped"
}
# Start build using InvokeBuild module
Write-Verbose -Message "Start Build"
Invoke-Build -Result 'Result' -File $buildTasksFilePath -Task $tasks
# Return error to CI
if ($Result.Error)
{
$Error[-1].ScriptStackTrace | Out-String
exit 1
}
exit 0
}catch{
throw $_
}