Now Reading
CI/CD with KiCad and Gitlab

CI/CD with KiCad and Gitlab

2023-05-12 15:49:49

(Blender Render of KiCad Exported PCB)

Introduction

I make many small tasks and normally order PCBs at some place. Producing Gerber recordsdata and checking every part is so as earlier than ordering will be tedious. Moreover the extra complicated the board the extra components I want and most certainly I may also want a reference so as to place the components.

So I made a decision to setup a gitlab pipeline to automate the entire course of.

After I commit into the grasp the gitlab pipeline will run checks on the schematic and on the PCB. If these move it’s going to generate the Gerbers I want for the particular fab I exploit (JLCPCB on this case) and likewise generate a BOM which I can use to order components at LCSC. Moreover it’s going to generate a flowery KiCad Interactive HTML BOM, place file for JLCPCB (if you’d like them to do meeting) and a PDF of the schematic
. All these artifacts are commited again into the grasp and a model is utilized. I even have a CHANGELOG.md which is routinely crammed from commit messages (I used typical commits to format my commit messages)

Git

To ensure that this to work you want to preserve your KiCad venture in a git repository. To do that I exploit the next .gitignore (KiCad makes tons of recordsdata however you don’t must commit all of them) and file construction.

Folder Construction

├── ci/               # Recordsdata particular to CI (colours for PDF and so on.)
├── datasheets/       # Information sheets of things I used on this venture
├── Fabrication/      # Fabrication output
├── footprints/       # KiCad footprints (just for this venture)
├── library/          # KiCad libraries (just for this venture)
├── packages3d/       # KiCad 3d packages (just for this venture)
├── VERSION.txt       # model (Auto up to date)
├── CHANGELOG.md      # changelog (Auto generated)
├── README.md         
├── output.kibot.yaml # KiBot output configuration, gerbers, BOM and so on. 
├── take a look at.kibot.yaml   # KiBot Exams
├── .gitignore
└── .gitlab-ci.yml    # Gitlab CI file

.gitignore

# For PCBs designed utilizing KiCad: http://www.kicad-pcb.org/
# Format documentation: http://kicad-pcb.org/assist/file-formats/

# Non permanent recordsdata
*.000
*.bak
*.bck
*.kicad_pcb-bak
*.kicad_sch-bak
*.kicad_prl
*.sch-bak
*~
_autosave-*
*.tmp
*-save.professional
*-save.kicad_pcb
fp-info-cache
*-backups/

# Netlist recordsdata (exported from Eeschema)
*.internet

# Autorouter recordsdata (exported from Pcbnew)
*.dsn
*.ses
*.guidelines

# Exported BOM recordsdata
*.xml
*.csv
export-*

