simplified workflow
This commit is contained in:
@@ -1,38 +1,34 @@
|
||||
name: "KiBot PCB Generation with Multi-layer Support"
|
||||
name: "KiBot PCB Generation"
|
||||
|
||||
# Controls when the action will run. Triggers the workflow on push or pull request
|
||||
# events but only for the master branch
|
||||
# Controls when the action will run
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**/*.kicad_sch'
|
||||
- '**/*.kicad_pcb'
|
||||
- '**/*.kicad_pro'
|
||||
- '**/*.kibot.yaml'
|
||||
- '**/kibot.yaml'
|
||||
- 'kibot.yaml'
|
||||
- '.gitea/workflows/*.yml'
|
||||
pull_request:
|
||||
paths:
|
||||
- '**/*.kicad_sch'
|
||||
- '**/*.kicad_pcb'
|
||||
- '**/*.kicad_pro'
|
||||
- '**/*.kibot.yaml'
|
||||
- '**/kibot.yaml'
|
||||
- 'kibot.yaml'
|
||||
- '.gitea/workflows/*.yml'
|
||||
repository_dispatch:
|
||||
types: [run_qs]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
board_layers:
|
||||
description: 'Number of PCB layers (auto-detect if not specified)'
|
||||
description: 'Number of PCB layers'
|
||||
required: false
|
||||
default: 'auto'
|
||||
default: '2'
|
||||
type: choice
|
||||
options:
|
||||
- auto
|
||||
- 2
|
||||
- 4
|
||||
- 6
|
||||
- '2'
|
||||
- '4'
|
||||
- '6'
|
||||
|
||||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||
jobs:
|
||||
@@ -77,128 +73,38 @@ jobs:
|
||||
echo "All PCB files found:"
|
||||
echo "$PCB_FILES"
|
||||
|
||||
- name: Detect layer count
|
||||
- name: Set layer count
|
||||
id: layers
|
||||
run: |
|
||||
PCB_FILE="${{ steps.find_project.outputs.pcb_file }}"
|
||||
if [ "${{ github.event.inputs.board_layers }}" != "" ] && [ "${{ github.event.inputs.board_layers }}" != "auto" ]; then
|
||||
echo "layers=${{ github.event.inputs.board_layers }}" >> $GITHUB_OUTPUT
|
||||
echo "Using manually specified ${{ github.event.inputs.board_layers }} layer configuration"
|
||||
else
|
||||
# Create Python script to detect layers
|
||||
cat > /tmp/detect_layers.py << 'PYTHON_SCRIPT'
|
||||
#!/usr/bin/env python3
|
||||
import re
|
||||
import sys
|
||||
|
||||
try:
|
||||
pcb_file = sys.argv[1]
|
||||
with open(pcb_file, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Look for the layers section in the KiCad PCB file
|
||||
# Format: (layers (0 "F.Cu" signal) (4 "In1.Cu" signal) ...)
|
||||
layers_section = re.search(r'\(layers\s*\n([^)]+)\)', content, re.MULTILINE | re.DOTALL)
|
||||
|
||||
if layers_section:
|
||||
layers_text = layers_section.group(0)
|
||||
# Find all layer definitions - match the pattern (number "name" type)
|
||||
layer_matches = re.findall(r'\(\d+\s+"([^"]+)"\s+\w+\)', layers_text)
|
||||
|
||||
# Count copper layers - any layer with .Cu suffix
|
||||
copper_layers = []
|
||||
for layer in layer_matches:
|
||||
if '.Cu' in layer:
|
||||
copper_layers.append(layer)
|
||||
print(f"Found copper layer: {layer}", file=sys.stderr)
|
||||
|
||||
print(len(copper_layers) if copper_layers else 2)
|
||||
else:
|
||||
# Alternative: look for individual layer definitions
|
||||
all_layers = re.findall(r'\(\d+\s+"([^"]+\.Cu)"\s+\w+\)', content)
|
||||
if not all_layers:
|
||||
# Try another pattern
|
||||
all_layers = re.findall(r'"(F\.Cu|B\.Cu|In\d+\.Cu)"', content)
|
||||
|
||||
# Remove duplicates
|
||||
unique_layers = list(set(all_layers))
|
||||
|
||||
for layer in unique_layers:
|
||||
print(f"Found copper layer: {layer}", file=sys.stderr)
|
||||
|
||||
print(len(unique_layers) if unique_layers else 2)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error detecting layers: {e}", file=sys.stderr)
|
||||
print(2) # Default to 2 layers
|
||||
PYTHON_SCRIPT
|
||||
|
||||
chmod +x /tmp/detect_layers.py
|
||||
|
||||
# Run the detection and capture both stdout and stderr
|
||||
LAYERS=$(python3 /tmp/detect_layers.py "$PCB_FILE" 2>&1 | tee /tmp/layer_detection.log | grep -v "Found copper layer" | tail -1)
|
||||
|
||||
# Show debug output
|
||||
grep "Found copper layer" /tmp/layer_detection.log || true
|
||||
|
||||
if [ -z "$LAYERS" ] || [ "$LAYERS" = "0" ]; then
|
||||
LAYERS=2
|
||||
echo "Failed to detect layers, defaulting to 2"
|
||||
# Use workflow input or default to 2 layers
|
||||
LAYERS="${{ github.event.inputs.board_layers }}"
|
||||
if [ -z "$LAYERS" ]; then
|
||||
LAYERS="2"
|
||||
fi
|
||||
|
||||
echo "layers=$LAYERS" >> $GITHUB_OUTPUT
|
||||
echo "Auto-detected $LAYERS layer board"
|
||||
fi
|
||||
echo "Using $LAYERS layer configuration"
|
||||
|
||||
- name: Check for KiBot config
|
||||
id: config_check
|
||||
run: |
|
||||
PROJECT_DIR="${{ steps.find_project.outputs.project_dir }}"
|
||||
|
||||
# Search for kibot config in multiple locations
|
||||
if [ -f "$PROJECT_DIR/kibot.yaml" ]; then
|
||||
# Check if kibot.yaml exists in repository root
|
||||
if [ -f "kibot.yaml" ]; then
|
||||
echo "found=true" >> $GITHUB_OUTPUT
|
||||
echo "config_path=$PROJECT_DIR/kibot.yaml" >> $GITHUB_OUTPUT
|
||||
echo "Using project-specific kibot.yaml"
|
||||
elif [ -f "$PROJECT_DIR/../kibot.yaml" ]; then
|
||||
echo "found=true" >> $GITHUB_OUTPUT
|
||||
echo "config_path=$PROJECT_DIR/../kibot.yaml" >> $GITHUB_OUTPUT
|
||||
echo "Using parent directory kibot.yaml"
|
||||
elif [ -f "kibot.yaml" ]; then
|
||||
echo "found=true" >> $GITHUB_OUTPUT
|
||||
echo "config_path=kibot.yaml" >> $GITHUB_OUTPUT
|
||||
echo "Using root kibot.yaml"
|
||||
elif [ -f ".kibot/config.yaml" ]; then
|
||||
echo "found=true" >> $GITHUB_OUTPUT
|
||||
echo "config_path=.kibot/config.yaml" >> $GITHUB_OUTPUT
|
||||
echo "Using .kibot/config.yaml"
|
||||
echo "Using kibot.yaml configuration from repository root"
|
||||
else
|
||||
echo "found=false" >> $GITHUB_OUTPUT
|
||||
echo "Using --quick-start mode (no custom config found)"
|
||||
echo "No kibot.yaml found in repository root - will use --quick-start mode"
|
||||
fi
|
||||
|
||||
- name: Run ERC
|
||||
if: steps.config_check.outputs.found == 'true'
|
||||
run: |
|
||||
cd "${{ steps.find_project.outputs.project_dir }}"
|
||||
CONFIG_PATH="${{ steps.config_check.outputs.config_path }}"
|
||||
|
||||
# Convert to absolute path if needed
|
||||
if [[ "$CONFIG_PATH" != /* ]]; then
|
||||
CONFIG_PATH="$(pwd)/$CONFIG_PATH"
|
||||
fi
|
||||
|
||||
# Normalize the path
|
||||
CONFIG_PATH=$(readlink -f "$CONFIG_PATH" 2>/dev/null || realpath "$CONFIG_PATH" 2>/dev/null || echo "$CONFIG_PATH")
|
||||
|
||||
if [ ! -f "$CONFIG_PATH" ]; then
|
||||
echo "Warning: Config file not found at $CONFIG_PATH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -n "${{ steps.find_project.outputs.sch_file }}" ]; then
|
||||
echo "Running ERC with config: $CONFIG_PATH"
|
||||
kibot -c "$CONFIG_PATH" -s run_erc -v || true
|
||||
echo "Running ERC on schematic files..."
|
||||
# Use absolute path to config file in repo root
|
||||
kibot -c "${GITHUB_WORKSPACE}/kibot.yaml" -s run_erc -v || true
|
||||
else
|
||||
echo "No schematic files found, skipping ERC"
|
||||
fi
|
||||
@@ -208,57 +114,29 @@ jobs:
|
||||
if: steps.config_check.outputs.found == 'true'
|
||||
run: |
|
||||
cd "${{ steps.find_project.outputs.project_dir }}"
|
||||
CONFIG_PATH="${{ steps.config_check.outputs.config_path }}"
|
||||
|
||||
# Convert to absolute path if needed
|
||||
if [[ "$CONFIG_PATH" != /* ]]; then
|
||||
CONFIG_PATH="$(pwd)/$CONFIG_PATH"
|
||||
fi
|
||||
|
||||
# Normalize the path
|
||||
CONFIG_PATH=$(readlink -f "$CONFIG_PATH" 2>/dev/null || realpath "$CONFIG_PATH" 2>/dev/null || echo "$CONFIG_PATH")
|
||||
|
||||
if [ ! -f "$CONFIG_PATH" ]; then
|
||||
echo "Warning: Config file not found at $CONFIG_PATH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Running DRC with config: $CONFIG_PATH"
|
||||
kibot -c "$CONFIG_PATH" -s run_drc -v || true
|
||||
echo "Running DRC on PCB..."
|
||||
# Use absolute path to config file in repo root
|
||||
kibot -c "${GITHUB_WORKSPACE}/kibot.yaml" -s run_drc -v || true
|
||||
continue-on-error: true
|
||||
|
||||
- name: Generate outputs with custom config
|
||||
if: steps.config_check.outputs.found == 'true'
|
||||
run: |
|
||||
cd "${{ steps.find_project.outputs.project_dir }}"
|
||||
CONFIG_PATH="${{ steps.config_check.outputs.config_path }}"
|
||||
|
||||
# Convert to absolute path if needed
|
||||
if [[ "$CONFIG_PATH" != /* ]]; then
|
||||
CONFIG_PATH="$(pwd)/$CONFIG_PATH"
|
||||
fi
|
||||
|
||||
# Normalize the path
|
||||
CONFIG_PATH=$(readlink -f "$CONFIG_PATH" 2>/dev/null || realpath "$CONFIG_PATH" 2>/dev/null || echo "$CONFIG_PATH")
|
||||
|
||||
if [ ! -f "$CONFIG_PATH" ]; then
|
||||
echo "Error: Config file not found at $CONFIG_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Generating outputs for ${{ steps.layers.outputs.layers }} layer board"
|
||||
echo "Project: ${{ steps.find_project.outputs.project_name }}"
|
||||
echo "Using config: $CONFIG_PATH"
|
||||
echo "Using config: ${GITHUB_WORKSPACE}/kibot.yaml"
|
||||
|
||||
# Run KiBot with the configuration
|
||||
kibot -c "$CONFIG_PATH" -d Fabrication -v
|
||||
# Run KiBot with the configuration from repo root
|
||||
kibot -c "${GITHUB_WORKSPACE}/kibot.yaml" -d Fabrication -v
|
||||
|
||||
# Move outputs to root Generated folder
|
||||
mkdir -p ../Generated
|
||||
mkdir -p "${GITHUB_WORKSPACE}/Generated"
|
||||
if [ -d "Fabrication" ]; then
|
||||
cp -r Fabrication/* ../Generated/
|
||||
cp -r Fabrication/* "${GITHUB_WORKSPACE}/Generated/"
|
||||
fi
|
||||
cd ..
|
||||
|
||||
- name: Quick Start fallback
|
||||
if: steps.config_check.outputs.found == 'false'
|
||||
@@ -268,15 +146,12 @@ jobs:
|
||||
kibot --quick-start
|
||||
|
||||
# Move outputs to root Generated folder
|
||||
mkdir -p "${GITHUB_WORKSPACE}/Generated"
|
||||
if [ -d "Generated" ]; then
|
||||
mv Generated ../
|
||||
else
|
||||
mkdir -p ../Generated
|
||||
echo "No Generated folder found after quick-start"
|
||||
cp -r Generated/* "${GITHUB_WORKSPACE}/Generated/"
|
||||
fi
|
||||
cd ..
|
||||
|
||||
- name: Add layer information to outputs
|
||||
- name: Add board information to outputs
|
||||
run: |
|
||||
echo "Board configuration: ${{ steps.layers.outputs.layers }} layers" > Generated/board_info.txt
|
||||
echo "Project: ${{ steps.find_project.outputs.project_name }}" >> Generated/board_info.txt
|
||||
@@ -322,7 +197,7 @@ jobs:
|
||||
name: Fabrication-Package-${{ steps.layers.outputs.layers }}layer
|
||||
path: Generated/*.zip
|
||||
|
||||
# This step is to upload the results to another repo (web pages)
|
||||
# Deploy to documentation branch
|
||||
deploy:
|
||||
runs-on: kicad-kibot-runner
|
||||
needs: generate
|
||||
@@ -367,7 +242,7 @@ jobs:
|
||||
# Commit and push if there are changes
|
||||
git add .
|
||||
if ! git diff --cached --quiet; then
|
||||
git commit -m "chore: update deployed documentation for ${{ needs.generate.outputs.layers }}-layer board"
|
||||
git commit -m "chore: update deployed documentation"
|
||||
git push --force "$AUTHED_URL" docu
|
||||
else
|
||||
echo "No changes to deploy"
|
||||
|
||||
Reference in New Issue
Block a user