やりたかったこと
- KiCAD(電子回路設計ソフト)のデータをGitHubでいい感じに管理したい。
- 設計データをpushしたらガーバーデータ(基板製造業者に発注するデータ)を自動で生成してほしい。
- 回路図とかのドキュメントのpdfも生成してほしい。
- 生成したデータはでWebからzipでダウンロードできるようにしたい。
つくったもの
試しにpublicなリポジトリにつくってみた。
こんなことができます。
tagをつけてpushすると自動でリリースしてくれる。リリースには生成データが添付される。
リリースしなくてもpushするたびに Artifacts にデータが生成される。
やりかた
GitHub Actions の kicad-exportsを使うと簡単にできてしまいました。
https://github.com/marketplace/actions/kicad-exports
やることはリポジトリ内にyamlファイルを数個配置するだけです。
手順
以下の手順でつくった完成品がこちらです。
https://github.com/YamadaKyohei/kicad-actions-sample
1. KiCADのデータ(.shc, .kicad_pcb)が配置されたGitHubリポジトリをつくる。
2. GitHub Actions 設定用のyamlファイルを配置する。
.github/workflows
の中にActionsの挙動を定義します。
pushしたとき用の動作を .github/workflows/main.yml
に以下のように記述しました。
name: KiCad-exports
on:
push:
paths:
- '**.sch'
- '**.kicad_pcb'
pull_request:
paths:
- '**.sch'
- '**.kicad_pcb'
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: nerdyscout/kicad-exports@v2.1
with:
# Required - kibot config file
config: ./config/docs.kibot.yaml
# optional - prefix to output defined in config
dir: docs
# optional - schematic file
schema: '*.sch'
# optional - PCB design file
board: '*.kicad_pcb'
- uses: nerdyscout/kicad-exports@v2.1
with:
# Required - kibot config file
config: ./config/fabrications.kibot.yaml
# optional - prefix to output defined in config
dir: gerber
# optional - schematic file
schema: '*.sch'
# optional - PCB design file
board: '*.kicad_pcb'
- name: upload results
uses: actions/upload-artifact@v2
with:
name: docs
path: |
docs/docs
!docs/docs/*.ogv
- name: upload results
uses: actions/upload-artifact@v2
with:
name: gerber
path: gerber/gerber
また、tagをつけてpushされたとき自動でリリースする動作は .github/workflows/release.yml
に以下のように記述しました。スクリーンキャプチャの.ogvファイルなども一緒に生成されてしまうので、zip化の際に除外しています。
name: KiCad-exports-release
on:
push:
tags:
- 'v*'
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: nerdyscout/kicad-exports@v2.1
with:
# Required - kibot config file
config: ./config/docs.kibot.yaml
# optional - prefix to output defined in config
dir: docs
# optional - schematic file
schema: '*.sch'
# optional - PCB design file
board: '*.kicad_pcb'
- uses: nerdyscout/kicad-exports@v2.1
with:
# Required - kibot config file
config: ./config/fabrications.kibot.yaml
# optional - prefix to output defined in config
dir: gerber
# optional - schematic file
schema: '*.sch'
# optional - PCB design file
board: '*.kicad_pcb'
- name: Create release
id: create_release
uses: actions/create-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: docs zip output
run: |
cd ./docs/docs
zip ../../docs * -x *.ogv
- name: Upload Release Docs
id: upload-release-docs
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: docs.zip
asset_name: docs.zip
asset_content_type: application/zip
- name: docs zip output
run: |
cd ./gerber/gerber
zip ../../gerber *.*
- name: Upload Release Gerbers
id: upload-release-gerber
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: gerber.zip
asset_name: gerber.zip
asset_content_type: application/zip
3. kicad-exports 設定用のyamlファイルを配置する。
回路図と配線図のpdfはconfig/docs.kibot.yaml
に生成に関する設定を記述しました。
kibot:
version: 1
preflight:
run_erc: true
run_drc: true
check_zone_fills: true
ignore_unconnected: false
outputs:
- name: 'print schema'
comment: "Print schematic (PDF)"
type: pdf_sch_print
dir: docs
options:
output: '%p-Schematic_%r.%x'
- name: 'print board'
comment: "Print board (PDF)"
type: pdf_pcb_print
dir: docs
options:
output: '%p-Board_%r.%x'
layers:
- 'all'
ガーバーデータの生成は、config/fabrications.kibot.yaml
に次のように設定しました。もうちょっと設定を詰めれば、Fusion PCBとかにそのままアップロードできるzipが作れると思います。
kibot:
version: 1
preflight:
run_erc: true
update_xml: true
run_drc: true
check_zone_fills: true
ignore_unconnected: false
outputs:
- name: 'interactive_bom'
comment: "Interactive Bill of Materials (HTML)"
type: ibom
dir: BoM
options:
blacklist: 'DNF*'
name_format: '%f_%r_iBoM'
- name: 'bom_csv'
comment: "Bill of Materials in CSV format"
type: kibom
dir: BoM
options:
format: CSV # HTML or CSV
- name: 'gerbers'
comment: "Gerbers for the board house"
type: gerber
dir: gerber
options:
# generic layer options
exclude_edge_layer: true
exclude_pads_from_silkscreen: true
use_aux_axis_as_origin: false
plot_sheet_reference: false
plot_footprint_refs: true
plot_footprint_values: true
force_plot_invisible_refs_vals: false
tent_vias: false
# gerber options
line_width: 0.1
subtract_mask_from_silk: false
use_protel_extensions: true
gerber_precision: 4.6
create_gerber_job_file: false
use_gerber_x2_attributes: false
use_gerber_net_attributes: false
# for 2-layer pcb
layers:
- layer: F.Cu
suffix: F_Cu
- layer: B.Cu
suffix: B_Cu
- layer: F.Paste
suffix: F_Paste
- layer: B.Paste
suffix: B_Paste
- layer: F.SilkS
suffix: F_SilkS
- layer: B.SilkS
suffix: B_SilkS
- layer: F.Mask
suffix: F_Mask
- layer: B.Mask
suffix: B_Mask
- layer: Edge.Cuts
suffix: Edge_Cuts
- name: "Excellon drills"
comment: "Excellon drill files"
type: "excellon"
dir: "gerber"
options:
use_aux_axis_as_origin: true
metric_units: true
pth_and_npth_single_file: false
minimal_header: true
mirror_y_axis: false
以上4つのyamlファイルを設置すると、以後GitHub Actionsが欲しいデータをつくってくれます。
感想
- GitHub Actionsが無料枠でけっこう遊べてしまってびっくり。
- ハードウェアを自動デプロイしてるような感じがして楽しい。
- 「回路図ください」「ガーバーください」とSlackで催促しあう文化から、これで卒業したい。
- ReleaseからドキュメントがダウンロードできるっていうUIは、回路設計者以外のプロジェクトメンバーにも使いやすそう。
- stepデータ(3Dの機械図面)も生成できるらしいので試したい。