Skip to content

Commit a2fc09d

Browse files
updated build logic
1 parent 86cdeb2 commit a2fc09d

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v1
1414
- name: Install Prerequisites
15-
run: .\build\vsts-prerequisites.ps1
15+
run: .\build\psf-prerequisites.ps1 -Bootstrap
1616
shell: powershell
1717
- name: Validate
1818
run: .\build\vsts-validate.ps1
1919
shell: powershell
2020
- name: Build
21-
run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY
21+
run: .\build\psf-build.ps1 -ApiKey $env:APIKEY
2222
shell: powershell
2323
env:
2424
APIKEY: ${{ secrets.ApiKey }}

.github/workflows/validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
steps:
99
- uses: actions/checkout@v1
1010
- name: Install Prerequisites
11-
run: .\build\vsts-prerequisites.ps1
11+
run: .\build\psf-prerequisites.ps1 -Bootstrap
1212
shell: powershell
1313
- name: Validate
1414
run: .\build\vsts-validate.ps1

build/psf-build.ps1

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<#
2+
This script publishes the module to the gallery.
3+
It expects as input an ApiKey authorized to publish the module.
4+
5+
Insert any build steps you may need to take before publishing it here.
6+
#>
7+
param (
8+
$ApiKey,
9+
10+
$WorkingDirectory = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
11+
)
12+
13+
# Prepare publish folder
14+
Write-PSFMessage -Level Important -Message "Creating and populating publishing directory"
15+
$publishDir = New-Item -Path $WorkingDirectory -Name publish -ItemType Directory -Force
16+
Remove-Item -Path "$publishDir\*" -Recurse -Force -ErrorAction SilentlyContinue
17+
Copy-Item -Path "$($WorkingDirectory)\PSUtil" -Destination $publishDir.FullName -Recurse -Force
18+
19+
#region Gather text data to compile
20+
$text = @()
21+
$processed = @()
22+
23+
# Gather Stuff to run before
24+
foreach ($line in (Get-Content "$($PSScriptRoot)\filesBefore.txt" | Where-Object { $_ -notlike "#*" }))
25+
{
26+
if ([string]::IsNullOrWhiteSpace($line)) { continue }
27+
28+
$basePath = Join-Path "$($publishDir.FullName)\PSUtil" $line
29+
foreach ($entry in (Resolve-PSFPath -Path $basePath))
30+
{
31+
$item = Get-Item $entry
32+
if ($item.PSIsContainer) { continue }
33+
if ($item.FullName -in $processed) { continue }
34+
$text += [System.IO.File]::ReadAllText($item.FullName)
35+
$processed += $item.FullName
36+
}
37+
}
38+
39+
# Gather commands
40+
Get-ChildItem -Path "$($publishDir.FullName)\PSUtil\internal\functions\" -Recurse -File -Filter "*.ps1" | ForEach-Object {
41+
$text += [System.IO.File]::ReadAllText($_.FullName)
42+
}
43+
Get-ChildItem -Path "$($publishDir.FullName)\PSUtil\functions\" -Recurse -File -Filter "*.ps1" | ForEach-Object {
44+
$text += [System.IO.File]::ReadAllText($_.FullName)
45+
}
46+
47+
# Gather stuff to run afterwards
48+
foreach ($line in (Get-Content "$($PSScriptRoot)\filesAfter.txt" | Where-Object { $_ -notlike "#*" }))
49+
{
50+
if ([string]::IsNullOrWhiteSpace($line)) { continue }
51+
52+
$basePath = Join-Path "$($publishDir.FullName)\PSUtil" $line
53+
foreach ($entry in (Resolve-PSFPath -Path $basePath))
54+
{
55+
$item = Get-Item $entry
56+
if ($item.PSIsContainer) { continue }
57+
if ($item.FullName -in $processed) { continue }
58+
$text += [System.IO.File]::ReadAllText($item.FullName)
59+
$processed += $item.FullName
60+
}
61+
}
62+
#endregion Gather text data to compile
63+
64+
#region Update the psm1 file
65+
$fileData = Get-Content -Path "$($publishDir.FullName)\PSUtil\PSUtil.psm1" -Raw
66+
$fileData = $fileData.Replace('"<was not compiled>"', '"<was compiled>"')
67+
$fileData = $fileData.Replace('"<compile code into here>"', ($text -join "`n`n"))
68+
[System.IO.File]::WriteAllText("$($publishDir.FullName)\PSUtil\PSUtil.psm1", $fileData, [System.Text.Encoding]::UTF8)
69+
#endregion Update the psm1 file
70+
71+
# Publish to Gallery
72+
Publish-PSFModule -Path "$($publishDir.FullName)\PSUtil" -ApiKey $ApiKey

build/psf-prerequisites.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
param (
2+
[string]
3+
$Repository = 'PSGallery',
4+
5+
[switch]
6+
$Bootstrap
7+
)
8+
9+
if ($Bootstrap) {
10+
Invoke-WebRequest 'https://raw.githubusercontent.com/PowershellFrameworkCollective/PSFramework.NuGet/refs/heads/master/bootstrap.ps1' | Invoke-Expression
11+
}
12+
13+
$modules = @("Pester", "PSFramework", "PSModuleDevelopment", "PSScriptAnalyzer")
14+
15+
# Automatically add missing dependencies
16+
$data = Import-PowerShellDataFile -Path "$PSScriptRoot\..\PSUtil\PSUtil.psd1"
17+
foreach ($dependency in $data.RequiredModules) {
18+
if ($dependency -is [string]) {
19+
if ($modules -contains $dependency) { continue }
20+
$modules += $dependency
21+
}
22+
else {
23+
if ($modules -contains $dependency.ModuleName) { continue }
24+
$modules += $dependency.ModuleName
25+
}
26+
}
27+
28+
Install-PSFModule -Name $modules

0 commit comments

Comments
 (0)