As part of my PCB design workflow I use kibot to process my PCB’s and generate the Gerber files I need for PCB manufacture, but sometimes to make better use of the of the PCB size I want to create panels that are the minimum size I need to pay for with JLCPCB who I frequently use to make these boards. Another problem I have found when doing respins of boards that have problems or errors, is keeping track of different versions, while i have tried in the past to keep up with a version on the board this hasn’t always worked out, so for these boards I wanted to add reference to the git version used to generate the files.
For generating the Git short sha, from within the github action, we create a varrible to store the current github short sha, which checks if github.event.pull_request.head.sha
is avalible and use it, if it is not avalible use git rev-parse --short HEAD
to populate the variable sha_short
.
# Do a string replacement in the PCB file to set the git HASH
- name: Set outputs
id: vars
run: |
if [${{ github.event.pull_request.head.sha }} == ""]; then
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
else
echo "::set-output name=sha_short::$(git rev-parse --short ${{ github.event.pull_request.head.sha }})"
fi
I need to create a reference to replace in the Kicad PCB, the KICAD pcb file is essentially a text file so I can take some text that is otherwise not in the file, and for my PCB i am using %%GITHASH%%
. This is placed on the back silkscreen of the PCB, where I want the short SHA to be placed.
Using this variable and the %%GITHASH%%
reference on the board we use a find and replace operation in the github action to complete the replacement.
- name: Set PCB version
uses: jacobtomlinson/gha-find-replace@master
with:
include: "Hardware/RP2040_Mini_PMod/RP2040_Mini_PMod.kicad_pcb"
find: "%%GITHASH%%"
replace: ${{ steps.vars.outputs.sha_short }}
With the Github SHA replacement completed on the board, the next task is to create the panels of the board using kikit
, I have used this a lot in the past, but by using within the github action we can ensure that the same board is always generated. As part of this github action, I also take the opportunity to ensure the JLC
part number is added added on the panels frame as well as other automatically generated information such as the same SHA Hash and the date that the PCb was generated.
- name: Make a panel
run: |
kikit panelize \
--layout 'grid; rows: 3; cols: 2; space: 2mm' \
--tabs 'fixed; width: 5mm; vcount: 2; hcount: 0' \
--cuts 'mousebites; drill: 0.5mm; spacing: 1mm; offset: -0.2mm; prolong: 0.7mm' \
--framing 'railstb; width: 5mm; space: 3mm;' \
--post 'millradius: 1mm' \
--text 'simple; text: JLCJLCJLCJLC; anchor: mt; voffset: 2.5mm; hjustify: center; vjustify: center;' \
--text2 'simple; text: Created {date} Git Version ${{ steps.vars.outputs.sha_short }}; anchor: mb; voffset: -2.5mm; hjustify: center; vjustify: center;' \
Hardware/RP2040_Mini_PMod/RP2040_Mini_PMod.kicad_pcb Hardware/RP2040_Mini_PMod/panel.kicad_pcb
The complete github action for generating the PCB’s can be found here as part of the RP2040 mini PMod I have been building.