Repository navigation
153 lines (124 loc) · 5.03 KB
/
Copy pathdeploy.yml
File metadata and controls
153 lines (124 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: KiCad CI
on:
workflow_dispatch: # Manually trigger the workflow
push:
branches:
[master, main]
# pull_request:
# branches:
# [master, main]
permissions:
contents: write # Ensure write access for the repository contents
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Find project, schematic, and PCB files
id: find_files
run: |
# Find the .pro project file
project_file=$(find . -type f -name "*.kicad_pro" | head -n 1)
if [ -z "$project_file" ]; then
echo "No project file found!"
exit 1
fi
# Extract the project name from the .pro file (remove the extension)
base_name=$(basename "$project_file" .kicad_pro)
# Find the corresponding schematic and PCB files based on the project name
schematic_file="./${base_name}.kicad_sch"
pcb_file="./${base_name}.kicad_pcb"
if [ ! -f "$schematic_file" ]; then
echo "Schematic file $schematic_file does not exist!"
exit 1
fi
if [ ! -f "$pcb_file" ]; then
echo "PCB file $pcb_file does not exist!"
exit 1
fi
echo "Found project file: $project_file"
echo "Found schematic file: $schematic_file"
echo "Found PCB file: $pcb_file"
# Store the base name for later use
echo "base_name=$base_name" >> $GITHUB_ENV
echo "schematic_file=$schematic_file" >> $GITHUB_ENV
echo "pcb_file=$pcb_file" >> $GITHUB_ENV
- name: Install KiCad V8.0.0 (or adjust version if necessary)
run: |
sudo add-apt-repository ppa:kicad/kicad-8.0-releases -y
sudo apt update
sudo apt install -y kicad
- name: Generate schematic PDF
run: |
# Ensure the 'doc' directory exists
mkdir -p doc
# Generate the schematic PDF with the project name dynamically inserted
kicad-cli sch export pdf --output "doc/${{ env.base_name }}-schematic.pdf" ${{ env.schematic_file }}
# Check if the PDF was generated successfully
if [ ! -f "doc/${{ env.base_name }}-schematic.pdf" ]; then
echo "Error: schematic PDF was not generated."
exit 1
fi
echo "Schematic PDF generated successfully."
- name: Get short commit SHA
id: get_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Replace BRD SHA placeholder in PCB file
run: |
sed -i "s/BRD SHA: %%%%%%%%/BRD SHA: ${{ env.short_sha }}/g" "${{ env.pcb_file }}"
echo "Updated PCB file with commit SHA: ${{ env.short_sha }}"
- name: Generate Gerber files
run: |
# Ensure the 'fab' directory exists
mkdir -p fab
# Generate the Gerber files
kicad-cli pcb export gerbers --no-protel-ext -o fab/ "${{ env.pcb_file }}"
kicad-cli pcb export drill -o fab/ "${{ env.pcb_file }}"
# Check if any Gerber files were generated in the 'fab' directory
if [ -z "$(ls fab/*.gbr 2>/dev/null)" ]; then
echo "Error: Gerber files were not generated."
exit 1
fi
echo "Gerber files generated successfully."
# - name: Zip Gerber files
# run: |
# # Create a zip file with the project name
# zip -r "fab/${{ env.base_name }}-gerbers.zip" fab/*.gbr fab/*.drl
# echo "Gerber files have been zipped into ${{ env.base_name }}gerbers.zip"
- name: List Generated Files
run: |
echo "Contents of doc/:"
ls -l doc/
echo "Contents of fab/:"
ls -l fab/
- name: Configure Git user
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
- name: Commit and push the generated PDF and Gerber files
run: |
# Add the schematic PDF
git add "doc/${{ env.base_name }}-schematic.pdf"
# Add the Gerber files based on patterns
git add fab/*_Cu.gbr
git add fab/*_Paste.gbr
git add fab/*_Silkscreen.gbr
git add fab/*_Mask.gbr
git add fab/*Edge_Cuts.gbr
for file in fab/*PTH-drl.gbr; do
[ -e "$file" ] && git add "$file"
done
git add fab/*.drl
# Check if there are changes to commit
if git diff --cached --quiet; then
echo "No changes to commit."
exit 0
fi
# Commit if the files were added
git commit -m "Add generated schematic PDF and Gerber files"
# Push the commit
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }}