Skip to content

Commit 2a50441

Browse files
🚀 [Feature]: Add functionality to automatically determine supported platforms (#18)
## Description - Add concurrency limit + cancel-in-progress. - Run module tests on 4 combinations: - pwsh@ubuntu - pwsh@macos - pwsh@windows - powershell@windows. If some tests pass, continue the workflow and add the correct info to the module manifest for the supportability of the module. - `Tags`: - `PSEdition_Core` - `PSEdition_Desktop` - `Linux` - `Windows` - `MacOS` - `CompatiblePSEdition`: - `Core` - `Desktop` - `PowerShellVersion`: - `5.0` by default - `7.0` if only `Core` ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [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 7fb9bf7 commit 2a50441

File tree

5 files changed

+258
-18
lines changed

5 files changed

+258
-18
lines changed

.github/workflows/Auto-Release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515

1616
concurrency:
1717
group: ${{ github.workflow }}
18+
cancel-in-progress: true
1819

1920
permissions:
2021
contents: write

.github/workflows/Linter.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ run-name: "Linter - [${{ github.event.pull_request.title }} #${{ github.event.pu
44

55
on: [pull_request]
66

7+
concurrency:
8+
group: ${{ github.workflow }}
9+
cancel-in-progress: true
10+
711
permissions:
812
contents: read
913
packages: read

.github/workflows/Workflow-Test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ run-name: "Workflow-Test - [${{ github.event.pull_request.title }} #${{ github.e
44

55
on: [pull_request]
66

7+
concurrency:
8+
group: ${{ github.workflow }}
9+
cancel-in-progress: true
10+
711
permissions:
812
contents: write
913
pull-requests: write

.github/workflows/workflow.yml

Lines changed: 239 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ permissions:
5656

5757
jobs:
5858
TestSourceCode:
59-
name: Test source code
59+
name: Test code
6060
strategy:
6161
fail-fast: false
6262
matrix:
@@ -84,7 +84,7 @@ jobs:
8484
Name: ${{ inputs.Name }}
8585
Path: ${{ inputs.Path }}
8686
Shell: ${{ matrix.shell }}
87-
TestType: 'SourceCode'
87+
TestType: SourceCode
8888

8989
BuildModule:
9090
name: Build module
@@ -124,18 +124,13 @@ jobs:
124124
if-no-files-found: error
125125
retention-days: 1
126126

127-
TestModule:
128-
name: Test module
127+
#This is necessary as there is no way to get output from a matrix job
128+
TestModule-pwsh-ubuntu-latest:
129+
name: Test module (pwsh, ubuntu-latest)
129130
needs: BuildModule
130-
strategy:
131-
fail-fast: false
132-
matrix:
133-
shell: [pwsh]
134-
os: [ubuntu-latest, macos-latest, windows-latest]
135-
include:
136-
- shell: powershell
137-
os: windows-latest
138-
runs-on: ${{ matrix.os }}
131+
runs-on: ubuntu-latest
132+
outputs:
133+
passed: ${{ steps.test.outputs.passed }}
139134
steps:
140135
- name: Checkout Code
141136
uses: actions/checkout@v4
@@ -145,7 +140,7 @@ jobs:
145140
with:
146141
Version: ${{ inputs.Version }}
147142
Prerelease: ${{ inputs.Prerelease }}
148-
Shell: ${{ matrix.shell }}
143+
Shell: pwsh
149144

150145
- name: Download module artifact
151146
uses: actions/download-artifact@v4
@@ -154,13 +149,239 @@ jobs:
154149
path: ${{ inputs.ModulesOutputPath }}
155150

156151
- name: Test built module
152+
id: test
157153
uses: PSModule/Test-PSModule@v1
158154
if: ${{ inputs.SkipTests != true }}
155+
continue-on-error: true
159156
with:
160157
Name: ${{ inputs.Name }}
161158
Path: ${{ inputs.ModulesOutputPath }}
162-
Shell: ${{ matrix.shell }}
163-
TestType: 'Module'
159+
Shell: pwsh
160+
TestType: Module
161+
162+
- name: Set status
163+
if: steps.test.outcome != 'success'
164+
shell: pwsh
165+
run: Write-Host "Complete successfully"
166+
167+
TestModule-pwsh-macos-latest:
168+
name: Test module (pwsh, macos-latest)
169+
needs: BuildModule
170+
runs-on: macos-latest
171+
outputs:
172+
passed: ${{ steps.test.outputs.passed }}
173+
steps:
174+
- name: Checkout Code
175+
uses: actions/checkout@v4
176+
177+
- name: Initialize environment
178+
uses: PSModule/Initialize-PSModule@v1
179+
with:
180+
Version: ${{ inputs.Version }}
181+
Prerelease: ${{ inputs.Prerelease }}
182+
Shell: pwsh
183+
184+
- name: Download module artifact
185+
uses: actions/download-artifact@v4
186+
with:
187+
name: module
188+
path: ${{ inputs.ModulesOutputPath }}
189+
190+
- name: Test built module
191+
id: test
192+
uses: PSModule/Test-PSModule@v1
193+
if: ${{ inputs.SkipTests != true }}
194+
continue-on-error: true
195+
with:
196+
Name: ${{ inputs.Name }}
197+
Path: ${{ inputs.ModulesOutputPath }}
198+
Shell: pwsh
199+
TestType: Module
200+
201+
- name: Set status
202+
if: steps.test.outcome != 'success'
203+
shell: pwsh
204+
run: Write-Host "Complete successfully"
205+
206+
TestModule-pwsh-windows-latest:
207+
name: Test module (pwsh, windows-latest)
208+
needs: BuildModule
209+
runs-on: windows-latest
210+
outputs:
211+
passed: ${{ steps.test.outputs.passed }}
212+
steps:
213+
- name: Checkout Code
214+
uses: actions/checkout@v4
215+
216+
- name: Initialize environment
217+
uses: PSModule/Initialize-PSModule@v1
218+
with:
219+
Version: ${{ inputs.Version }}
220+
Prerelease: ${{ inputs.Prerelease }}
221+
Shell: pwsh
222+
223+
- name: Download module artifact
224+
uses: actions/download-artifact@v4
225+
with:
226+
name: module
227+
path: ${{ inputs.ModulesOutputPath }}
228+
229+
- name: Test built module
230+
id: test
231+
uses: PSModule/Test-PSModule@v1
232+
if: ${{ inputs.SkipTests != true }}
233+
continue-on-error: true
234+
with:
235+
Name: ${{ inputs.Name }}
236+
Path: ${{ inputs.ModulesOutputPath }}
237+
Shell: pwsh
238+
TestType: Module
239+
240+
- name: Set status
241+
if: steps.test.outcome != 'success'
242+
shell: pwsh
243+
run: Write-Host "Complete successfully"
244+
245+
TestModule-powershell-windows-latest:
246+
name: Test module (powershell, windows-latest)
247+
needs: BuildModule
248+
runs-on: windows-latest
249+
outputs:
250+
passed: ${{ steps.test.outputs.passed }}
251+
steps:
252+
- name: Checkout Code
253+
uses: actions/checkout@v4
254+
255+
- name: Initialize environment
256+
uses: PSModule/Initialize-PSModule@v1
257+
with:
258+
Version: ${{ inputs.Version }}
259+
Prerelease: ${{ inputs.Prerelease }}
260+
Shell: powershell
261+
262+
- name: Download module artifact
263+
uses: actions/download-artifact@v4
264+
with:
265+
name: module
266+
path: ${{ inputs.ModulesOutputPath }}
267+
268+
- name: Test built module
269+
id: test
270+
uses: PSModule/Test-PSModule@v1
271+
if: ${{ inputs.SkipTests != true }}
272+
continue-on-error: true
273+
with:
274+
Name: ${{ inputs.Name }}
275+
Path: ${{ inputs.ModulesOutputPath }}
276+
Shell: powershell
277+
TestType: Module
278+
279+
- name: Set status
280+
if: steps.test.outcome != 'success'
281+
shell: pwsh
282+
run: Write-Host "Complete successfully"
283+
284+
TestModuleStatus:
285+
name: Test module status
286+
needs:
287+
- TestModule-pwsh-ubuntu-latest
288+
- TestModule-pwsh-macos-latest
289+
- TestModule-pwsh-windows-latest
290+
- TestModule-powershell-windows-latest
291+
runs-on: ubuntu-latest
292+
if: success() || failure()
293+
steps:
294+
- name: Checkout Code
295+
uses: actions/checkout@v4
296+
297+
- name: Initialize environment
298+
uses: PSModule/Initialize-PSModule@v1
299+
with:
300+
Version: ${{ inputs.Version }}
301+
Prerelease: ${{ inputs.Prerelease }}
302+
303+
- name: Download module artifact
304+
uses: actions/download-artifact@v4
305+
with:
306+
name: module
307+
path: ${{ inputs.ModulesOutputPath }}
308+
309+
- name: Summerize tests
310+
shell: pwsh
311+
run: |
312+
Start-LogGroup -Name 'Status'
313+
$Linux = '${{ needs.TestModule-pwsh-ubuntu-latest.outputs.passed }}' -eq 'true'
314+
$MacOS = '${{ needs.TestModule-pwsh-macos-latest.outputs.passed }}' -eq 'true'
315+
$Windows = '${{ needs.TestModule-pwsh-windows-latest.outputs.passed }}' -eq 'true'
316+
$Desktop = '${{ needs.TestModule-powershell-windows-latest.outputs.passed }}' -eq 'true'
317+
$Core = $Linux -or $MacOS -or $Windows
318+
319+
$Status = [pscustomobject]@{
320+
Linux = $Linux
321+
MacOS = $MacOS
322+
Windows = $Windows
323+
Desktop = $Desktop
324+
Core = $Core
325+
}
326+
327+
Write-Host ($Status | Format-Table | Out-String)
328+
329+
if (-not ($Core -or $Desktop)) {
330+
Write-Host "::[error]::No tests passed"
331+
exit 1
332+
}
333+
Stop-LogGroup
334+
335+
Start-LogGroup -Name 'Data'
336+
$moduleName = [string]::IsNullOrEmpty('${{ inputs.Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ inputs.Name }}'
337+
$path = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath "${{ inputs.ModulesOutputPath }}\$moduleName"
338+
$moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1"
339+
340+
$data = [pscustomobject]@{
341+
ModuleName = $moduleName
342+
Path = $path
343+
ModuleManifestPath = $moduleManifestPath
344+
}
345+
Write-Host ($data | Format-Table | Out-String)
346+
347+
if ($Desktop) {
348+
Add-ModuleManifestData -Path $moduleManifestPath -CompatiblePSEditions 'Desktop'
349+
Add-ModuleManifestData -Path $moduleManifestPath -Tags 'PSEdition_Desktop'
350+
}
351+
352+
if ($Core) {
353+
Add-ModuleManifestData -Path $moduleManifestPath -CompatiblePSEditions 'Core'
354+
Add-ModuleManifestData -Path $moduleManifestPath -Tags 'PSEdition_Core'
355+
Set-ModuleManifest -Path $moduleManifestPath -PowerShellVersion '7.0'
356+
} else {
357+
Set-ModuleManifest -Path $moduleManifestPath -PowerShellVersion '5.1'
358+
}
359+
360+
if ($Linux) {
361+
Add-ModuleManifestData -Path $moduleManifestPath -Tags 'Linux'
362+
}
363+
364+
if ($MacOS) {
365+
Add-ModuleManifestData -Path $moduleManifestPath -Tags 'MacOS'
366+
}
367+
368+
if ($Windows) {
369+
Add-ModuleManifestData -Path $moduleManifestPath -Tags 'Windows'
370+
}
371+
Stop-LogGroup
372+
373+
Start-LogGroup -Name 'Module Manifest'
374+
Show-FileContent -Path $moduleManifestPath
375+
Stop-LogGroup
376+
377+
- name: Upload module artifact
378+
uses: actions/upload-artifact@v4
379+
with:
380+
name: module
381+
path: ${{ inputs.ModulesOutputPath }}
382+
if-no-files-found: error
383+
retention-days: 1
384+
overwrite: true
164385

165386
LintDocs:
166387
name: Lint documentation
@@ -197,8 +418,9 @@ jobs:
197418

198419
PublishModule:
199420
name: Publish module
421+
if: ${{ needs.TestModuleStatus.result == 'success' && needs.LintDocs.result == 'success' && (success() || failure()) }}
200422
needs:
201-
- TestModule
423+
- TestModuleStatus
202424
- LintDocs
203425
runs-on: ubuntu-latest
204426
steps:

tests/tests/PSModuleTest.Tests.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
Describe 'PSModuleTest.Tests.ps1' {
1+
[CmdletBinding()]
2+
Param(
3+
# Path to the module to test.
4+
[Parameter()]
5+
[string] $Path
6+
)
7+
8+
Write-Verbose "Path to the module: [$Path]" -Verbose
9+
10+
Describe 'PSModuleTest.Tests.ps1' {
211
It 'Should be able to import the module' {
312
Import-Module -Name 'PSModuleTest' -Verbose
413
Get-Module -Name 'PSModuleTest' | Should -Not -BeNullOrEmpty

0 commit comments

Comments
 (0)