Skip to content

Commit 1d217f4

Browse files
ci: optimize docker build matrix to run only on modified services
1 parent a6270f1 commit 1d217f4

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

.github/workflows/docker-build-push.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,50 @@ env:
99
REGISTRY: ghcr.io
1010

1111
jobs:
12+
detect-changes:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
matrix: ${{ steps.set-matrix.outputs.matrix }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: dorny/paths-filter@v3
19+
id: filter
20+
with:
21+
filters: |
22+
tracker:
23+
- 'apps/tracker/**'
24+
- 'packages/**'
25+
- 'package.json'
26+
- 'package-lock.json'
27+
cron:
28+
- 'apps/cron/**'
29+
- 'packages/**'
30+
- 'package.json'
31+
- 'package-lock.json'
32+
ws:
33+
- 'apps/ws/**'
34+
- 'packages/**'
35+
- 'package.json'
36+
- 'package-lock.json'
37+
- id: set-matrix
38+
run: |
39+
MATRIX="[]"
40+
if [[ "${{ steps.filter.outputs.tracker }}" == "true" ]]; then MATRIX=$(echo $MATRIX | jq '. += ["tracker"]'); fi
41+
if [[ "${{ steps.filter.outputs.cron }}" == "true" ]]; then MATRIX=$(echo $MATRIX | jq '. += ["cron"]'); fi
42+
if [[ "${{ steps.filter.outputs.ws }}" == "true" ]]; then MATRIX=$(echo $MATRIX | jq '. += ["ws"]'); fi
43+
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
44+
1245
build-and-push:
46+
needs: detect-changes
47+
if: ${{ needs.detect-changes.outputs.matrix != '[]' && needs.detect-changes.outputs.matrix != '' }}
1348
runs-on: ubuntu-latest
1449
permissions:
1550
contents: read
1651
packages: write
1752

1853
strategy:
1954
matrix:
20-
service: [tracker, cron, ws]
55+
service: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
2156

2257
steps:
2358
- name: Checkout repository

0 commit comments

Comments
 (0)