Public/Set-BuildEnvironment.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
function Set-BuildEnvironment {
    <#
    .SYNOPSIS
        Normalize build system and project details into environment variables
 
    .FUNCTIONALITY
        CI/CD
 
    .DESCRIPTION
        Normalize build system and project details into environment variables
 
        Creates the following environment variables:
            $ENV:BHProjectPath via Get-BuildVariables
            $ENV:BHBranchName via Get-BuildVariables
            $ENV:BHCommitMessage via Get-BuildVariables
            $ENV:BHBuildNumber via Get-BuildVariables
            $ENV:BHProjectName via Get-ProjectName
            $ENV:BHPSModuleManifest via Get-PSModuleManifest
            $ENV:BHPSModulePath via Split-Path on BHPSModuleManifest
 
    .PARAMETER Path
        Path to project root. Defaults to the current working path
 
    .NOTES
        We assume you are in the project root, for several of the fallback options
 
    .EXAMPLE
        Set-BuildEnvironment
 
        Get-Item ENV:BH*
 
    .LINK
        https://github.com/RamblingCookieMonster/BuildHelpers
 
    .LINK
        Get-BuildVariables
 
    .LINK
        Get-ProjectName
 
    .LINK
        about_BuildHelpers
    #>

    [cmdletbinding()]
    param(
        $Path = $PWD.Path
    )

    $BuildVars = Get-BuildVariables -Path $Path
    $ProjectName = Get-ProjectName -Path $Path
    $ManifestPath = Get-PSModuleManifest -Path $Path

    $ENV:BHBuildSystem = $BuildVars.BuildSystem
    $ENV:BHProjectPath = $BuildVars.ProjectPath
    $ENV:BHBranchName = $BuildVars.BranchName
    $ENV:BHCommitMessage = $BuildVars.CommitMessage
    $ENV:BHBuildNumber = $BuildVars.BuildNumber
    $ENV:BHProjectName = $ProjectName
    $ENV:BHPSModuleManifest = $ManifestPath
    if($ManifestPath)
    {
        $ENV:BHPSModulePath = Split-Path -Path $ManifestPath -Parent
    }

}