Skip to content

Commit f8a8aaf

Browse files
chore: Enhance CI workflow to always lint all modules in case of .env changes (#1728)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it Change module discovery to emit all modules in case of .env changes to always lint all modules in such a case. --------- Signed-off-by: Gerald Morrison (SAP) <gerald.morrison@sap.com> Co-authored-by: Gerald Morrison (SAP) <gerald.morrison@sap.com>
1 parent fd227ec commit f8a8aaf

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ jobs:
2525
permissions:
2626
pull-requests: read
2727
outputs:
28-
# useful for working directly with modules
28+
# modules_json = changed modules only (filtered by paths)
2929
modules_json: ${{ steps.filtered.outputs.modules_json }}
30+
# lint_modules_json = all modules when .env changed, else changed modules
31+
lint_modules_json: ${{ steps.filtered.outputs.lint_modules_json }}
3032
integration_test_modules_json: ${{ steps.filtered_test.outputs.integration_test_modules_json }}
3133
unit_test_modules_json: ${{ steps.filtered_test.outputs.unit_test_modules_json }}
3234
env_changed: ${{ steps.env_changes.outputs.env }}
@@ -42,6 +44,13 @@ jobs:
4244
with:
4345
repository: ${{ env.REPO }}
4446
ref: ${{ env.REF }}
47+
# Detect .env changes to decide whether to run golangci-lint on all or only changed modules
48+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
49+
id: env_changes
50+
with:
51+
filters: |
52+
env:
53+
- '.env'
4554
- name: Discover Go Modules
4655
id: discover
4756
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
@@ -82,23 +91,19 @@ jobs:
8291
id: changes
8392
with:
8493
filters: ${{ steps.discover.outputs.filters }}
85-
# Detect .env changes separately to not interfere with module filtering
86-
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
87-
id: env_changes
88-
with:
89-
filters: |
90-
env:
91-
- '.env'
9294
- name: Filter JSONs Based on Changes
9395
id: filtered
9496
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
9597
env:
9698
MODULES_JSON: ${{ steps.discover.outputs.modules_json }}
9799
CHANGE_JSON: ${{ steps.changes.outputs.changes }}
100+
ENV_CHANGED: ${{ steps.env_changes.outputs.env }}
98101
with:
99102
script: |
100103
const modulesJson = JSON.parse(process.env.MODULES_JSON || '[]');
101104
const changeJson = JSON.parse(process.env.CHANGE_JSON || '[]');
105+
const envChanged = process.env.ENV_CHANGED === 'true';
106+
const lintModulesFromEnv = envChanged ? modulesJson : null;
102107
103108
if (process.env.check_only_changed === "true") {
104109
console.log(`Filtering modules based on changes: ${JSON.stringify(changeJson)}`);
@@ -107,9 +112,11 @@ jobs:
107112
});
108113
console.log(`Filtered modules: ${JSON.stringify(filteredModules)}`);
109114
core.setOutput("modules_json", JSON.stringify(filteredModules));
115+
core.setOutput('lint_modules_json', JSON.stringify(lintModulesFromEnv ?? filteredModules));
110116
} else {
111117
console.log("check_only_changed is false, no filtering applied.");
112118
core.setOutput("modules_json", JSON.stringify(modulesJson));
119+
core.setOutput('lint_modules_json', JSON.stringify(lintModulesFromEnv ?? modulesJson));
113120
}
114121
- name: Filter based on Testability
115122
id: filtered_test
@@ -152,6 +159,7 @@ jobs:
152159
script: |
153160
const modules = JSON.parse(`${{ steps.discover.outputs.modules_json || '[]' }}`);
154161
const filtered = JSON.parse(`${{ steps.filtered.outputs.modules_json || '[]' }}`);
162+
const envChanged = `${{ steps.env_changes.outputs.env || 'false' }}` === 'true';
155163
const unitTests = JSON.parse(`${{ steps.filtered_test.outputs.unit_test_modules_json || '[]' }}`);
156164
const integrationTests = JSON.parse(`${{ steps.filtered_test.outputs.integration_test_modules_json || '[]' }}`);
157165
@@ -163,6 +171,7 @@ jobs:
163171
164172
summary += `**🔍 Discovered Modules (${modules.length}):**\n${toMarkdownList(modules)}\n\n`;
165173
summary += `**🎯 Filtered Modules (${filtered.length}):**\n${toMarkdownList(filtered)}\n\n`;
174+
summary += `**🧹 Lint Scope:** ${envChanged ? 'all modules (env changed)' : 'changed modules only'}\n\n`;
166175
summary += `**🧪 Unit Test Modules (${unitTests.length}):**\n${toMarkdownList(unitTests)}\n\n`;
167176
summary += `**🧬 Integration Test Modules (${integrationTests.length}):**\n${toMarkdownList(integrationTests)}\n`;
168177
@@ -205,11 +214,11 @@ jobs:
205214
permissions:
206215
# Optional: allow write access to checks to allow the action to annotate code in the PR.
207216
checks: write
208-
# Run if modules exist OR .env changed as it may affect golangci-lint version
209-
if: ${{ fromJSON(needs.discover_modules.outputs.modules_json)[0] != null || needs.discover_modules.outputs.env_changed == 'true' }}
217+
# Run for all modules when .env changed, else only for changed modules)
218+
if: ${{ fromJSON(needs.discover_modules.outputs.lint_modules_json)[0] != null }}
210219
strategy:
211220
matrix:
212-
module: ${{ fromJSON(needs.discover_modules.outputs.modules_json) }}
221+
module: ${{ fromJSON(needs.discover_modules.outputs.lint_modules_json) }}
213222
steps:
214223
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
215224
with:
@@ -386,7 +395,7 @@ jobs:
386395
- run_unit_tests
387396
- run_integration_tests
388397
- golangci_lint
389-
if: failure()
398+
if: ${{ failure() }}
390399
steps:
391400
- name: Some CI step failed or was cancelled!
392401
run: exit 1

0 commit comments

Comments
 (0)