# Rendered output
3d/Render/*

KiCad Setup

When including elements, add “LCSC” to total schematic (BOM export will fail if added to every half individually (be a part of challenge)) and the half quantity in every half to the half so as to use the JLCPCB meeting service. Solely components with LCSC column are exported within the JLCPCB BOMs.

/posts/ci-cd-with-kicad-and-gitlab/kicad-pref.png

Now when including components fill within the LCSC area.

/posts/ci-cd-with-kicad-and-gitlab/kicad-part.png

GitLab Setup

/posts/ci-cd-with-kicad-and-gitlab/gitlab-pipeline.png

I exploit a common gitlab setup with docker runners and semantic releases

Gitlab CI

.gitlab-ci.yml

levels:
  - fetch-version
  - testing
  - gen_fab
  - publish

#https://levelup.gitconnected.com/semantic-versioning-and-release-automation-on-gitlab-9ba16af0c21
fetch-semantic-version:
  picture: node:18
  stage: fetch-version
  solely:
    refs:
    - grasp
    - alpha
    - /^(([0-9]+).)?([0-9]+).x/ # This matches upkeep branches
    - /^([0-9]+).([0-9]+).([0-9]+)(?:-([0-9A-Za-z-]+(?:.[0-9A-Za-z-]+)*))?(?:+[0-9A-Za-z-]+)?$/ # This matches pre-releases
  script:
    - npm set up @semantic-release/gitlab @semantic-release/exec @semantic-release/changelog @semantic-release/git -D
    - npx semantic-release --generate-notes false --dry-run
  artifacts:
    paths:
    - VERSION.txt
  tags:
    - docker

generate-non-semantic-version:
  stage: fetch-version
  besides:
    refs:
    - grasp
    - alpha
    - /^(([0-9]+).)?([0-9]+).x/ # This matches upkeep branches
    - /^([0-9]+).([0-9]+).([0-9]+)(?:-([0-9A-Za-z-]+(?:.[0-9A-Za-z-]+)*))?(?:+[0-9A-Za-z-]+)?$/ # This matches pre-releases
  script:
    - echo build-$CI_PIPELINE_ID > VERSION.txt
  artifacts:
    paths:
    - VERSION.txt
  tags:
    - docker

checks:
  picture: ghcr.io/inti-cmnb/kicad7_auto:1.6.2
  stage: testing
  script:
    - "[ -f *.kicad_pcb ] && kibot -c take a look at.kibot.yaml"
  tags:
    - docker

pcb_outputs:
  picture: ghcr.io/inti-cmnb/kicad7_auto:1.6.2
  stage: gen_fab
  script:
    - "[ -f *.kicad_pcb ] && kibot -c output.kibot.yaml"
  solely:
    refs:
    - grasp
    - alpha
    # This matches upkeep branches
    - /^(([0-9]+).)?([0-9]+).x/
    # This matches pre-releases
    - /^([0-9]+).([0-9]+).([0-9]+)(?:-([0-9A-Za-z-]+(?:.[0-9A-Za-z-]+)*))?(?:+[0-9A-Za-z-]+)?$/ 
  artifacts:
    when: all the time
    paths:
      - Fabrication/
  tags:
    - docker

launch:
  stage: publish
  picture: node:18
  solely:
    refs:
    - grasp
    - alpha
    # This matches upkeep branches
    - /^(([0-9]+).)?([0-9]+).x/
    # This matches pre-releases
    - /^([0-9]+).([0-9]+).([0-9]+)(?:-([0-9A-Za-z-]+(?:.[0-9A-Za-z-]+)*))?(?:+[0-9A-Za-z-]+)?$/ 
  script:
    - npm set up @semantic-release/gitlab @semantic-release/exec @semantic-release/changelog @semantic-release/git -D
    - npx semantic-release
  tags:
    - docker

KiBot

KiBot helps you to automate nearly something that KiCad can do. I exploit it with docker to have the ability to run it in gitlab.

See Also

Right here is the take a look at and output configrations I exploit that are particular for JLCPCB however will be adjusted to nearly any fab. There are additionally many examples on the KiBot github for different fabs.

take a look at.kibot.yaml

kibot:
  model: 1

preflight:
  run_erc: true
  update_xml: false
  run_drc: true
  check_zone_fills: true
  ignore_unconnected: false

output.kibot.yaml

# Gerber and drill recordsdata for JLCPCB, with out stencil
# URL: https://jlcpcb.com/
kibot:
  model: 1

globals:
  resources_dir: ci

filters:
  - title: only_jlc_parts
    remark: 'Solely components with JLC (LCSC) code'
    sort: generic
    include_only:
      - column: 'LCSC'
        regex: '^Cd+'

variants:
  - title: rotated
    remark: 'Only a place holder for the rotation filter'
    sort: kibom
    variant: rotated
    pre_transform: _rot_footprint

# JLCPCB Gerber Output
outputs:
  - title: JLCPCB_gerbers
    remark: Gerbers suitable with JLCPCB
    sort: gerber
    dir: JLCPCB
    choices: &gerber_options
      exclude_edge_layer: true
      exclude_pads_from_silkscreen: true
      plot_sheet_reference: false
      plot_footprint_refs: true
      plot_footprint_values: false
      force_plot_invisible_refs_vals: false
      tent_vias: true
      use_protel_extensions: true
      create_gerber_job_file: false
      disable_aperture_macros: true
      gerber_precision: 4.6
      use_gerber_x2_attributes: false
      use_gerber_net_attributes: false
      line_width: 0.1
      subtract_mask_from_silk: true
    layers:
      # Be aware: a extra generic method is to make use of 'copper' however then the filenames
      # are barely completely different.
      - F.Cu
      - B.Cu
      - F.Paste
      - B.Paste
      - F.SilkS
      - B.SilkS
      - F.Masks
      - B.Masks
      - Edge.Cuts

# JLCPCB drill recordsdata
  - title: JLCPCB_drill
    remark: Drill recordsdata suitable with JLCPCB
    sort: excellon
    dir: JLCPCB
    choices:
      pth_and_npth_single_file: false
      pth_id: '-PTH'
      npth_id: '-NPTH'
      metric_units: false
      output: "%fpercenti.%x"

# zip all JLCPCB gerber and drill recordsdata collectively
  - title: JLCPCB
    remark: ZIP file for JLCPCB
    sort: compress
    dir: Fabrication/JLCPCB
    choices:
      recordsdata:
        - from_output: JLCPCB_gerbers
          dest: /
        - from_output: JLCPCB_drill
          dest: /

# html ibom
  - title: ibom
    remark: Interactive BOM
    sort: ibom 
    dir: Fabrication/ibom
    choices:
      dark_mode: true
      name_format: 'index'

# JLCPCB meeting positions of elements
  - title: 'JLCPCB_position'
    remark: "Decide and place file, JLCPCB fashion"
    sort: place
    dir: Fabrication/JLCPCB-BOM
    choices:
      variant: rotated
      output: '%f_cpl_jlc.%x'
      format: CSV
      models: millimeters
      separate_files_for_front_and_back: false
      only_smd: true
      columns:
        - id: Ref
          title: Designator
        - Val
        - Bundle
        - id: PosX
          title: "Mid X"
        - id: PosY
          title: "Mid Y"
        - id: Rot
          title: Rotation
        - id: Aspect
          title: Layer

# JLCPCB Bom for meeting or for LCSC order
  - title: 'JLCPCB_bom'
    remark: "BoM for JLCPCB"
    sort: bom
    dir: Fabrication/JLCPCB-BOM    
    choices:
      output: '%f_percenti_jlc.%x'
      exclude_filter: 'only_jlc_parts'
      ref_separator: ','
      columns:
        - area: Worth
          title: Remark
        - area: References
          title: Designator
        - Footprint
        - area: 'LCSC'
          title: 'LCSC half quantity'
        - area: 'Amount Per PCB'
          title: 'QTY'
      csv:
        hide_pcb_info: true
        hide_stats_info: true
        quote_all: true

# PDF of Schematic with dracula theme
  - title: 'SchPrint'
    remark: "Print schematic PDF"
    sort: pdf_sch_print
    dir: Fabrication/PDFs
    choices:
      color_theme: dracula
      background_color: true

Fabrication

After the pipeline runs efficiently I’ve the next recordsdata in my repositories Fabrication folder:

├── ibom
│   └── myproject-ibom.html      # interactive BOM
├── JLCPCB
│   └── myproject-JLCPCB.zip     # gerbers for PCB order
├── JLCPCB-BOM
│   ├── myproject_bom_jlc.csv    # BOM for meeting or LCDC order
│   └── myproject_cpl_jlc.csv    # Meeting place file
└── PDFs
    └── myproject-schematic.pdf  # PDF of schematic

TODO

  • I’ve not used JLCPCB’s meeting service with this export so it is probably not appropriate
  • The DRC seems to be utilizing the KiCad defaults and never the choices I set in KiCad, I’ll must move the designs guidelines to KiBot by some means.
  • A PDF of the PCB would even be helpful however requires defining which layers and so on. within the config above.
  • I would really like the interactive BOM be add to a gitlab web page
  • 3d export?

Eye-Sweet

That is an export from KiCad into Blender which textures utilized in addition to animated.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top