Skip to content

Commit 7be2509

Browse files
feat: update workflow conditions to handle closed pull requests and improve job execution logic
1 parent 55941e0 commit 7be2509

File tree

1 file changed

+92
-13
lines changed

1 file changed

+92
-13
lines changed

.github/workflows/workflow.yml

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ permissions:
7171
id-token: write # to verify the deployment originates from an appropriate source
7272

7373
jobs:
74+
# Runs on:
75+
# - ✅ Open/Updated PR - Always runs to load configuration
76+
# - ✅ Merged PR - Always runs to load configuration
77+
# - ✅ Abandoned PR - Always runs to load configuration
78+
# - ✅ Manual run - Always runs to load configuration
7479
Get-Settings:
7580
uses: ./.github/workflows/Get-Settings.yml
7681
with:
@@ -82,10 +87,15 @@ jobs:
8287
Version: ${{ inputs.Version }}
8388
WorkingDirectory: ${{ inputs.WorkingDirectory }}
8489

90+
# Runs on:
91+
# - ✅ Open/Updated PR - Lints code changes in active PRs
92+
# - ❌ Merged PR - No need to lint after merge + its a merge commit that causes issues with super-linter
93+
# - ❌ Abandoned PR - No need to lint abandoned changes
94+
# - ❌ Manual run - Only runs for PR events
8595
Lint-Repository:
8696
name: Lint code base
8797
runs-on: ubuntu-latest
88-
if: github.event_name == 'pull_request' && github.event.pull_request.merged != true
98+
if: github.event_name == 'pull_request' && github.event.pull_request.merged != true && github.event.action != 'closed'
8999
needs:
90100
- Get-Settings
91101
steps:
@@ -106,17 +116,27 @@ jobs:
106116
VALIDATE_MARKDOWN_PRETTIER: false
107117
VALIDATE_YAML_PRETTIER: false
108118

119+
# Runs on:
120+
# - ✅ Open/Updated PR - Builds module for testing
121+
# - ✅ Merged PR - Builds module for publishing
122+
# - ❌ Abandoned PR - Skips building abandoned changes
123+
# - ✅ Manual run - Builds module when manually triggered
109124
Build-Module:
110-
if: ${{ fromJson(needs.Get-Settings.outputs.Settings).Build.Module.Skip != true }}
125+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && fromJson(needs.Get-Settings.outputs.Settings).Build.Module.Skip != true }}
111126
uses: ./.github/workflows/Build-Module.yml
112127
needs:
113128
- Get-Settings
114129
with:
115130
Name: ${{ fromJson(needs.Get-Settings.outputs.Settings).Name }}
116131
WorkingDirectory: ${{ inputs.WorkingDirectory }}
117132

133+
# Runs on:
134+
# - ✅ Open/Updated PR - Builds documentation for review
135+
# - ✅ Merged PR - Builds documentation for publishing
136+
# - ❌ Abandoned PR - Skips building docs for abandoned changes
137+
# - ✅ Manual run - Builds documentation when manually triggered
118138
Build-Docs:
119-
if: ${{ fromJson(needs.Get-Settings.outputs.Settings).Build.Docs.Skip != true }}
139+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && fromJson(needs.Get-Settings.outputs.Settings).Build.Docs.Skip != true }}
120140
needs:
121141
- Get-Settings
122142
- Build-Module
@@ -129,8 +149,13 @@ jobs:
129149
Version: ${{ inputs.Version }}
130150
WorkingDirectory: ${{ inputs.WorkingDirectory }}
131151

152+
# Runs on:
153+
# - ✅ Open/Updated PR - Builds site for preview
154+
# - ✅ Merged PR - Builds site for publishing
155+
# - ❌ Abandoned PR - Skips building site for abandoned changes
156+
# - ✅ Manual run - Builds site when manually triggered
132157
Build-Site:
133-
if: ${{ fromJson(needs.Get-Settings.outputs.Settings).Build.Site.Skip != true }}
158+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && fromJson(needs.Get-Settings.outputs.Settings).Build.Site.Skip != true }}
134159
needs:
135160
- Get-Settings
136161
- Build-Docs
@@ -143,8 +168,13 @@ jobs:
143168
Version: ${{ inputs.Version }}
144169
WorkingDirectory: ${{ inputs.WorkingDirectory }}
145170

