KiCad CI #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: KiCad CI | |
| on: | |
| push: | |
| paths: | |
| - 'pmod/**' | |
| - '!pmod/assets/**' | |
| - '!pmod/template/**' | |
| pull_request: | |
| paths: | |
| - 'pmod/**' | |
| - '!pmod/assets/**' | |
| - '!pmod/template/**' | |
| workflow_dispatch: | |
| inputs: | |
| project_filter: | |
| description: 'Filter by specific project (optional)' | |
| required: false | |
| default: '' | |
| type: string | |
| jobs: | |
| kicad_checks: | |
| runs-on: ubuntu-latest | |
| name: KiCad DRC and 3D Export | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Find KiCad projects | |
| id: find_projects | |
| run: | | |
| echo "Searching for KiCad projects in pmod directory..." | |
| # If manual run with project filter, only look for that specific project | |
| if [ -n "${{ github.event.inputs.project_filter }}" ]; then | |
| echo "Filtering for project: ${{ github.event.inputs.project_filter }}" | |
| PROJECTS=$(find pmod -name "*.kicad_pro" -path "*/${{ github.event.inputs.project_filter }}/KiCad/*" | sed 's|/KiCad/.*\.kicad_pro||' | sort -u) | |
| else | |
| PROJECTS=$(find pmod -name "*.kicad_pro" -path "*/KiCad/*" | sed 's|/KiCad/.*\.kicad_pro||' | sort -u) | |
| fi | |
| if [ -z "$PROJECTS" ]; then | |
| echo "No KiCad projects found matching the filter" | |
| echo "projects=" >> $GITHUB_OUTPUT | |
| else | |
| echo "Found projects: $PROJECTS" | |
| echo "projects=$PROJECTS" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Process each KiCad project | |
| run: | | |
| # Check if any projects were found | |
| if [ -z "${{ steps.find_projects.outputs.projects }}" ]; then | |
| echo "No KiCad projects found to process" | |
| exit 0 | |
| fi | |
| for PROJECT_PATH in ${{ steps.find_projects.outputs.projects }}; do | |
| echo "Processing project: $PROJECT_PATH" | |
| PROJECT_NAME=$(basename "$PROJECT_PATH") | |
| KICAD_DIR="$PROJECT_PATH/KiCad" | |
| ASSETS_DIR="$PROJECT_PATH/assets" | |
| # Find the main project file (without .kicad_pro extension) | |
| PROJECT_FILE=$(find "$KICAD_DIR" -name "*.kicad_pro" -exec basename {} .kicad_pro \; | head -1) | |
| if [ -n "$PROJECT_FILE" ]; then | |
| echo "Found KiCad project: $PROJECT_FILE" | |
| # Change to the KiCad directory for processing | |
| cd "$KICAD_DIR" | |
| # Run DRC | |
| echo "Running DRC for $PROJECT_FILE..." | |
| pcb_drc_result=0 | |
| /usr/bin/docker run --rm -v "$PWD:/workspace" sparkengineering/kicad-action:latest \ | |
| --kicad_pcb "$PROJECT_FILE.kicad_pcb" --pcb_drc || pcb_drc_result=$? | |
| # Generate 3D render | |
| echo "Generating 3D render for $PROJECT_FILE..." | |
| pcb_3d_result=0 | |
| /usr/bin/docker run --rm -v "$PWD:/workspace" sparkengineering/kicad-action:latest \ | |
| --kicad_pcb "$PROJECT_FILE.kicad_pcb" --pcb_3d --pcb_3d_output "temp_3d.png" || pcb_3d_result=$? | |
| # Create assets directory and move 3D render | |
| if [ $pcb_3d_result -eq 0 ] && [ -f "temp_3d.png" ]; then | |
| echo "Moving 3D render to assets directory..." | |
| mkdir -p "../../assets" | |
| mv "temp_3d.png" "../../assets/default.png" | |
| echo "3D render saved to $PROJECT_PATH/assets/default.png" | |
| fi | |
| # Go back to workspace root | |
| cd "$GITHUB_WORKSPACE" | |
| # Upload artifacts for this project | |
| if [ $pcb_drc_result -ne 0 ] && [ -f "$KICAD_DIR/drc.rpt" ]; then | |
| echo "Uploading DRC report for $PROJECT_NAME" | |
| cp "$KICAD_DIR/drc.rpt" "drc_${PROJECT_NAME}.rpt" | |
| fi | |
| if [ -f "$PROJECT_PATH/assets/default.png" ]; then | |
| echo "Uploading 3D render for $PROJECT_NAME" | |
| cp "$PROJECT_PATH/assets/default.png" "render_${PROJECT_NAME}.png" | |
| fi | |
| else | |
| echo "No KiCad project file found in $KICAD_DIR" | |
| fi | |
| done | |
| # Upload DRC reports only if DRC failed | |
| - name: Upload DRC reports | |
| uses: actions/upload-artifact@v4 | |
| if: ${{ failure() }} | |
| with: | |
| name: drc-reports | |
| path: drc_*.rpt | |
| # Upload 3D renders if generation succeeded | |
| - name: Upload 3D renders | |
| uses: actions/upload-artifact@v4 | |
| if: ${{ !cancelled() }} | |
| with: | |
| name: 3d-renders | |
| path: render_*.png |