Skip to content

Commit 0760d85

Browse files
committed
refactor: eliminate boilerplate in set-matrix steps
Replace repetitive if-blocks with automatic extraction of changed modules using toJSON() and jq filtering. This drastically reduces code duplication and maintenance burden. Changes: - lint.yml: replace 14 if-blocks (64 lines) with single jq filter (4 lines) - test-e2e.yml: replace 3 if-blocks with config JSON + jq mapping - Use toJSON(steps.filter.outputs) to get all filter results - Use jq to extract only modules where value == "true" - test-e2e.yml: define module configs in clean JSON format
1 parent bb40dc3 commit 0760d85

2 files changed

Lines changed: 45 additions & 60 deletions

File tree

.github/workflows/lint.yml

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,10 @@ jobs:
2828
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
2929
runs-on: ubuntu-latest
3030
outputs:
31-
payments: ${{ steps.filter.outputs.payments }}
32-
user: ${{ steps.filter.outputs.user }}
33-
chat: ${{ steps.filter.outputs.chat }}
34-
common-styling: ${{ steps.filter.outputs.common-styling }}
35-
tests: ${{ steps.filter.outputs.tests }}
36-
core: ${{ steps.filter.outputs.core }}
37-
oauth-facebook: ${{ steps.filter.outputs.oauth-facebook }}
38-
oauth-github: ${{ steps.filter.outputs.oauth-github }}
39-
oauth-google: ${{ steps.filter.outputs.oauth-google }}
40-
openai: ${{ steps.filter.outputs.openai }}
41-
reports: ${{ steps.filter.outputs.reports }}
42-
data-export-api: ${{ steps.filter.outputs.data-export-api }}
43-
payments-stripe: ${{ steps.filter.outputs.payments-stripe }}
44-
payments-example-gateway: ${{ steps.filter.outputs.payments-example-gateway }}
31+
changed-modules: ${{ steps.set-matrix.outputs.matrix }}
4532
steps:
4633
- uses: actions/checkout@v4
47-
34+
4835
- uses: dorny/paths-filter@v3
4936
id: filter
5037
with:
@@ -78,55 +65,38 @@ jobs:
7865
payments-example-gateway:
7966
- 'pos-module-payments-example-gateway/**'
8067
68+
- name: Set matrix for changed modules
69+
id: set-matrix
70+
run: |
71+
# Extract module names where filter output is "true"
72+
modules=$(echo '${{ toJSON(steps.filter.outputs) }}' | jq -c '[to_entries[] | select(.value == "true") | .key]')
73+
74+
echo "matrix=$modules" >> $GITHUB_OUTPUT
75+
echo "Changed modules for linting: $modules"
76+
8177
lint-platformos-check:
8278
needs: detect-changes
79+
if: needs.detect-changes.outputs.changed-modules != '[]'
8380
runs-on: ubuntu-latest
8481
strategy:
8582
matrix:
86-
module:
87-
- payments
88-
- user
89-
- chat
90-
- common-styling
91-
- tests
92-
- core
93-
- oauth-facebook
94-
- oauth-github
95-
- oauth-google
96-
- openai
97-
- reports
98-
- data-export-api
99-
- payments-stripe
100-
- payments-example-gateway
83+
module: ${{ fromJSON(needs.detect-changes.outputs.changed-modules) }}
10184
fail-fast: false
10285
env:
10386
CI: true
10487
PLATFORMOS_CHECK_DEBUG: true
10588
DOCKER_WORKSPACE: ${{ github.workspace }}/pos-module-${{ matrix.module }}
10689
LOGS_DIR: ${{ github.workspace }}/pos-module-${{ matrix.module }}/logs
10790
steps:
108-
- name: Check if this module changed
109-
id: changed
110-
run: |
111-
MODULE_CHANGED="${{ needs.detect-changes.outputs[matrix.module] }}"
112-
if [ "$MODULE_CHANGED" != "true" ]; then
113-
echo "skip=true" >> $GITHUB_OUTPUT
114-
else
115-
echo "skip=false" >> $GITHUB_OUTPUT
116-
fi
117-
11891
- name: Checkout code
119-
if: steps.changed.outputs.skip != 'true'
12092
uses: actions/checkout@v4
12193