171+
# Runs on:
172+
# - ✅ Open/Updated PR - Tests source code changes
173+
# - ✅ Merged PR - Tests source code before publishing
174+
# - ❌ Abandoned PR - Skips testing abandoned changes
175+
# - ✅ Manual run - Tests source code when manually triggered
146176
Test-SourceCode:
147-
if: ${{ needs.Get-Settings.outputs.SourceCodeTestSuites != '[]' }}
177+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Get-Settings.outputs.SourceCodeTestSuites != '[]' }}
148178
needs:
149179
- Get-Settings
150180
strategy:
@@ -162,8 +192,13 @@ jobs:
162192
Version: ${{ inputs.Version }}
163193
WorkingDirectory: ${{ inputs.WorkingDirectory }}
164194

195+
# Runs on:
196+
# - ✅ Open/Updated PR - Lints source code changes
197+
# - ✅ Merged PR - Lints source code before publishing
198+
# - ❌ Abandoned PR - Skips linting abandoned changes
199+
# - ✅ Manual run - Lints source code when manually triggered
165200
Lint-SourceCode:
166-
if: ${{ needs.Get-Settings.outputs.SourceCodeTestSuites != '[]' }}
201+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Get-Settings.outputs.SourceCodeTestSuites != '[]' }}
167202
needs:
168203
- Get-Settings
169204
strategy:
@@ -181,8 +216,13 @@ jobs:
181216
Version: ${{ inputs.Version }}
182217
WorkingDirectory: ${{ inputs.WorkingDirectory }}
183218

219+
# Runs on:
220+
# - ✅ Open/Updated PR - Tests built module
221+
# - ✅ Merged PR - Tests built module before publishing
222+
# - ❌ Abandoned PR - Skips testing abandoned changes
223+
# - ✅ Manual run - Tests built module when manually triggered
184224
Test-Module:
185-
if: ${{ needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.PSModuleTestSuites != '[]' }}
225+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.PSModuleTestSuites != '[]' }}
186226
needs:
187227
- Build-Module
188228
- Get-Settings
@@ -202,8 +242,13 @@ jobs:
202242
Version: ${{ inputs.Version }}
203243
WorkingDirectory: ${{ inputs.WorkingDirectory }}
204244

245+
# Runs on:
246+
# - ✅ Open/Updated PR - Runs setup scripts before local module tests
247+
# - ✅ Merged PR - Runs setup scripts before local module tests
248+
# - ❌ Abandoned PR - Skips setup for abandoned changes
249+
# - ✅ Manual run - Runs setup scripts when manually triggered
205250
BeforeAll-ModuleLocal:
206-
if: ${{ needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
251+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
207252
name: BeforeAll-ModuleLocal
208253
runs-on: ubuntu-latest
209254
needs:
@@ -243,8 +288,13 @@ jobs:
243288
}
244289
}
245290
291+
# Runs on:
292+
# - ✅ Open/Updated PR - Tests module in local environment
293+
# - ✅ Merged PR - Tests module in local environment before publishing
294+
# - ❌ Abandoned PR - Skips testing abandoned changes
295+
# - ✅ Manual run - Tests module in local environment when manually triggered
246296
Test-ModuleLocal:
247-
if: ${{ needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
297+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
248298
needs:
249299
- Build-Module
250300
- Get-Settings
@@ -267,6 +317,11 @@ jobs:
267317
Version: ${{ inputs.Version }}
268318
WorkingDirectory: ${{ inputs.WorkingDirectory }}
269319

320+
# Runs on:
321+
# - ✅ Open/Updated PR - Runs teardown scripts after local module tests
322+
# - ✅ Merged PR - Runs teardown scripts after local module tests
323+
# - ✅ Abandoned PR - Runs teardown if tests were started (cleanup)
324+
# - ✅ Manual run - Runs teardown scripts after local module tests
270325
AfterAll-ModuleLocal:
271326
if: ${{ needs.Test-ModuleLocal.result != 'skipped' && always() }}
272327
name: AfterAll-ModuleLocal
@@ -311,8 +366,13 @@ jobs:
311366
}
312367
}
313368
369+
# Runs on:
370+
# - ✅ Open/Updated PR - Collects and reports test results
371+
# - ✅ Merged PR - Collects and reports test results before publishing
372+
# - ❌ Abandoned PR - Skips collecting results for abandoned changes
373+
# - ✅ Manual run - Collects and reports test results when manually triggered
314374
Get-TestResults:
315-
if: needs.Get-Settings.result == 'success' && !fromJson(needs.Get-Settings.outputs.Settings).Test.TestResults.Skip && (needs.Get-Settings.outputs.SourceCodeTestSuites != '[]' || needs.Get-Settings.outputs.PSModuleTestSuites != '[]' || needs.Get-Settings.outputs.ModuleTestSuites != '[]') && (always() && !cancelled())
375+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Get-Settings.result == 'success' && !fromJson(needs.Get-Settings.outputs.Settings).Test.TestResults.Skip && (needs.Get-Settings.outputs.SourceCodeTestSuites != '[]' || needs.Get-Settings.outputs.PSModuleTestSuites != '[]' || needs.Get-Settings.outputs.ModuleTestSuites != '[]') && (always() && !cancelled()) }}
316376
needs:
317377
- Get-Settings
318378
- Test-SourceCode
@@ -330,8 +390,13 @@ jobs:
330390
Verbose: ${{ inputs.Verbose }}
331391
Version: ${{ inputs.Version }}
332392

