Skip to content

Commit 7ebde58

Browse files
Improve change detection in drc-3d-render workflow
Refactor file change detection logic for improved handling of different GitHub event types and conditions.
1 parent 84fdd20 commit 7ebde58

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

.github/workflows/drc-3d-render.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,53 @@ jobs:
2727
steps:
2828
- name: Checkout
2929
uses: actions/checkout@v4
30-
31-
- name: Get changed files
32-
uses: dorny/paths-filter@v2
33-
id: changes
3430
with:
35-
filters: |
36-
pmod_projects:
37-
- 'pmod/**'
38-
- '!pmod/assets/**'
39-
- '!pmod/template/**'
40-
31+
fetch-depth: 0 # Fetch all history for proper diffing
32+
4133
- name: Find changed KiCad projects
4234
id: filter-projects
43-
if: steps.changes.outputs.pmod_projects == 'true'
4435
run: |
4536
echo "Checking for changed files in pmod directory..."
4637
4738
# Get the list of changed files
4839
if [ "${{ github.event_name }}" == "push" ]; then
4940
# For push events, compare with previous commit
50-
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- "pmod/")
51-
else
41+
if [ -n "${{ github.event.before }}" ]; then
42+
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} -- "pmod/")
43+
else
44+
# For initial push or force push, get all files
45+
CHANGED_FILES=$(git log -1 --name-only --oneline ${{ github.sha }} -- "pmod/")
46+
fi
47+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
5248
# For PR events, compare with base branch
5349
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- "pmod/")
50+
else
51+
# For workflow_dispatch or other events, process all projects
52+
echo "Manual trigger - processing all projects"
53+
PROJECTS=$(find pmod -name "*.kicad_pro" -path "*/KiCad/*" | sed 's|/KiCad/.*\.kicad_pro||' | sort -u)
54+
if [ -n "${{ github.event.inputs.project_filter }}" ]; then
55+
echo "Filtering for project: ${{ github.event.inputs.project_filter }}"
56+
PROJECTS=$(echo "$PROJECTS" | grep "${{ github.event.inputs.project_filter }}" || true)
57+
fi
58+
if [ -n "$PROJECTS" ]; then
59+
JSON_PROJECTS=$(echo "$PROJECTS" | jq -R -s -c 'split("\n") | map(select(. != ""))')
60+
echo "projects=$JSON_PROJECTS" >> $GITHUB_OUTPUT
61+
else
62+
echo 'projects=[]' >> $GITHUB_OUTPUT
63+
fi
64+
exit 0
5465
fi
5566
5667
echo "Changed files:"
5768
echo "$CHANGED_FILES"
5869
70+
# If no changed files found, exit early
71+
if [ -z "$CHANGED_FILES" ]; then
72+
echo "No changed files found in pmod directory"
73+
echo 'projects=[]' >> $GITHUB_OUTPUT
74+
exit 0
75+
fi
76+
5977
# Extract unique project directories from changed files
6078
CHANGED_PROJECTS=()
6179
while IFS= read -r file; do

0 commit comments

Comments
 (0)