Skip to content

Commit 03a0f20

Browse files
committed
Improve CI job selection with change detection
Add logic to detect changed files and only run affected jobs (backend/frontend) instead of running everything on every push. Also handle new branches where no parent commit exists.
1 parent af8fac6 commit 03a0f20

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,28 @@ jobs:
2121
frontend: ${{ steps.filter.outputs.frontend }}
2222
steps:
2323
- uses: actions/checkout@v6
24-
- uses: dorny/paths-filter@v3
25-
id: filter
2624
with:
27-
filters: |
28-
backend:
29-
- 'backend/**'
30-
frontend:
31-
- 'frontend/**'
25+
fetch-depth: 2 # need parent commit for push diff
26+
27+
- name: Detect changed paths
28+
id: filter
29+
run: |
30+
# New branch — no parent commit yet, build everything
31+
if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
32+
echo "backend=true" >> $GITHUB_OUTPUT
33+
echo "frontend=true" >> $GITHUB_OUTPUT
34+
exit 0
35+
fi
36+
37+
if [ "${{ github.event_name }}" = "pull_request" ]; then
38+
git fetch origin ${{ github.base_ref }} --depth=1
39+
CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
40+
else
41+
CHANGED=$(git diff --name-only HEAD~1 HEAD)
42+
fi
43+
44+
echo "$CHANGED" | grep -q "^backend/" && echo "backend=true" >> $GITHUB_OUTPUT || echo "backend=false" >> $GITHUB_OUTPUT
45+
echo "$CHANGED" | grep -q "^frontend/" && echo "frontend=true" >> $GITHUB_OUTPUT || echo "frontend=false" >> $GITHUB_OUTPUT
3246
3347
# Build backend + run unit tests
3448
backend:

0 commit comments

Comments
 (0)