Skip to content

Commit d155a5f

Browse files
Initial commit of the script
1 parent d9afe46 commit d155a5f

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

createpowershellmodule.ps1

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
param (
2+
[string]$ModuleName,
3+
[string]$Source = "",
4+
[string]$Output = "",
5+
[string]$Imports,
6+
[bool]$Debug = $false
7+
)
8+
try
9+
{
10+
Write-Host "::group::Starting the BuildModule task..."
11+
Write-Host "::group::Setting up variables"
12+
13+
if ([string]::IsNullOrEmpty($Source))
14+
{
15+
$sourcePath = "$($env:GITHUB_WORKSPACE)"
16+
}
17+
else
18+
{
19+
$sourcePath = "$($env:GITHUB_WORKSPACE)\$($Source)"
20+
}
21+
22+
if ([string]::IsNullOrEmpty($Output))
23+
{
24+
$outputPath = "$($env:GITHUB_WORKSPACE)\output"
25+
}
26+
else
27+
{
28+
$outputPath = "$($env:GITHUB_WORKSPACE)\$($Output)"
29+
}
30+
31+
$artifactsPath = "$($env:GITHUB_WORKSPACE)\artifacts"
32+
$modulePath = "$($outputPath)\$($ModuleName).psm1"
33+
34+
if ($Debug)
35+
{
36+
Write-Host "::debug::ModuleName : $($ModuleName)"
37+
Write-Host "::debug::SourcePath : $($sourcePath)"
38+
Write-Host "::debug::OutputPath : $($outputPath)"
39+
Write-Host "::debug::ModulePath : $($modulePath)"
40+
Write-Host "::debug::Imports : $($imports)"
41+
Write-Host "::debug::artifactsPath : $($artifactsPath)"
42+
}
43+
44+
$stringbuilder = [System.Text.StringBuilder]::new()
45+
$importFolders = $imports.Split(',')
46+
47+
Write-Host "::endgroup::"
48+
49+
Write-Host "::group::Copying Manifest"
50+
51+
if ($Debug)
52+
{
53+
Write-Host "::debug::Testing Output"
54+
}
55+
56+
if (-not (Test-Path -Path $outputPath)) {
57+
New-Item -ItemType Directory -Path $outputPath | Out-Null
58+
}
59+
60+
Write-Host "Copying Module manifest"
61+
Copy-Item -Path "$($artifactsPath)\$($ModuleName)\*" -Destination $outputPath -Recurse
62+
Write-Host "::endgroup::"
63+
64+
Write-Host "::group::Processing import folders..."
65+
foreach ($importFolder in $importFolders)
66+
{
67+
Write-Host "Importing from [$($sourcePath)\$($importFolder)]"
68+
if ($Debug)
69+
{
70+
Write-Host "::debug::Testing ImportFolder"
71+
}
72+
if (Test-Path "$sourcePath\$importFolder")
73+
{
74+
$fileList = Get-ChildItem "$($sourcePath)\$($importFolder)\*.ps1" -Exclude "*.Tests.ps1"
75+
foreach ($file in $fileList)
76+
{
77+
Write-Host " Importing [.$($file.BaseName)]"
78+
if ($Debug)
79+
{
80+
Write-Host "::debug::Reading file: $file.FullName"
81+
}
82+
$stringbuilder.AppendLine("# .$($file.BaseName)") | Out-Null
83+
$stringbuilder.AppendLine([System.IO.File]::ReadAllText($file.FullName)) | Out-Null
84+
}
85+
}
86+
else
87+
{
88+
Write-Host "##[warning]Folder $importFolder not found at $sourcePath"
89+
}
90+
}
91+
Write-Host "::endgroup::"
92+
93+
Write-Host "::group::Creating module [$($modulePath)]"
94+
Set-Content -Path $modulePath -Value $stringbuilder.ToString()
95+
Write-Host "BuildModule task completed successfully."
96+
Write-Host "::endgroup::"
97+
Write-Host "::endgroup::"
98+
}
99+
catch
100+
{
101+
Write-Host "##[error]An error occurred: $($_.Exception.Message)"
102+
exit 1
103+
}

0 commit comments

Comments
 (0)