-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpowershell.ps1
More file actions
192 lines (170 loc) · 5.8 KB
/
powershell.ps1
File metadata and controls
192 lines (170 loc) · 5.8 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#
# PSDocs
#
# See details at: https://github.com/Microsoft/ps-docs
[CmdletBinding()]
param (
# The working directory PSDocs is run from.
[Parameter(Mandatory = $False)]
[String]$Path = $Env:INPUT_PATH,
# The path PSDocs will look for files to input files.
[Parameter(Mandatory = $False)]
[String]$InputPath = $Env:INPUT_INPUTPATH,
# An path containing definitions to use for generating documentation.
[Parameter(Mandatory = $False)]
[String]$Source = $Env:INPUT_SOURCE,
# A comma separated list of modules to use containing document definitions.
[Parameter(Mandatory = $False)]
[String]$Modules = $Env:INPUT_MODULES,
[Parameter(Mandatory = $False)]
[String]$Conventions = $ENV:INPUT_CONVENTIONS,
# The path to write documentation to.
[Parameter(Mandatory = $False)]
[String]$OutputPath = $Env:INPUT_OUTPUTPATH,
# Determine if a pre-release module version is installed.
[Parameter(Mandatory = $False)]
[String]$PreRelease = $Env:INPUT_PRERELEASE
)
$workspacePath = $Env:GITHUB_WORKSPACE;
$ProgressPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue;
if ($Env:SYSTEM_DEBUG -eq 'true') {
$VerbosePreference = [System.Management.Automation.ActionPreference]::Continue;
}
# Set workspace
if ([String]::IsNullOrEmpty($workspacePath)) {
$workspacePath = $PWD;
}
# Set Path
if ([String]::IsNullOrEmpty($Path)) {
$Path = $workspacePath;
}
else {
$Path = Join-Path -Path $workspacePath -ChildPath $Path;
}
# Set InputPath
if ([String]::IsNullOrEmpty($InputPath)) {
$InputPath = $Path;
}
else {
$InputPath = Join-Path -Path $Path -ChildPath $InputPath;
}
# Set Source
if ([String]::IsNullOrEmpty($Source)) {
$Source = Join-Path -Path $Path -ChildPath '.ps-docs/';
}
else {
$Source = Join-Path -Path $Path -ChildPath $Source;
}
function WriteDebug {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $True)]
[String]$Message
)
process {
if ($Env:SYSTEM_DEBUG -eq 'true' -or $Env:ACTIONS_STEP_DEBUG -eq 'true') {
Write-Host "::debug::$Message";
}
}
}
# Setup paths for importing modules
$modulesPath = '/ps_modules/';
if ((Get-Variable -Name IsMacOS -ErrorAction Ignore) -or (Get-Variable -Name IsLinux -ErrorAction Ignore)) {
$moduleSearchPaths = $Env:PSModulePath.Split(':', [System.StringSplitOptions]::RemoveEmptyEntries);
if ($modulesPath -notin $moduleSearchPaths) {
$Env:PSModulePath += [String]::Concat($Env:PSModulePath, ':', $modulesPath);
}
}
else {
$moduleSearchPaths = $Env:PSModulePath.Split(';', [System.StringSplitOptions]::RemoveEmptyEntries);
if ($modulesPath -notin $moduleSearchPaths) {
$Env:PSModulePath += [String]::Concat($Env:PSModulePath, ';', $modulesPath);
}
}
$moduleNames = @()
if (![String]::IsNullOrEmpty($Modules)) {
$moduleNames = $Modules.Split(',', [System.StringSplitOptions]::RemoveEmptyEntries);
}
$moduleParams = @{
Scope = 'CurrentUser'
Force = $True
}
if ($PreRelease -eq 'true') {
$moduleParams['AllowPrerelease'] = $True;
}
try {
# Install each module if not already installed
foreach ($m in $moduleNames) {
$m = $m.Trim();
Write-Host "> Checking module: $m";
if ($Null -eq (Get-InstalledModule -Name $m -ErrorAction Ignore)) {
Write-Host ' - Installing module';
$Null = Install-Module -Name $m @moduleParams -AllowClobber -ErrorAction Stop;
}
else {
Write-Host ' - Already installed';
}
# Check
if ($Null -eq (Get-InstalledModule -Name $m)) {
Write-Host "::error::Failed to install $m.";
}
else {
Write-Host " - Using version: $((Get-InstalledModule -Name $m).Version)";
}
}
}
catch {
Write-Host "::error::An error occured installing a dependency module.";
$Host.SetShouldExit(1);
}
$Null = Import-Module PSDocs -ErrorAction Stop;
$version = (Get-InstalledModule PSDocs).Version;
Write-Host '';
Write-Host "[info] Using Version: $version";
Write-Host "[info] Using Action: $Env:GITHUB_ACTION";
Write-Host "[info] Using PWD: $PWD";
Write-Host "[info] Using Path: $Path";
Write-Host "[info] Using Source: $Source";
Write-Host "[info] Using Conventions: $Conventions";
Write-Host "[info] Using InputPath: $InputPath";
Write-Host "[info] Using OutputPath: $OutputPath";
try {
Push-Location -Path $Path;
$invokeParams = @{
Path = $Source
ErrorAction = 'Stop'
}
WriteDebug "Preparing command-line:";
WriteDebug ([String]::Concat('-Path ''', $Source, ''''));
if (![String]::IsNullOrEmpty($Modules)) {
$moduleNames = $Modules.Split(',', [System.StringSplitOptions]::RemoveEmptyEntries);
$invokeParams['Module'] = $moduleNames;
WriteDebug ([String]::Concat('-Module ', [String]::Join(', ', $moduleNames)));
}
if (![String]::IsNullOrEmpty($Conventions)) {
$conventionNames = $Conventions.Split(',', [System.StringSplitOptions]::RemoveEmptyEntries);
$invokeParams['Convention'] = $conventionNames;
WriteDebug ([String]::Concat('-Convention ', [String]::Join(', ', $conventionNames)));
}
if (![String]::IsNullOrEmpty($OutputPath)) {
$invokeParams['OutputPath'] = $OutputPath;
WriteDebug ([String]::Concat('-OutputPath ''', $OutputPath, ''''));
}
WriteDebug 'Running ''Invoke-PSDocument''.';
Write-Host '';
Write-Host '---';
Invoke-PSDocument @invokeParams -InputPath $InputPath;
}
catch {
Write-Host "::error::An error occured generating documentation. $($_.Exception.Message)";
if ($Null -ne $_.ScriptStackTrace) {
$_.ScriptStackTrace;
}
$Host.SetShouldExit(1);
}
finally {
Pop-Location;
}
Write-Host '---';