Skip to content

Commit e5b4ca9

Browse files
committed
CI
1 parent d51a849 commit e5b4ca9

File tree

2 files changed

+266
-0
lines changed

2 files changed

+266
-0
lines changed

.github/workflows/main.yml

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
paths-ignore:
6+
- '**/README.md'
7+
- '**/LICENSE'
8+
pull_request:
9+
branches:
10+
- main
11+
paths-ignore:
12+
- '**/README.md'
13+
- '**/LICENSE'
14+
workflow_dispatch:
15+
paths-ignore:
16+
- '**/README.md'
17+
- '**/LICENSE'
18+
19+
env:
20+
DOCKER_USER_OPTION: '$UID:$GID'
21+
22+
name: Build
23+
jobs:
24+
generate:
25+
runs-on: ubuntu-latest
26+
name: Generate
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
- uses: xanantis/docker-file-ownership-fix@v1
31+
- name: Run build script
32+
run: |
33+
chmod +x build.sh
34+
./build.sh
35+
shell: bash
36+
- name: Persist PCB gerbers
37+
uses: actions/upload-artifact@v2
38+
with:
39+
name: Nijuni_pcb_gerbers
40+
path: gerbers/pcb
41+
- name: Persist case gerbers
42+
uses: actions/upload-artifact@v2
43+
with:
44+
name: Nijuni_case_gerbers
45+
path: gerbers/case
46+
- name: Persist images
47+
uses: actions/upload-artifact@v2
48+
with:
49+
name: Nijuni_images
50+
path: images
51+
- name: Persist laser case files
52+
uses: actions/upload-artifact@v2
53+
with:
54+
name: Nijuni_laser_case_files
55+
path: dxf
56+
57+
58+
image_matrix:
59+
runs-on: ubuntu-latest
60+
name: PCB image matrix
61+
needs: generate
62+
outputs:
63+
matrix: ${{ steps.setmatrix.outputs.matrix }}
64+
steps:
65+
- uses: actions/download-artifact@master
66+
with:
67+
name: Nijuni_images
68+
path: images
69+
- id: setmatrix
70+
run: |
71+
matrixArray=$(find ./images -name 'pcb*.png' | xargs -n 1 -i echo {} {} | sed 's# .*/# #') # Creates array of all PCB image files
72+
# Start Generate JSON String
73+
echo "$matrixArray" | \
74+
jq --slurp --raw-input 'split("\n")[:-1] | map(split(" "))' | \
75+
jq "map({\"filepath\": (.[0]), \"basename\": .[1] })" | \
76+
jq -sc "{ \"include\": .[] }" > tmp
77+
cat ./tmp
78+
# End Generate JSON String
79+
matrixStringifiedObject=$(cat ./tmp) # Use this as jq @sh wasn't cooperating
80+
echo "::set-output name=matrix::$matrixStringifiedObject"
81+
82+
gerber_matrix:
83+
runs-on: ubuntu-latest
84+
name: Gerber matrix
85+
needs: generate
86+
outputs:
87+
matrix: ${{ steps.setmatrix.outputs.matrix }}
88+
steps:
89+
- uses: actions/download-artifact@master
90+
with:
91+
name: Nijuni_gerbers
92+
path: gerbers
93+
- id: setmatrix
94+
run: |
95+
matrixArray=$(find ./gerbers/pcb -name '*.zip' | xargs -n 1 -i echo {} {} | sed 's# .*/# #') # Creates array of all PCB gerber files
96+
# Start Generate JSON String
97+
echo "$matrixArray" | \
98+
jq --slurp --raw-input 'split("\n")[:-1] | map(split(" "))' | \
99+
jq "map({\"filepath\": (.[0]), \"basename\": .[1] })" | \
100+
jq -sc "{ \"include\": .[] }" > tmp
101+
cat ./tmp
102+
# End Generate JSON String
103+
matrixStringifiedObject=$(cat ./tmp) # Use this as jq @sh wasn't cooperating
104+
echo "::set-output name=matrix::$matrixStringifiedObject"
105+
106+
upload_pcb_gerbers:
107+
runs-on: ubuntu-latest
108+
name: Upload gerbers
109+
needs: [generate, gerber_matrix]
110+
strategy:
111+
matrix: ${{fromJson(needs.gerber_matrix.outputs.matrix)}}
112+
steps:
113+
- uses: actions/download-artifact@master
114+
with:
115+
name: Nijuni_gerbers
116+
path: gerbers
117+
- name: Gets latest created release info
118+
id: latest_release_info
119+
uses: jossef/action-latest-release-info@v1.1.0
120+
env:
121+
GITHUB_TOKEN: ${{ github.token }}
122+
- name: Upload gerbers
123+
uses: shogo82148/actions-upload-release-asset@v1
124+
env:
125+
GITHUB_TOKEN: ${{ github.token }}
126+
with:
127+
overwrite: true
128+
upload_url: ${{ steps.latest_release_info.outputs.upload_url }}
129+
asset_path: ${{ matrix.filepath }}
130+
asset_name: ${{ matrix.basename }}
131+
132+
upload_images:
133+
runs-on: ubuntu-latest
134+
name: Upload images
135+
needs: [generate, image_matrix]
136+
strategy:
137+
matrix: ${{fromJson(needs.image_matrix.outputs.matrix)}}
138+
steps:
139+
- uses: actions/download-artifact@master
140+
with:
141+
name: Nijuni_images
142+
path: images
143+
- name: Gets latest created release info
144+
id: latest_release_info
145+
uses: jossef/action-latest-release-info@v1.1.0
146+
env:
147+
GITHUB_TOKEN: ${{ github.token }}
148+
- name: Upload images
149+
uses: shogo82148/actions-upload-release-asset@v1
150+
env:
151+
GITHUB_TOKEN: ${{ github.token }}
152+
with:
153+
overwrite: true
154+
upload_url: ${{ steps.latest_release_info.outputs.upload_url }}
155+
asset_path: ${{ matrix.filepath }}
156+
asset_name: ${{ matrix.basename }}
157+
158+
upload_laser_case_files:
159+
runs-on: ubuntu-latest
160+
name: Upload case DXF files
161+
needs: generate
162+
steps:
163+
- uses: actions/download-artifact@master
164+
with:
165+
name: Nijuni_laser_case_files
166+
path: dxf
167+
- name: Gets latest created release info
168+
id: latest_release_info
169+
uses: jossef/action-latest-release-info@v1.1.0
170+
env:
171+
GITHUB_TOKEN: ${{ github.token }}
172+
- name: Upload case files
173+
uses: shogo82148/actions-upload-release-asset@v1
174+
env:
175+
GITHUB_TOKEN: ${{ github.token }}
176+
with:
177+
overwrite: true
178+
upload_url: ${{ steps.latest_release_info.outputs.upload_url }}
179+
asset_path: ./dxf/laser_case_files.zip
180+
asset_name: laser_case_files.zip
181+
182+
upload_gerber_case_files:
183+
runs-on: ubuntu-latest
184+
name: Upload case DXF files
185+
needs: generate
186+
steps:
187+
- uses: actions/download-artifact@master
188+
with:
189+
name: Nijuni_gerber_case_files
190+
path: gerbers/case
191+
- name: Gets latest created release info
192+
id: latest_release_info
193+
uses: jossef/action-latest-release-info@v1.1.0
194+
env:
195+
GITHUB_TOKEN: ${{ github.token }}
196+
- name: Upload case files
197+
uses: shogo82148/actions-upload-release-asset@v1
198+
env:
199+
GITHUB_TOKEN: ${{ github.token }}
200+
with:
201+
overwrite: true
202+
upload_url: ${{ steps.latest_release_info.outputs.upload_url }}
203+
asset_path: ./gerbers/case/gerber_case_files.zip
204+
asset_name: gerber_case_files.zip

