Skip to content

Commit a84a255

Browse files
Refactor KiCad project detection in workflow
Updated workflow to find changed KiCad projects and handle project filtering. Enhanced error handling and adjusted job dependencies.
1 parent 99e4dd0 commit a84a255

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

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

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,73 @@ on:
2020
type: string
2121

2222
jobs:
23-
find-projects:
23+
find-changed-projects:
2424
runs-on: ubuntu-latest
2525
outputs:
26-
projects: ${{ steps.find-projects.outputs.projects }}
26+
projects: ${{ steps.filter-projects.outputs.projects }}
2727
steps:
2828
- name: Checkout
2929
uses: actions/checkout@v4
3030

31-
- name: Find KiCad projects
32-
id: find-projects
31+
- name: Get changed files
32+
uses: dorny/paths-filter@v2
33+
id: changes
34+
with:
35+
filters: |
36+
pmod_projects:
37+
- 'pmod/**'
38+
- '!pmod/assets/**'
39+
- '!pmod/template/**'
40+
41+
- name: Find changed KiCad projects
42+
id: filter-projects
43+
if: steps.changes.outputs.pmod_projects == 'true'
3344
run: |
34-
echo "Searching for KiCad projects in pmod directory..."
45+
echo "Checking for changed files in pmod directory..."
3546
36-
# If manual run with project filter, only look for that specific project
37-
if [ -n "${{ github.event.inputs.project_filter }}" ]; then
38-
echo "Filtering for project: ${{ github.event.inputs.project_filter }}"
39-
PROJECTS=$(find pmod -name "*.kicad_pro" -path "*/${{ github.event.inputs.project_filter }}/KiCad/*" | sed 's|/KiCad/.*\.kicad_pro||' | sort -u)
47+
# Get the list of changed files
48+
if [ "${{ github.event_name }}" == "push" ]; then
49+
# For push events, compare with previous commit
50+
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- "pmod/")
4051
else
41-
PROJECTS=$(find pmod -name "*.kicad_pro" -path "*/KiCad/*" | sed 's|/KiCad/.*\.kicad_pro||' | sort -u)
52+
# For PR events, compare with base branch
53+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- "pmod/")
4254
fi
4355
44-
if [ -z "$PROJECTS" ]; then
45-
echo "No KiCad projects found matching the filter"
46-
echo 'projects=[]' >> $GITHUB_OUTPUT
47-
else
48-
# Convert to JSON array for matrix output
49-
JSON_PROJECTS=$(echo "$PROJECTS" | jq -R -s -c 'split("\n") | map(select(. != ""))')
50-
echo "Found projects: $JSON_PROJECTS"
56+
echo "Changed files:"
57+
echo "$CHANGED_FILES"
58+
59+
# Extract unique project directories from changed files
60+
CHANGED_PROJECTS=()
61+
while IFS= read -r file; do
62+
if [[ "$file" =~ ^pmod/([^/]+)/ ]]; then
63+
PROJECT_NAME="${BASH_REMATCH[1]}"
64+
# Skip blacklisted directories
65+
if [[ "$PROJECT_NAME" != "assets" && "$PROJECT_NAME" != "template" ]]; then
66+
CHANGED_PROJECTS+=("pmod/$PROJECT_NAME")
67+
fi
68+
fi
69+
done <<< "$CHANGED_FILES"
70+
71+
# Remove duplicates and convert to JSON
72+
if [ ${#CHANGED_PROJECTS[@]} -gt 0 ]; then
73+
UNIQUE_PROJECTS=($(printf "%s\n" "${CHANGED_PROJECTS[@]}" | sort -u))
74+
JSON_PROJECTS=$(printf '%s\n' "${UNIQUE_PROJECTS[@]}" | jq -R -s -c 'split("\n") | map(select(. != ""))')
75+
echo "Changed projects: $JSON_PROJECTS"
5176
echo "projects=$JSON_PROJECTS" >> $GITHUB_OUTPUT
77+
else
78+
echo "No changed projects found"
79+
echo 'projects=[]' >> $GITHUB_OUTPUT
5280
fi
5381
5482
kicad-checks:
55-
needs: find-projects
83+
needs: find-changed-projects
84+
if: needs.find-changed-projects.outputs.projects != '[]'
5685
runs-on: ubuntu-latest
5786
strategy:
5887
matrix:
59-
project: ${{ fromJson(needs.find-projects.outputs.projects) }}
60-
name: KiCad DRC and 3D Export - ${{ matrix.project }}
88+
project: ${{ fromJson(needs.find-changed-projects.outputs.projects) }}
89+
name: KiCad DRC and 3D Export - ${{ fromJson(matrix.project) }}
6190
steps:
6291
- name: Checkout
6392
uses: actions/checkout@v4
@@ -74,24 +103,30 @@ jobs:
74103
id: project-file
75104
run: |
76105
KICAD_DIR="${{ matrix.project }}/KiCad"
77-
PROJECT_FILE=$(find "$KICAD_DIR" -name "*.kicad_pro" -exec basename {} .kicad_pro \; | head -1)
78-
if [ -n "$PROJECT_FILE" ]; then
79-
echo "project_file=$PROJECT_FILE" >> $GITHUB_OUTPUT
80-
echo "kicad_dir=$KICAD_DIR" >> $GITHUB_OUTPUT
106+
if [ -d "$KICAD_DIR" ]; then
107+
PROJECT_FILE=$(find "$KICAD_DIR" -name "*.kicad_pro" -exec basename {} .kicad_pro \; | head -1)
108+
if [ -n "$PROJECT_FILE" ]; then
109+
echo "project_file=$PROJECT_FILE" >> $GITHUB_OUTPUT
110+
echo "kicad_dir=$KICAD_DIR" >> $GITHUB_OUTPUT
111+
else
112+
echo "No KiCad project file found in $KICAD_DIR"
113+
exit 1
114+
fi
81115
else
82-
echo "No KiCad project file found in $KICAD_DIR"
116+
echo "KiCad directory not found: $KICAD_DIR"
83117
exit 1
84118
fi
85119
86120
- name: Create assets directory
87121
run: |
88122
mkdir -p "${{ matrix.project }}/assets"
89123
90-
- name: Run KiCad DRC
124+
- name: Run KiCad DRC (continue on error)
91125
uses: sparkengineering/kicad-action@v4
92126
with:
93127
kicad_pcb: "${{ steps.project-file.outputs.kicad_dir }}/${{ steps.project-file.outputs.project_file }}.kicad_pcb"
94128
pcb_drc: true
129+
continue-on-error: true
95130

96131
- name: Generate 3D render
97132
uses: sparkengineering/kicad-action@v4

0 commit comments

Comments
 (0)