12294
- name: Set up logs directory
123-
if: steps.changed.outputs.skip != 'true'
12495
run: |
12596
mkdir -p ${{ env.LOGS_DIR }}
12697
chmod -R 777 ${{ env.LOGS_DIR }}
12798
12899
- name: Start PlatformOS LSP
129-
if: steps.changed.outputs.skip != 'true'
130100
id: start_lsp
131101
run: |
132102
docker run -i \
@@ -137,7 +107,7 @@ jobs:
137107
platformos/platformos-lsp:latest
138108
139109
- name: Run platformos-check
140-
if: steps.changed.outputs.skip != 'true' && steps.start_lsp.outcome == 'success'
110+
if: steps.start_lsp.outcome == 'success'
141111
id: run_check
142112
run: |
143113
set +e # Disable exit on error
@@ -155,7 +125,7 @@ jobs:
155125
exit $docker_exit_code
156126
157127
- name: Upload logs
158-
if: always() && steps.changed.outputs.skip != 'true' && steps.run_check.outcome != 'skipped'
128+
if: always() && steps.run_check.outcome != 'skipped'
159129
uses: actions/upload-artifact@v4
160130
with:
161131
name: platformos_check_logs_${{ matrix.module }}_${{ github.run_id }}
@@ -165,7 +135,7 @@ jobs:
165135
${{ env.LOGS_DIR }}/platformos-check-raw.json
166136
167137
- name: Generate summary
168-
if: always() && steps.changed.outputs.skip != 'true' && steps.run_check.outcome != 'skipped'
138+
if: always() && steps.run_check.outcome != 'skipped'
169139
run: |
170140
echo "# PlatformOS Check Summary - ${{ matrix.module }} :checkered_flag:" >> $GITHUB_STEP_SUMMARY
171141
echo "## Result: ${{ steps.run_check.outcome }} ${{ env.RESULT_ICON }}" >> $GITHUB_STEP_SUMMARY
@@ -183,7 +153,7 @@ jobs:
183153
RESULT_ICON: ${{ steps.run_check.outcome == 'success' && ':white_check_mark:' || ':x:' }}
184154

185155
- name: Fail job if platformos-check failed
186-
if: always() && steps.changed.outputs.skip != 'true' && steps.run_check.outcome == 'failure'
156+
if: always() && steps.run_check.outcome == 'failure'
187157
run: |
188158
echo "platformos-check failed — marking job as failed"
189159
exit 1

.github/workflows/test-e2e.yml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,34 @@ jobs:
4545
- name: Set matrix for changed modules
4646
id: set-matrix
4747
run: |
48-
modules='[]'
49-
50-
if [ "${{ steps.filter.outputs.user }}" == "true" ]; then
51-
modules=$(echo "$modules" | jq -c '. += [{"module":"user","path":"pos-module-user","deploy-script":"rm app/pos-modules.* || true\nsh ./tests/data/seed/seed.sh","test-commands":"npm run admin-panel-pw-tests\nnpm run pw-tests"}]')
52-
fi
53-
54-
if [ "${{ steps.filter.outputs.chat }}" == "true" ]; then
55-
modules=$(echo "$modules" | jq -c '. += [{"module":"chat","path":"pos-module-chat","deploy-script":"rm app/pos-modules.* || true\nsh ./tests/data/seed/seed.sh","test-commands":"npm run pw-tests"}]')
56-
fi
57-
58-
if [ "${{ steps.filter.outputs.common-styling }}" == "true" ]; then
59-
modules=$(echo "$modules" | jq -c '. += [{"module":"common-styling","path":"pos-module-common-styling","deploy-script":"pos-cli data clean --include-schema --auto-confirm\npos-cli deploy","test-commands":"npm run pw-tests"}]')
60-
fi
48+
# Define module configurations
49+
cat > /tmp/module-config.json << 'EOF'
50+
{
51+
"user": {
52+
"module": "user",
53+
"path": "pos-module-user",
54+
"deploy-script": "rm app/pos-modules.* || true\nsh ./tests/data/seed/seed.sh",
55+
"test-commands": "npm run admin-panel-pw-tests\nnpm run pw-tests"
56+
},
57+
"chat": {
58+
"module": "chat",
59+
"path": "pos-module-chat",
60+
"deploy-script": "rm app/pos-modules.* || true\nsh ./tests/data/seed/seed.sh",
61+
"test-commands": "npm run pw-tests"
62+
},
63+
"common-styling": {
64+
"module": "common-styling",
65+
"path": "pos-module-common-styling",
66+
"deploy-script": "pos-cli data clean --include-schema --auto-confirm\npos-cli deploy",
67+
"test-commands": "npm run pw-tests"
68+
}
69+
}
70+
EOF
71+
72+
# Extract changed modules and map to their configurations
73+
modules=$(echo '${{ toJSON(steps.filter.outputs) }}' | \
74+
jq -c --slurpfile config /tmp/module-config.json \
75+
'[to_entries[] | select(.value == "true") | .key as $m | $config[0][$m] | select(. != null)]')
6176
6277
echo "matrix=$modules" >> $GITHUB_OUTPUT
6378
echo "Changed modules matrix: $modules"

0 commit comments

Comments
 (0)