-
Notifications
You must be signed in to change notification settings - Fork 0
272 lines (235 loc) · 10 KB
/
generate_output.yml
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: CI and Release Workflow
on:
push:
branches:
- '**'
tags:
- 'v[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+-rc[0-9]+'
paths:
- '*.kicad_sch'
- '*.kicad_pcb'
- '*.kiplot.yaml'
- '.github/workflows/generate_output.yml'
- 'project.properties'
pull_request:
paths:
- '*.kicad_sch'
- '*.kicad_pcb'
- '*.kiplot.yaml'
- '.github/workflows/generate_output.yml'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel.
#jobs:
#call-workflow-passing-data:
# uses: 42CrMo4/KiCad_Workflows/.github/workflows/generate_output.yml@ki8Diff
jobs:
determine-run-type:
runs-on: ubuntu-latest
outputs:
run-type: ${{ steps.check-ref.outputs.run-type }}
steps:
- name: Check ref
id: check-ref
run: |
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+$ ]]; then
echo "run-type=release" >> $GITHUB_OUTPUT
elif [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+-rc[0-9]+$ ]]; then
echo "run-type=rc" >> $GITHUB_OUTPUT
else
echo "run-type=ci" >> $GITHUB_OUTPUT
fi
ERC:
runs-on: ubuntu-latest
container: ghcr.io/inti-cmnb/kicad8_auto:1.7.0
steps:
- uses: actions/checkout@v4
- name: Run ERC
run: |
[ -f *.kicad_sch ] && kiplot -d Fabrication_temp -s update_xml,run_drc -i
DRC:
runs-on: ubuntu-latest
container: ghcr.io/inti-cmnb/kicad8_auto:1.7.0
needs: ERC
steps:
- uses: actions/checkout@v4
- name: Run DRC
run: |
[ -f *.kicad_pcb ] && kiplot -d Fabrication_temp -s update_xml,run_erc -i
Fabrication:
name: Fabrication files
runs-on: ubuntu-latest
permissions:
contents: write
needs: [DRC, determine-run-type]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: List tags and set environment variables
run: |
# Fetch all tags and prune deleted references
# git fetch --prune --unshallow
# Sort tags, placing non-pre-release tags last
sorted_tags=$(git tag | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//')
# Get the most recent tag
last_tag=$(echo "$sorted_tags" | tail -n 1)
# Initialize arrays for pre-release and regular release tags
pre_release_tags=()
release_tags=()
# Categorize tags into pre-release and regular release
for tag in $(git tag); do
if [[ $tag =~ rc ]]; then
pre_release_tags+=("$tag")
else
release_tags+=("$tag")
fi
done
# Get the last pre-release and regular release tags
pre_release_last_tag=${pre_release_tags[-1]}
non_pre_release_last_tag=${release_tags[-1]}
# Get the second to last pre-release and regular release tags
pre_release_second_to_last_tag=${pre_release_tags[-2]}
non_pre_release_second_to_last_tag=${release_tags[-2]}
# Set environment variables
echo "LAST_TAG=$last_tag" >> $GITHUB_ENV
echo "PRE_RELEASE_LAST_TAG=$pre_release_last_tag" >> $GITHUB_ENV
echo "last_tag=$non_pre_release_last_tag" >> $GITHUB_ENV
echo "PRE_RELEASE_SECOND_TO_LAST_TAG=$pre_release_second_to_last_tag" >> $GITHUB_ENV
echo "NON_PRE_RELEASE_SECOND_TO_LAST_TAG=$non_pre_release_second_to_last_tag" >> $GITHUB_ENV
# Check if the latest tag is a non-rc tag and find corresponding rc tag
if [[ ! $last_tag =~ rc ]]; then
last_tag_base=$(echo $last_tag | sed 's/[a-zA-Z]*//g')
echo "last_tag_base=$last_tag_base"
corresponding_rc_tag=$(git tag | grep "${last_tag_base}-rc" | tail -n 1)
if [[ -n $corresponding_rc_tag ]]; then
echo "matching_rc_tag=$corresponding_rc_tag" >> $GITHUB_ENV
else
echo "CORRESPONDING_RC_TAG=No corresponding RC tag found" >> $GITHUB_ENV
fi
else
# If the latest tag is an rc tag, find the second to last rc tag with the same base number
last_tag_base=$(echo $last_tag | sed 's/-rc.*//')
# Get the tags that match the given base pattern
matching_rc_tags=($(git tag | grep "${last_tag_base}-rc" | sort -V))
matching_rc_tag=$(matching_rc_tags | tail -n 1)
echo "matching_rc_tag=$matching_rc_tag" >> $GITHUB_ENV
if [[ ${matching_rc_tags[@]} -eq 0 ]]; then
echo "No matching tags found for base: ${last_tag_base}-rc"
exit 1
fi
second_to_last_matching_rc_tag=${matching_rc_tags[-2]}
if [[ -n $second_to_last_matching_rc_tag ]]; then
echo "SECOND_TO_LAST_MATCHING_RC_TAG=$second_to_last_matching_rc_tag" >> $GITHUB_ENV
else
echo "SECOND_TO_LAST_MATCHING_RC_TAG=No second to last RC tag found" >> $GITHUB_ENV
fi
echo "LAST_NON_RC_TAG=$non_pre_release_last_tag" >> $GITHUB_ENV
fi
# # Debug: Print the counts of tags
# echo "Length of sorted_tags: $(echo "$sorted_tags" | wc -w)"
# echo "Length of pre_release_tags: ${#pre_release_tags[@]}"
# echo "Length of release_tags: ${#release_tags[@]}"
# Debug: Print the last and second to last tags
echo "Last pre-release tag: $pre_release_last_tag"
echo "Last non-pre-release tag: $non_pre_release_last_tag"
echo "Second to last pre-release tag: $pre_release_second_to_last_tag"
echo "Second to last non-pre-release tag: $non_pre_release_second_to_last_tag"
# Print the tags in a logical order for understanding
echo "Last Tag: $last_tag"
echo "Pre-Release Tags:"
for tag in "${pre_release_tags[@]}"; do
echo $tag
done
echo "Regular Release Tags:"
for tag in "${release_tags[@]}"; do
echo $tag
done
echo "Second to last non-pre-release tag: $non_pre_release_second_to_last_tag"
- name: Update the Kibot File with the Tags
run: |
if [ -n "${{ env.last_tag }}" ]; then
curl -o Diff_append.yaml https://raw.githubusercontent.com/42CrMo4/KiCad_Workflows/ki8Diff/.github/workflows/Diff_append.yaml
cat Diff_append.yaml >> *.kiplot.yaml
sed -i "s!<<TAG>>!${{ env.last_tag }}!" *.kiplot.yaml
else
echo "No suitable tag found"
fi
if [ -n "${{ env.matching_rc_tag }}" ]; then
curl -o Diff_append.yaml https://raw.githubusercontent.com/42CrMo4/KiCad_Workflows/ki8Diff/.github/workflows/Diff_append.yaml
cat Diff_append.yaml >> *.kiplot.yaml
sed -i "s!<<TAG>>!${{ env.matching_rc_tag }}!" *.kiplot.yaml
else
echo "No suitable rc-tag found"
fi
- name: Assign variables from project.properties to Env variable
run: |
cat project.properties | egrep -v "^\s*(#|$)" >> $GITHUB_ENV
echo COMMIT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
- name: Update the Schematic with the git hash
run: |
sed -i "s!<<hash>>!Git-${{ env.COMMIT }}!" *.kicad_sch
sed -i "s!<<project_name>>!${{ env.project_name }}!" *.kicad_sch
sed -i "s!<<date>>!$(date +'%Y-%m-%d')!" *.kicad_sch
sed -i "s!<<ID>>!${{ env.ID }}!" *.kicad_sch
- name: Update the PCBs with the git hash
run: |
sed -i "s!<<hash>>!Git-${{ env.COMMIT }}!" *.kicad_pcb
sed -i "s!<<project_name>>!${{ env.project_name }}!" *.kicad_pcb
sed -i "s!<<date>>!$(date +'%Y-%m-%d')!" *.kicad_pcb
sed -i "s!<<website_link>>!${{ env.Website_link }}//${{ env.ID }}!" *.kicad_pcb
sed -i "s!<<ID>>!ID:${{ env.ID }}!" *.kicad_pcb
- name: Update the KiPlot File with the git hash
run: |
sed -i "s!<<hash>>!Git-${{ env.COMMIT }}!" *.kiplot.yaml
sed -i "s!<<project_name>>!${{ env.project_name }}!" *.kiplot.yaml
sed -i "s!<<ID>>!${{ env.ID }}!" *.kiplot.yaml
- uses: INTI-CMNB/KiBot@v2_k8
with:
config: config.kiplot.yaml
dir: Fabrication_temp
- name: Rename the Schematic and PCB Raw Files
run: |
mv *.kicad_sch ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}.kicad_sch
mv *.kicad_pcb ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}.kicad_pcb
cp *.kicad_sch ${{ env.ID }}_${{ env.COMMIT }}.kicad_sch
cp *.kicad_pcb ${{ env.ID }}_${{ env.COMMIT }}.kicad_pcb
- name: Retrieve results kicad_pcb with the git hash
uses: actions/upload-artifact@v4
with:
name: ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}_Kicad_raw
path: '${{ env.ID }}_*.kicad_*'
- name: Retrieve results
uses: actions/upload-artifact@v4
with:
name: ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}_Output
path: |
Fabrication_temp/
- name: Create GitHub Release
if: needs.determine-run-type.outputs.run-type != 'ci'
uses: ncipollo/release-action@v1
with:
artifacts: "Fabrication_temp/*,Fabrication_temp/*/*, *.kicad_sch, *.kicad_pcb, *Gerber.zip"
bodyFile: "docs/release_note.md"
prerelease: ${{ needs.determine-run-type.outputs.run-type == 'rc' }}
token: ${{ secrets.GITHUB_TOKEN }}
Archive-md:
name: Archive & Renew Release Docs
runs-on: ubuntu-latest
needs: [Fabrication, determine-run-type]
if: needs.determine-run-type.outputs.run-type == 'release'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Renaming Release note & checklist + copy the template
run: |
cd docs
mv release_note.md release_note_${{ github.ref_name }}.md
mv release_checklist.md release_checklist_${{ github.ref_name }}.md
cp release_template/release_note.md release_note.md
cp release_template/release_checklist.md release_checklist.md
- uses: stefanzweifel/git-auto-commit-action@v5
with:
repository: .
branch: main
commit_message: Archive & Renew release docs