Skip to content

Commit dff7240

Browse files
Refactor GitHub workflows to use a centralized settings object
- Removed individual inputs for module name, debug, verbose, version, prerelease, and working directory from multiple workflows. - Introduced a unified settings object passed as a JSON string to streamline configuration across workflows. - Updated workflows: Get-Settings, Get-TestResults, Lint-SourceCode, Test-Module, Test-ModuleLocal, Test-SourceCode, and others to utilize the new settings structure. - Created new workflows for BeforeAll and AfterAll setup scripts to handle module testing. - Added Publish-Module and Publish-Site workflows for modular publishing processes. - Updated README to reflect changes in input parameters and workflow configurations.
1 parent 12d0c59 commit dff7240

19 files changed

+324
-584
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: AfterAll-ModuleLocal
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
Settings:
7+
type: string
8+
description: The complete settings object including test suites.
9+
required: true
10+
11+
permissions:
12+
contents: read # to checkout the repo
13+
14+
jobs:
15+
AfterAll-ModuleLocal:
16+
name: AfterAll-ModuleLocal
17+
runs-on: ubuntu-latest
18+
env:
19+
SETTINGS: ${{ inputs.Settings }}
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
23+
with:
24+
persist-credentials: false
25+
fetch-depth: 0
26+
27+
- name: Run AfterAll Teardown Scripts
28+
if: always()
29+
uses: PSModule/GitHub-Script@8b9d2739d6896975c0e5448d2021ae2b94b6766a # v1.7.6
30+
with:
31+
Name: AfterAll-ModuleLocal
32+
ShowInfo: false
33+
ShowOutput: true
34+
Debug: ${{ fromJson(inputs.Settings).Debug }}
35+
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
36+
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
37+
Version: ${{ fromJson(inputs.Settings).Version }}
38+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
39+
Script: |
40+
LogGroup "Running AfterAll Teardown Scripts" {
41+
$afterAllScript = 'tests/AfterAll.ps1'
42+
43+
if (-not (Test-Path $afterAllScript)) {
44+
Write-Host "No AfterAll.ps1 script found at [$afterAllScript] - exiting successfully"
45+
exit 0
46+
}
47+
48+
Write-Host "Running AfterAll teardown script: $afterAllScript"
49+
try {
50+
& $afterAllScript
51+
Write-Host "AfterAll script completed successfully: $afterAllScript"
52+
} catch {
53+
Write-Warning "AfterAll script failed: $afterAllScript - $_"
54+
# Don't throw for teardown scripts to ensure other cleanup scripts can run
55+
}
56+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: BeforeAll-ModuleLocal
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
Settings:
7+
type: string
8+
description: The complete settings object including test suites.
9+
required: true
10+
11+
permissions:
12+
contents: read # to checkout the repo
13+
14+
jobs:
15+
BeforeAll-ModuleLocal:
16+
name: BeforeAll-ModuleLocal
17+
runs-on: ubuntu-latest
18+
env:
19+
Settings: ${{ inputs.Settings }}
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
23+
with:
24+
persist-credentials: false
25+
fetch-depth: 0
26+
27+
- name: Run BeforeAll Setup Scripts
28+
uses: PSModule/GitHub-Script@8b9d2739d6896975c0e5448d2021ae2b94b6766a # v1.7.6
29+
with:
30+
Name: BeforeAll-ModuleLocal
31+
ShowInfo: false
32+
ShowOutput: true
33+
Debug: ${{ fromJson(inputs.Settings).Debug }}
34+
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
35+
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
36+
Version: ${{ fromJson(inputs.Settings).Version }}
37+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
38+
Script: |
39+
LogGroup "Running BeforeAll Setup Scripts" {
40+
$beforeAllScript = 'tests/BeforeAll.ps1'
41+
42+
if (-not (Test-Path $beforeAllScript)) {
43+
Write-Host "No BeforeAll.ps1 script found at [$beforeAllScript] - exiting successfully"
44+
exit 0
45+
}
46+
47+
Write-Host "Running BeforeAll setup script: $beforeAllScript"
48+
try {
49+
& $beforeAllScript
50+
Write-Host "BeforeAll script completed successfully: $beforeAllScript"
51+
} catch {
52+
Write-Error "BeforeAll script failed: $beforeAllScript - $_"
53+
throw
54+
}
55+
}

.github/workflows/Build-Docs.yml

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,10 @@ name: Build-Docs
33
on:
44
workflow_call:
55
inputs:
6-
Name:
6+
Settings:
77
type: string
8-
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
9-
required: false
10-
Debug:
11-
type: boolean
12-
description: Enable debug output.
13-
required: false
14-
default: false
15-
Verbose:
16-
type: boolean
17-
description: Enable verbose output.
18-
required: false
19-
default: false
20-
Version:
21-
type: string
22-
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
23-
required: false
24-
default: ''
25-
Prerelease:
26-
type: boolean
27-
description: Whether to use a prerelease version of the 'GitHub' module.
28-
required: false
29-
default: false
30-
WorkingDirectory:
31-
type: string
32-
description: The working directory where the script will run from.
33-
required: false
34-
default: '.'
35-
ShowSummaryOnSuccess:
36-
type: boolean
37-
description: Whether to show the super-linter summary on success.
38-
required: false
39-
default: false
8+
description: The complete settings object.
9+
required: true
4010

4111
permissions:
4212
contents: read # to checkout the repo
@@ -57,30 +27,30 @@ jobs:
5727
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
5828
with:
5929
name: module
60-
path: ${{ inputs.WorkingDirectory }}/outputs/module
30+
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/module
6131

6232
- name: Document module
6333
uses: PSModule/Document-PSModule@15dc407c99e408fc0a4023d4f16aee2a5507ba74 # v1.0.12
6434
with:
65-
Name: ${{ inputs.Name }}
66-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
35+
Name: ${{ fromJson(inputs.Settings).Name }}
36+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
6737

6838
- name: Upload docs artifact
6939
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
7040
with:
7141
name: docs
72-
path: ${{ inputs.WorkingDirectory }}/outputs/docs
42+
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/docs
7343
if-no-files-found: error
7444
retention-days: 1
7545

7646
- name: Commit all changes
7747
uses: PSModule/GitHub-Script@8b9d2739d6896975c0e5448d2021ae2b94b6766a # v1.7.6
7848
with:
79-
Debug: ${{ inputs.Debug }}
80-
Prerelease: ${{ inputs.Prerelease }}
81-
Verbose: ${{ inputs.Verbose }}
82-
Version: ${{ inputs.Version }}
83-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
49+
Debug: ${{ fromJson(inputs.Settings).Debug }}
50+
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
51+
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
52+
Version: ${{ fromJson(inputs.Settings).Version }}
53+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
8454
Script: |
8555
# Rename the gitignore file to .gitignore.bak
8656
if (Test-Path -Path .gitignore) {
@@ -106,8 +76,8 @@ jobs:
10676
env:
10777
RUN_LOCAL: true
10878
DEFAULT_BRANCH: main
109-
DEFAULT_WORKSPACE: ${{ inputs.WorkingDirectory }}
110-
FILTER_REGEX_INCLUDE: ${{ inputs.WorkingDirectory }}/outputs/docs
79+
DEFAULT_WORKSPACE: ${{ fromJson(inputs.Settings).WorkingDirectory }}
80+
FILTER_REGEX_INCLUDE: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/docs
11181
ENABLE_GITHUB_ACTIONS_GROUP_TITLE: true
11282
GITHUB_TOKEN: ${{ github.token }}
11383
VALIDATE_ALL_CODEBASE: true
@@ -123,7 +93,7 @@ jobs:
12393
SAVE_SUPER_LINTER_SUMMARY: true
12494

12595
- name: Post super-linter summary
126-
if: failure() || inputs.ShowSummaryOnSuccess == true
96+
if: failure() || fromJson(inputs.Settings).Build.Docs.ShowSummaryOnSuccess == true
12797
shell: pwsh
12898
run: |
12999
$summaryPath = Join-Path $env:GITHUB_WORKSPACE 'super-linter-output' 'super-linter-summary.md'

.github/workflows/Build-Module.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@ name: Build-Module
33
on:
44
workflow_call:
55
inputs:
6-
Name:
6+
Settings:
77
type: string
8-
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
9-
required: false
8+
description: The settings object as a JSON string.
9+
required: true
1010
ArtifactName:
1111
type: string
1212
description: Name of the artifact to upload.
1313
required: false
1414
default: module
15-
WorkingDirectory:
16-
type: string
17-
description: The working directory where the script will run from.
18-
required: false
19-
default: '.'
2015

2116
permissions:
2217
contents: read # to checkout the repository
@@ -37,6 +32,6 @@ jobs:
3732
- name: Build module
3833
uses: PSModule/Build-PSModule@fe8cc14a7192066cc46cb9514659772ebde05849 # v4.0.9
3934
with:
40-
Name: ${{ inputs.Name }}
35+
Name: ${{ fromJson(inputs.Settings).Name }}
4136
ArtifactName: ${{ inputs.ArtifactName }}
42-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
37+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}

.github/workflows/Build-Site.yml

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,10 @@ name: Build-Site
33
on:
44
workflow_call:
55
inputs:
6-
Name:
6+
Settings:
77
type: string
8-
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
9-
required: false
10-
Debug:
11-
type: boolean
12-
description: Enable debug output.
13-
required: false
14-
default: false
15-
Verbose:
16-
type: boolean
17-
description: Enable verbose output.
18-
required: false
19-
default: false
20-
Version:
21-
type: string
22-
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
23-
required: false
24-
default: ''
25-
Prerelease:
26-
type: boolean
27-
description: Whether to use a prerelease version of the 'GitHub' module.
28-
required: false
29-
default: false
30-
WorkingDirectory:
31-
type: string
32-
description: The working directory where the script will run from.
33-
required: false
34-
default: '.'
8+
description: The complete settings object.
9+
required: true
3510

3611
permissions:
3712
contents: read # to checkout the repo
@@ -54,7 +29,7 @@ jobs:
5429
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
5530
with:
5631
name: docs
57-
path: ${{ inputs.WorkingDirectory }}/outputs/docs
32+
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/docs
5833

5934
- name: Install mkdocs-material
6035
shell: pwsh
@@ -67,16 +42,16 @@ jobs:
6742
- name: Structure site
6843
uses: PSModule/GitHub-Script@8b9d2739d6896975c0e5448d2021ae2b94b6766a # v1.7.6
6944
with:
70-
Debug: ${{ inputs.Debug }}
71-
Prerelease: ${{ inputs.Prerelease }}
72-
Verbose: ${{ inputs.Verbose }}
73-
Version: ${{ inputs.Version }}
74-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
45+
Debug: ${{ fromJson(inputs.Settings).Debug }}
46+
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
47+
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
48+
Version: ${{ fromJson(inputs.Settings).Version }}
49+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
7550
Script: |
7651
LogGroup "Get folder structure" {
7752
$functionDocsFolder = New-Item -Path "outputs/site/docs/Functions" -ItemType Directory -Force
7853
Copy-Item -Path "outputs/docs/*" -Destination "outputs/site/docs/Functions" -Recurse -Force
79-
$moduleName = [string]::IsNullOrEmpty('${{ inputs.Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ inputs.Name }}'
54+
$moduleName = [string]::IsNullOrEmpty('${{ fromJson(inputs.Settings).Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ fromJson(inputs.Settings).Name }}'
8055
$ModuleSourcePath = Resolve-Path 'src' | Select-Object -ExpandProperty Path
8156
$SiteOutputPath = Resolve-Path 'outputs/site' | Select-Object -ExpandProperty Path
8257
@@ -162,7 +137,7 @@ jobs:
162137
}
163138
164139
- name: Build mkdocs-material project
165-
working-directory: ${{ inputs.WorkingDirectory }}/outputs/site
140+
working-directory: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/site
166141
shell: pwsh
167142
run: |
168143
LogGroup 'Build docs - mkdocs build - content' {
@@ -176,5 +151,5 @@ jobs:
176151
- uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
177152
with:
178153
name: github-pages
179-
path: ${{ inputs.WorkingDirectory }}/_site
154+
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/_site
180155
retention-days: 1

.github/workflows/Get-CodeCoverage.yml

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,10 @@ name: Get-CodeCoverage
33
on:
44
workflow_call:
55
inputs:
6-
StepSummary_Mode:
6+
Settings:
77
type: string
8-
description: |
9-
Controls which sections to show in the GitHub step summary.
10-
Use 'Full' for all sections, 'None' to disable, or a comma-separated list of 'Missed, Executed, Files'.
11-
required: false
12-
default: Missed, Files
13-
CodeCoveragePercentTarget:
14-
type: number
15-
description: The target for code coverage.
16-
Debug:
17-
type: boolean
18-
description: Enable debug output.
19-
required: false
20-
default: false
21-
Verbose:
22-
type: boolean
23-
description: Enable verbose output.
24-
required: false
25-
default: false
26-
Version:
27-
type: string
28-
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
29-
required: false
30-
default: ''
31-
Prerelease:
32-
type: boolean
33-
description: Whether to use a prerelease version of the 'GitHub' module.
34-
required: false
35-
default: false
36-
WorkingDirectory:
37-
type: string
38-
description: The working directory where the script will run from.
39-
required: false
40-
default: '.'
8+
description: The complete settings object.
9+
required: true
4110

4211
permissions:
4312
contents: read # to checkout the repo
@@ -51,10 +20,10 @@ jobs:
5120
uses: PSModule/Get-PesterCodeCoverage@a7923eefbf55b452f9b1534c5b50ca9bd192f810 # v1.0.3
5221
id: Get-CodeCoverage
5322
with:
54-
CodeCoveragePercentTarget: ${{ inputs.CodeCoveragePercentTarget }}
55-
StepSummary_Mode: ${{ inputs.StepSummary_Mode }}
56-
Debug: ${{ inputs.Debug }}
57-
Prerelease: ${{ inputs.Prerelease }}
58-
Verbose: ${{ inputs.Verbose }}
59-
Version: ${{ inputs.Version }}
60-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
23+
CodeCoveragePercentTarget: ${{ fromJson(inputs.Settings).Test.CodeCoverage.PercentTarget }}
24+
StepSummary_Mode: ${{ fromJson(inputs.Settings).Test.CodeCoverage.StepSummaryMode }}
25+
Debug: ${{ fromJson(inputs.Settings).Debug }}
26+
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
27+
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
28+
Version: ${{ fromJson(inputs.Settings).Version }}
29+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}

0 commit comments

Comments
 (0)