Skip to content

Commit 1c06436

Browse files
🪲 [Fix]: No longer check missing module manifest fields on source code (#46)
## Description - No longer check missing module manifest fields on source code - Adds tests for source code without module named folder, and without manifest. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 276b770 commit 1c06436

File tree

68 files changed

+1135
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1135
-74
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Action-Test [Src-Default]
2+
3+
run-name: "Action-Test [Src-Default] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
4+
5+
on: [pull_request]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions: {}
12+
13+
jobs:
14+
ActionTest:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
shell: [pwsh]
20+
include:
21+
- os: windows-latest
22+
shell: powershell
23+
name: Action-Test [Src-Default] - [${{ matrix.os }}@${{ matrix.shell }}]
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Checkout repo
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize environment
30+
uses: PSModule/Initialize-PSModule@main
31+
with:
32+
Shell: ${{ matrix.shell }}
33+
34+
- name: Action-Test
35+
uses: ./
36+
env:
37+
GITHUB_TOKEN: ${{ github.token }}
38+
with:
39+
Name: PSModuleTest
40+
Path: tests/src
41+
Shell: ${{ matrix.shell }}
42+
TestType: SourceCode
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Action-Test [Src-UnnamedFolder]
2+
3+
run-name: "Action-Test [Src-UnnamedFolder] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
4+
5+
on: [pull_request]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions: {}
12+
13+
jobs:
14+
ActionTest:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
shell: [pwsh]
20+
include:
21+
- os: windows-latest
22+
shell: powershell
23+
name: Action-Test [Src-UnnamedFolder] - [${{ matrix.os }}@${{ matrix.shell }}]
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Checkout repo
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize environment
30+
uses: PSModule/Initialize-PSModule@main
31+
with:
32+
Shell: ${{ matrix.shell }}
33+
34+
- name: Action-Test
35+
uses: ./
36+
env:
37+
GITHUB_TOKEN: ${{ github.token }}
38+
with:
39+
Name: PSModuleTest
40+
Path: tests/srcNo
41+
Shell: ${{ matrix.shell }}
42+
TestType: SourceCode
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Action-Test [Src-UnnamedWithManifest]
2+
3+
run-name: "Action-Test [Src-UnnamedWithManifest] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
4+
5+
on: [pull_request]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions: {}
12+
13+
jobs:
14+
ActionTest:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
shell: [pwsh]
20+
include:
21+
- os: windows-latest
22+
shell: powershell
23+
name: Action-Test [Src-UnnamedWithManifest] - [${{ matrix.os }}@${{ matrix.shell }}]
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Checkout repo
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize environment
30+
uses: PSModule/Initialize-PSModule@main
31+
with:
32+
Shell: ${{ matrix.shell }}
33+
34+
- name: Action-Test
35+
uses: ./
36+
env:
37+
GITHUB_TOKEN: ${{ github.token }}
38+
with:
39+
Name: PSModuleTest
40+
Path: tests/srcNoWithManifest
41+
Shell: ${{ matrix.shell }}
42+
TestType: SourceCode
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Action-Test [outputs]
2+
3+
run-name: "Action-Test [outputs] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
4+
5+
on: [pull_request]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions: {}
12+
13+
jobs:
14+
ActionTest:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
shell: [pwsh]
20+
include:
21+
- os: windows-latest
22+
shell: powershell
23+
name: Action-Test [outputs] - [${{ matrix.os }}@${{ matrix.shell }}]
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Checkout repo
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize environment
30+
uses: PSModule/Initialize-PSModule@main
31+
with:
32+
Shell: ${{ matrix.shell }}
33+
34+
- name: Action-Test
35+
uses: ./
36+
env:
37+
GITHUB_TOKEN: ${{ github.token }}
38+
with:
39+
Name: PSModuleTest
40+
Path: tests/outputs/modules
41+
Shell: ${{ matrix.shell }}
42+
TestType: Module

.github/workflows/Action-Test.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/Auto-Release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Auto-Release
22

3-
run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
3+
run-name: "${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
44

55
on:
66
pull_request_target:

.github/workflows/Linter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ jobs:
2727
uses: super-linter/super-linter@latest
2828
env:
2929
GITHUB_TOKEN: ${{ github.token }}
30+
FILTER_REGEX_EXCLUDE: ${{ github.workspace }}/tests

scripts/tests/PSScriptAnalyzer/Settings.SourceCode.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151
}
5252
ExcludeRules = @(
53+
'PSMissingModuleManifestField', # This rule is not applicable until the module is built.
5354
'PSAvoidUsingCmdletAliases',
5455
'PSUseToExportFieldsInManifest'
5556
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@{
2+
ModuleVersion = '0.0.0'
3+
RootModule = 'PSModuleTest.psm1'
4+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[Cmdletbinding()]
2+
param()
3+
4+
Write-Verbose 'Importing subcomponents'
5+
$Folders = 'init', 'classes', 'private', 'public'
6+
# Import everything in these folders
7+
Foreach ($Folder in $Folders) {
8+
$Root = Join-Path -Path $PSScriptRoot -ChildPath $Folder
9+
Write-Verbose "Processing folder: $Root"
10+
if (Test-Path -Path $Root) {
11+
Write-Verbose "Getting all files in $Root"
12+
$Files = $null
13+
$Files = Get-ChildItem -Path $Root -Include '*.ps1', '*.psm1' -Recurse
14+
# dot source each file
15+
foreach ($File in $Files) {
16+
Write-Verbose "Importing $($File)"
17+
Import-Module $File
18+
Write-Verbose "Importing $($File): Done"
19+
}
20+
}
21+
}
22+
23+
. "$PSScriptRoot\finally.ps1"
24+
25+
# Define the types to export with type accelerators.
26+
$ExportableTypes = @(
27+
[Book]
28+
[BookList]
29+
)
30+
31+
# Get the internal TypeAccelerators class to use its static methods.
32+
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
33+
'System.Management.Automation.TypeAccelerators'
34+
)
35+
# Ensure none of the types would clobber an existing type accelerator.
36+
# If a type accelerator with the same name exists, throw an exception.
37+
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
38+
foreach ($Type in $ExportableTypes) {
39+
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
40+
$Message = @(
41+
"Unable to register type accelerator '$($Type.FullName)'"
42+
'Accelerator already exists.'
43+
) -join ' - '
44+
45+
throw [System.Management.Automation.ErrorRecord]::new(
46+
[System.InvalidOperationException]::new($Message),
47+
'TypeAcceleratorAlreadyExists',
48+
[System.Management.Automation.ErrorCategory]::InvalidOperation,
49+
$Type.FullName
50+
)
51+
}
52+
}
53+
# Add type accelerators for every exportable type.
54+
foreach ($Type in $ExportableTypes) {
55+
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
56+
}
57+
# Remove type accelerators when the module is removed.
58+
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
59+
foreach ($Type in $ExportableTypes) {
60+
$TypeAcceleratorsClass::Remove($Type.FullName)
61+
}
62+
}.GetNewClosure()
63+
64+
$Param = @{
65+
Function = (Get-ChildItem -Path "$PSScriptRoot\public" -Include '*.ps1' -Recurse).BaseName
66+
Variable = '*'
67+
Cmdlet = '*'
68+
Alias = '*'
69+
}
70+
71+
Write-Verbose 'Exporting module members'
72+
73+
Export-ModuleMember @Param

0 commit comments

Comments
 (0)