-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.ps1
65 lines (57 loc) · 2.94 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
task . Clean, Build
task Build Compile, CreateManifest
task CreateManifest CopyPSD, UpdateModuleVersion
$Root = $env:BUILD_REPOSITORY_LOCALPATH
$srcPath = $env:BUILD_REPOSITORY_LOCALPATH
$ModuleName = [System.IO.Path]::GetFileNameWithoutExtension((Get-ChildItem -Path $srcPath -Filter "*.psd1").Name)
$srcModulePath = Join-Path -Path $srcPath -ChildPath "$($ModuleName).psd1"
[version]$srcModuleVersion = (Import-PowerShellDataFile -Path $srcModulePath).ModuleVersion
$NewModuleVersion = "{0}.{1}.{2}" -f $srcModuleVersion.Major, $srcModuleVersion.Minor, $env:BUILD_BUILDID
$OutPutFolder = Join-Path -Path $env:BUILD_REPOSITORY_LOCALPATH -ChildPath "Release"
$PsmPath = [System.IO.Path]::Combine($env:BUILD_REPOSITORY_LOCALPATH, "Release", $ModuleName, $NewModuleVersion, "$ModuleName.psm1")
$PsdPath = [System.IO.Path]::Combine($env:BUILD_REPOSITORY_LOCALPATH, "Release", $ModuleName, $NewModuleVersion, "$ModuleName.psd1")
$ExtensionPath = [System.IO.Path]::Combine($env:BUILD_REPOSITORY_LOCALPATH, "Release", $ModuleName, $NewModuleVersion)
$LicensePath = [System.IO.Path]::Combine($env:BUILD_REPOSITORY_LOCALPATH, "Release", $ModuleName, $NewModuleVersion, "LICENSE.txt")
$ReadMePath = [System.IO.Path]::Combine($env:BUILD_REPOSITORY_LOCALPATH, "Release", $ModuleName, $NewModuleVersion, "README.md")
task "Clean" {
if (-not(Test-Path $OutPutFolder))
{
$null = New-Item -ItemType Directory -Path $OutPutFolder
}
Remove-Item -Path "$($OutPutFolder)\*" -Force -Recurse
}
task Compile {
New-Item -ItemType Directory -Path $ExtensionPath -Force
Copy-Item -Path (Join-Path -Path $Root -ChildPath "$($ModuleName).psm1") -Destination $PsmPath -Force
Copy-Item -Path (Join-Path -Path $Root -ChildPath "$($ModuleName).Extension") -Destination $ExtensionPath -Recurse -Force
Copy-Item -Path (Join-Path -Path $Root -ChildPath "LICENSE") -Destination $LicensePath -Recurse -Force
Copy-Item -Path (Join-Path -Path $Root -ChildPath "README.md") -Destination $ReadMePath -Recurse -Force
}
task CopyPSD {
New-Item -Path (Split-Path $PsdPath) -ItemType Directory -ErrorAction 0
$copy = @{
Path = Join-Path -Path $srcPath -ChildPath "$($ModuleName).psd1"
Destination = $PsdPath
Force = $true
Verbose = $true
}
Copy-Item @copy
}
task UpdateModuleVersion {
$manifest = Import-PowerShellDataFile $PsdPath
[version]$version = $manifest.ModuleVersion
Write-Output "Old Version - $Version"
[version]$NewVersion = "{0}.{1}.{2}" -f $Version.Major, $Version.Minor, $env:BUILD_BUILDID
Write-Output "New Version - $NewVersion"
# Update the manifest file
try
{
Write-Output "Updating the Module Version to $NewVersion"
(Get-Content $PsdPath) -replace $version, $NewVersion | Set-Content $PsdPath -Encoding string
Write-Output "Updated the Module Version to $NewVersion"
}
catch
{
Write-Error "Failed to update the Module Version - $_"
}
}