393+
# Runs on:
394+
# - ✅ Open/Updated PR - Calculates and reports code coverage
395+
# - ✅ Merged PR - Calculates and reports code coverage before publishing
396+
# - ❌ Abandoned PR - Skips coverage for abandoned changes
397+
# - ✅ Manual run - Calculates and reports code coverage when manually triggered
333398
Get-CodeCoverage:
334-
if: needs.Get-Settings.result == 'success' && !fromJson(needs.Get-Settings.outputs.Settings).Test.CodeCoverage.Skip && (needs.Get-Settings.outputs.PSModuleTestSuites != '[]' || needs.Get-Settings.outputs.ModuleTestSuites != '[]') && (always() && !cancelled())
399+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Get-Settings.result == 'success' && !fromJson(needs.Get-Settings.outputs.Settings).Test.CodeCoverage.Skip && (needs.Get-Settings.outputs.PSModuleTestSuites != '[]' || needs.Get-Settings.outputs.ModuleTestSuites != '[]') && (always() && !cancelled()) }}
335400
needs:
336401
- Get-Settings
337402
- Test-Module
@@ -346,8 +411,13 @@ jobs:
346411
Verbose: ${{ inputs.Verbose }}
347412
Version: ${{ inputs.Version }}
348413

414+
# Runs on:
415+
# - ❌ Open/Updated PR - Site not published for PRs in progress
416+
# - ✅ Merged PR - Deploys site to GitHub Pages after successful merge
417+
# - ❌ Abandoned PR - Site not published for abandoned changes
418+
# - ❌ Manual run - Only publishes on merged PRs, not manual runs
349419
Publish-Site:
350-
if: ${{ needs.Get-TestResults.result == 'success' && needs.Get-CodeCoverage.result == 'success' && needs.Build-Site.result == 'success' && !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.merged == true }}
420+
if: ${{ !(github.event.action == 'closed' && github.event.pull_request.merged != true) && needs.Get-TestResults.result == 'success' && needs.Get-CodeCoverage.result == 'success' && needs.Build-Site.result == 'success' && !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.merged == true }}
351421
needs:
352422
- Get-Settings
353423
- Get-TestResults
@@ -367,8 +437,17 @@ jobs:
367437
id: deployment
368438
uses: actions/deploy-pages@v4
369439

440+
# Runs on:
441+
# - ✅ Open/Updated PR - Publishes prerelease when all tests/coverage/build succeed
442+
# - ✅ Merged PR - Publishes release when all tests/coverage/build succeed
443+
# - ✅ Abandoned PR - Publishes cleanup/retraction version
444+
# - ✅ Manual run - Publishes when all tests/coverage/build succeed
370445
Publish-Module:
371-
if: ${{ needs.Get-Settings.result == 'success' && needs.Get-TestResults.result == 'success' && needs.Get-CodeCoverage.result == 'success' && needs.Build-Site.result == 'success' && !cancelled() && github.event_name == 'pull_request' }}
446+
if: |
447+
needs.Get-Settings.result == 'success' && !cancelled() && github.event_name == 'pull_request' && (
448+
(github.event.action == 'closed' && github.event.pull_request.merged != true) ||
449+
(needs.Get-TestResults.result == 'success' && needs.Get-CodeCoverage.result == 'success' && needs.Build-Site.result == 'success')
450+
)
372451
needs:
373452
- Get-Settings
374453
- Get-TestResults

0 commit comments

Comments
 (0)