Skip to content

Commit 0bb06fb

Browse files
authored
A new build, using GitHub Actions
Merge pull request #107 from PoshCode/jaykul/wip
2 parents 97349a1 + 0dbffc6 commit 0bb06fb

16 files changed

+332
-144
lines changed

.editorconfig

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# EditorConfig is awesome: http://EditorConfig.org
2-
#
3-
# Settings follow https://github.com/PowerShell/PowerShellEditorServices/blob/master/.editorconfig
4-
5-
# top-most EditorConfig file
6-
root = true
72

83
[*]
94
indent_style = space
105
insert_final_newline = true
6+
end_of_line = crlf
7+
8+
[*.{ps1,psm1,psd1}]
9+
indent_size = 4
10+
trim_trailing_whitespace = true
1111

1212
[*.{cs}]
1313
indent_size = 4
@@ -17,9 +17,5 @@ trim_trailing_whitespace = true
1717
indent_size = 2
1818
trim_trailing_whitespace = true
1919

20-
[*.{ps1,psm1,psd1}]
21-
indent_size = 4
22-
trim_trailing_whitespace = true
23-
2420
[*.{ps1xml,props,xml,yaml,yml}]
2521
indent_size = 2

.github/workflows/build.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build on push
2+
on: [push]
3+
jobs:
4+
build:
5+
runs-on: windows-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v2
9+
- name: GitVersion
10+
id: gitversion
11+
uses: PoshCode/Actions/gitversion@v1
12+
- name: Install-RequiredModules
13+
uses: PoshCode/Actions/install-requiredmodules@v1
14+
- name: Build Module
15+
id: build
16+
uses: PoshCode/actions/build-module@v1
17+
with:
18+
path: ${{github.workspace}}/Source
19+
version: ${{ steps.gitversion.outputs.LegacySemVerPadded }}
20+
destination: ${{github.workspace}}/output
21+
- name: Upload Build Output
22+
uses: actions/upload-artifact@v2
23+
with:
24+
name: Modules
25+
path: ${{github.workspace}}/output
26+
- name: Upload Tests
27+
uses: actions/upload-artifact@v2
28+
with:
29+
name: PesterTests
30+
path: ${{github.workspace}}/Tests
31+
- name: Upload RequiredModules.psd1
32+
uses: actions/upload-artifact@v2
33+
with:
34+
name: RequiredModules
35+
path: ${{github.workspace}}/RequiredModules.psd1
36+
- name: Upload PSScriptAnalyzerSettings.psd1
37+
uses: actions/upload-artifact@v2
38+
with:
39+
name: ScriptAnalyzer
40+
path: ${{github.workspace}}/PSScriptAnalyzerSettings.psd1
41+
lint:
42+
needs: build
43+
name: Run PSScriptAnalyzer
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Download Build Output
47+
uses: actions/download-artifact@v2
48+
- name: Invoke-ScriptAnalyzer
49+
uses: devblackops/github-action-psscriptanalyzer@master
50+
with:
51+
rootPath: Modules/ModuleBuilder
52+
repoToken: ${{ secrets.GITHUB_TOKEN }}
53+
test:
54+
needs: build
55+
runs-on: ${{ matrix.os }}
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
os: [windows-2016, windows-latest, ubuntu-latest, macos-latest]
60+
steps:
61+
- name: Download Build Output
62+
uses: actions/download-artifact@v2
63+
- uses: PoshCode/Actions/install-requiredmodules@v1
64+
- uses: PoshCode/Actions/pester@v1
65+
with:
66+
codeCoveragePath: Modules/ModuleBuilder
67+
moduleUnderTest: ModuleBuilder
68+
additionalModulePaths: ${{github.workspace}}/Modules
69+
- name: Publish Test Results
70+
uses: zyborg/dotnet-tests-report@v1
71+
with:
72+
test_results_path: results.xml
73+
- name: Upload Results
74+
uses: actions/upload-artifact@v2
75+
with:
76+
name: Pester Results
77+
path: ${{github.workspace}}/*.xml

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"powershell.codeFormatting.preset": "OTBS",
88
"powershell.codeFormatting.ignoreOneLineBlock": false,
99
"powershell.codeFormatting.newLineAfterCloseBrace": false,
10+
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
11+
"powershell.codeFormatting.alignPropertyValuePairs": true,
12+
"powershell.codeFormatting.autoCorrectAliases": true,
13+
"powershell.codeFormatting.useCorrectCasing": true,
1014
"files.associations": {
1115
"*.ps1xml": "xml"
1216
}

RequiredModules.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@{
33
"Configuration" = "[1.3.1,2.0)"
44
"ModuleBuilder" = "1.*"
5-
"Pester" = "[4.5.0,5.0)"
5+
"Pester" = "[4.10.1,5.0)"
66
"PowerShellGet" = "2.0.4"
77
"PSScriptAnalyzer" = "1.*"
88
}

Source/ModuleBuilder.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
@{
22
# The module version should be SemVer.org compatible
3-
ModuleVersion = "1.1.0"
3+
ModuleVersion = "0.0.0"
44

55
# PrivateData is where all third-party metadata goes
66
PrivateData = @{
77
# PrivateData.PSData is the PowerShell Gallery data
88
PSData = @{
99
# Prerelease string should be here, so we can set it
10-
Prerelease = 'beta'
10+
Prerelease = 'source'
1111

1212
# Release Notes have to be here, so we can update them
1313
ReleaseNotes = '

Source/ModuleBuilder.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foreach ($file in Get-ChildItem "Private", "Public") {
2+
. $file.FullName
3+
}

Source/Private/GetBuildInfo.ps1

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ function GetBuildInfo {
6565
}
6666
# BuildInfo.SourcePath should point to a module manifest
6767
if ($BuildInfo.SourcePath -and $BuildInfo.SourcePath -ne $BuildManifest) {
68+
Write-Debug " Updating: SourcePath"
69+
Write-Debug " To: $($BuildInfo.SourcePath)"
6870
$ParameterValues["SourcePath"] = $BuildInfo.SourcePath
6971
}
7072
# If SourcePath point to build.psd1, we should clear it
7173
if ($ParameterValues["SourcePath"] -eq $BuildManifest) {
74+
Write-Debug " Removing: SourcePath"
7275
$ParameterValues.Remove("SourcePath")
7376
}
7477
Write-Debug "Finished parsing Build Manifest $BuildManifest"
@@ -80,25 +83,31 @@ function GetBuildInfo {
8083
}
8184

8285
if ((-not $BuildInfo.SourcePath) -and $ParameterValues["SourcePath"] -notmatch '\.psd1') {
86+
Write-Debug " Searching: SourcePath"
8387
# Find a module manifest (or maybe several)
8488
$ModuleInfo = Get-ChildItem $BuildManifestParent -Recurse -Filter *.psd1 -ErrorAction SilentlyContinue |
8589
ImportModuleManifest -ErrorAction SilentlyContinue
8690
# If we found more than one module info, the only way we have of picking just one is if it matches a folder name
8791
if (@($ModuleInfo).Count -gt 1) {
88-
# Resolve Build Manifest's parent folder to find the Absolute path
89-
$ModuleName = Split-Path -Leaf $BuildManifestParent
90-
# If we're in a "well known" source folder, look higher for a name
91-
if ($ModuleName -in 'Source', 'src') {
92-
$ModuleName = Split-Path (Split-Path -Parent $BuildManifestParent) -Leaf
92+
Write-Debug (@(@(" Found $(@($ModuleInfo).Count):") + @($ModuleInfo.Path)) -join "`n ")
93+
# It can't be a module that needs building unless it has either:
94+
$ModuleInfo = $ModuleInfo.Where{
95+
$Root = Split-Path $_.Path
96+
@(
97+
# - A build.psd1 next to it
98+
Test-Path (Join-Path $Root "build.ps1") -PathType Leaf
99+
# - A Public (or Private) folder with source scripts in it
100+
Test-Path (Join-Path $Root "Public") -PathType Container
101+
Test-Path (Join-Path $Root "Private") -PathType Container
102+
) -contains $true
93103
}
94-
$ModuleInfo = @($ModuleInfo).Where{ $_.Name -eq $ModuleName }
104+
Write-Debug (@(@(" Filtered $(@($ModuleInfo).Count):") + @($ModuleInfo.Path)) -join "`n ")
95105
}
96106
if (@($ModuleInfo).Count -eq 1) {
97107
Write-Debug "Updating BuildInfo SourcePath to $($ModuleInfo.Path)"
98108
$ParameterValues["SourcePath"] = $ModuleInfo.Path
99-
}
100-
if (-Not $ModuleInfo) {
101-
throw "Can't find a module manifest in $BuildManifestParent"
109+
} else {
110+
throw "Can't determine the module manifest in $BuildManifestParent"
102111
}
103112
}
104113

Source/Private/MoveUsingStatements.ps1

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ function MoveUsingStatements {
88
99
This function uses AST to comment out those statements (to preserver line numbering)
1010
and insert them (conserving order) at the top of the script.
11-
12-
Should the merged RootModule already have errors not related to the Using statements,
13-
or no errors caused by misplaced Using statements, this steps is skipped.
14-
15-
If moving (comment & copy) the Using statements introduce parsing errors to the script,
16-
those changes won't be applied to the file.
1711
#>
1812
[CmdletBinding()]
1913
param(
@@ -52,15 +46,14 @@ function MoveUsingStatements {
5246
# Edit the Script content by commenting out existing statements (conserving line numbering)
5347
$ScriptText = $AST.Extent.Text
5448
$InsertedCharOffset = 0
55-
$StatementsToCopy = New-Object System.Collections.ArrayList
49+
$StatementsToCopy = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
50+
5651
foreach ($UsingSatement in $UsingStatementExtents) {
5752
$ScriptText = $ScriptText.Insert($UsingSatement.StartOffset + $InsertedCharOffset, '#')
5853
$InsertedCharOffset++
5954

6055
# Keep track of unique statements we'll need to insert at the top
61-
if (!$StatementsToCopy.Contains($UsingSatement.Text)) {
62-
$null = $StatementsToCopy.Add($UsingSatement.Text)
63-
}
56+
$null = $StatementsToCopy.Add($UsingSatement.Text)
6457
}
6558

6659
$ScriptText = $ScriptText.Insert(0, ($StatementsToCopy -join "`r`n") + "`r`n")

Source/Public/Convert-Breakpoint.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function Convert-Breakpoint {
2+
<#
3+
.SYNOPSIS
4+
Convert any breakpoints on source files to module files and vice-versa
5+
#>
6+
[CmdletBinding(DefaultParameterSetName="All")]
7+
param(
8+
[Parameter(ParameterSetName="Module")]
9+
[switch]$ModuleOnly,
10+
[Parameter(ParameterSetName="Source")]
11+
[switch]$SourceOnly
12+
)
13+
14+
if (!$SourceOnly) {
15+
foreach ($ModuleBreakPoint in Get-PSBreakpoint | ConvertFrom-SourceLineNumber) {
16+
Set-PSBreakpoint -Script $ModuleBreakPoint.Script -Line $ModuleBreakPoint.Line
17+
if ($ModuleOnly) {
18+
# TODO: | Remove-PSBreakpoint
19+
}
20+
}
21+
}
22+
23+
if (!$ModuleOnly) {
24+
foreach ($SourceBreakPoint in Get-PSBreakpoint | ConvertTo-SourceLineNumber) {
25+
if (!(Test-Path $SourceBreakPoint.SourceFile)) {
26+
Write-Warning "Can't find source path: $($SourceBreakPoint.SourceFile)"
27+
} else {
28+
Set-PSBreakpoint -Script $SourceBreakPoint.SourceFile -Line $SourceBreakPoint.SourceLineNumber
29+
}
30+
if ($SourceOnly) {
31+
# TODO: | Remove-PSBreakpoint
32+
}
33+
}
34+
}
35+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
function ConvertFrom-SourceLineNumber {
2+
<#
3+
.SYNOPSIS
4+
Convert a source file path and line number to the line number in the built output
5+
.EXAMPLE
6+
ConvertFrom-SourceLineNumber -Module ~\2.0.0\ModuleBuilder.psm1 -SourceFile ~\Source\Public\Build-Module.ps1 -Line 27
7+
#>
8+
[CmdletBinding(DefaultParameterSetName="FromString")]
9+
param(
10+
# The SourceFile is the source script file that was built into the module
11+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, Position=0)]
12+
[Alias("PSCommandPath", "File", "ScriptName", "Script")]
13+
[string]$SourceFile,
14+
15+
# The SourceLineNumber (from an InvocationInfo) is the line number in the source file
16+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, Position=1)]
17+
[Alias("LineNumber", "Line", "ScriptLineNumber")]
18+
[int]$SourceLineNumber,
19+
20+
# The name of the module in memory, or the full path to the module psm1
21+
[Parameter()]
22+
[string]$Module
23+
)
24+
begin {
25+
$filemap = @{}
26+
}
27+
process {
28+
if (!$Module) {
29+
$Command = [IO.Path]::GetFileNameWithoutExtension($SourceFile)
30+
$Module = (Get-Command $Command -ErrorAction SilentlyContinue).Source
31+
if (!$Module) {
32+
Write-Warning "Please specify -Module for breakpoint ${SourceFile}: $SourceLineNumber"
33+
return
34+
}
35+
}
36+
if ($Module -and -not (Test-Path $Module)) {
37+
$Module = (Get-Module $Module -ErrorAction Stop).Path
38+
}
39+
# Push-Location (Split-Path $SourceFile)
40+
try {
41+
if (!$filemap.ContainsKey($Module)) {
42+
# Note: the new pattern is #Region but the old one was # BEGIN
43+
$regions = Select-String '^(?:#Region|# BEGIN) (?<SourceFile>.*) (?<LineNumber>\d+)?$' -Path $Module
44+
$filemap[$Module] = @($regions.ForEach{
45+
[PSCustomObject]@{
46+
PSTypeName = "BuildSourceMapping"
47+
SourceFile = $_.Matches[0].Groups["SourceFile"].Value.Trim("'")
48+
StartLineNumber = $_.LineNumber
49+
}
50+
})
51+
}
52+
53+
$hit = $filemap[$Module]
54+
55+
if ($Source = $hit.Where{ $SourceFile.EndsWith($_.SourceFile.TrimStart(".\")) }) {
56+
[PSCustomObject]@{
57+
PSTypeName = "OutputLocation"
58+
Script = $Module
59+
Line = $Source.StartLineNumber + $SourceLineNumber
60+
}
61+
} elseif($Source -eq $Module) {
62+
[PSCustomObject]@{
63+
PSTypeName = "OutputLocation"
64+
Script = $Module
65+
Line = $SourceLineNumber
66+
}
67+
} else {
68+
Write-Warning "'$SourceFile' not found in $Module"
69+
}
70+
} finally {
71+
Pop-Location
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)