build.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
container_cmd="docker run -v=$(pwd):/kikit -w=/kikit --rm"
4+
5+
# Images
6+
echo "Drawing image files"
7+
mkdir -p images
8+
for name in "pcb" "plate" "bottom"
9+
do
10+
for option in "$name"/*/
11+
do
12+
short_option="$(basename "$option")"
13+
file="$(find $option -type f -name '*.kicad_pcb')"
14+
${container_cmd} yaqwsx/kikit:nightly pcbdraw --style builtin:set-black-hasl.json "$file" images/"$name"_"$short_option".png >> /dev/null
15+
${container_cmd} yaqwsx/kikit:nightly pcbdraw --style builtin:set-black-hasl.json --back "$file" images/"$name"_"$short_option"_back.png >> /dev/null
16+
done
17+
done
18+
19+
# Gerbers
20+
echo "Generating gerbers"
21+
mkdir -p gerbers
22+
for name in "pcb" "plate" "bottom"
23+
do
24+
prefix="case"
25+
if [[ "$name" == "pcb" ]]; then
26+
prefix="pcb"
27+
fi
28+
mkdir -p gerbers/"$prefix"
29+
for option in "$name"/*/
30+
do
31+
if [[ "$name" == "plate" ]] && ! [[ "$option" =~ ^.*\/fr4.*$ ]]; then
32+
continue
33+
fi
34+
short_option="$(basename "$option")"
35+
file="$(find $option -type f -name '*.kicad_pcb')"
36+
${container_cmd} yaqwsx/kikit:nightly kikit fab jlcpcb --no-assembly "$file" gerbers/"$name"_"$short_option" --no-drc
37+
mv gerbers/"$name"_"$short_option"/gerbers.zip gerbers/"$prefix"/"$name"_"$short_option"_gerbers.zip
38+
rm -r gerbers/"$name"_"$short_option"
39+
done
40+
done
41+
42+
# Plate/bottom dxf files
43+
echo "Generating case DXF files"
44+
mkdir -p dxf
45+
for name in "plate" "bottom"
46+
do
47+
for option in "$name"/*/
48+
do
49+
if [[ "$name" == "plate" ]] && [[ ! "$option" =~ ^.*\/laser.*$ ]]; then
50+
continue
51+
fi
52+
short_option="$(basename "$option")"
53+
file="$(find $option -type f -name '*.kicad_pcb')"
54+
file_name=$(basename "$file" .kicad_pcb)
55+
${container_cmd} yaqwsx/kikit:nightly kikit export dxf "$file" dxf/"$name"_"$short_option"
56+
mv dxf/"$name"_"$short_option"/"$file_name"-EdgeCuts.dxf dxf/"$name"_"$short_option".dxf
57+
rm -r dxf/"$name"_"$short_option"
58+
done
59+
done
60+
61+
zip -jr dxf/laser_case_files dxf/
62+

0 commit comments

Comments
 (0)