-
Notifications
You must be signed in to change notification settings - Fork 0
275 lines (247 loc) · 11.4 KB
/
release-workflow.yaml
File metadata and controls
275 lines (247 loc) · 11.4 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
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
273
274
275
name: Release Workflow
on:
# Runs on direct push to master, but we'll check if it's from a PR merge in the job condition
push:
branches:
- master # or 'main' depending on your main branch
# Removed pull_request trigger to avoid duplicate runs
# Allows manual triggering from the Actions tab
workflow_dispatch:
inputs:
version_increment:
description: 'Force version increment (yes/no)'
required: false
default: 'no'
release_notes:
description: 'Custom release notes'
required: false
jobs:
release:
name: Compile and Release
# Run this job if:
# 1. Any push to master (including PR merges)
# 2. Manually triggered
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
firmware-version: ${{ steps.compile-bsom.outputs.firmware-version }}
firmware-version-updated: ${{ steps.compile-bsom.outputs.firmware-version-updated }}
release-url: ${{ steps.release.outputs.html_url }}
strategy:
matrix:
platform: ['bsom', 'b5som']
steps:
# Generate a GitHub App token using the official action - UNCONDITIONALLY
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
# Explicitly specify contents write permission to push changes
permission-contents: write
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Compile application for BSOM
id: compile-bsom
if: matrix.platform == 'bsom'
uses: particle-iot/compile-action@9dbe1eb567c6268f1baa7458217d5d6e5553850d
with:
particle-platform-name: 'bsom'
auto-version: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.version_increment != 'no' }}
device-os-version: 6.2.1
- name: Compile application for B5SOM
id: compile-b5som
if: matrix.platform == 'b5som'
uses: particle-iot/compile-action@9dbe1eb567c6268f1baa7458217d5d6e5553850d
with:
particle-platform-name: 'b5som'
auto-version: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.version_increment != 'no' }}
device-os-version: 6.2.1
- name: Upload BSOM artifacts
if: matrix.platform == 'bsom'
uses: actions/upload-artifact@v4
with:
name: bsom-release-artifacts
path: |
${{ steps.compile-bsom.outputs.firmware-path }}
${{ steps.compile-bsom.outputs.target-path }}
- name: Upload B5SOM artifacts
if: matrix.platform == 'b5som'
uses: actions/upload-artifact@v4
with:
name: b5som-release-artifacts
path: |
${{ steps.compile-b5som.outputs.firmware-path }}
${{ steps.compile-b5som.outputs.target-path }}
- name: Commit updated version file
id: commit
if: matrix.platform == 'bsom' && steps.compile-bsom.outputs.firmware-version-updated == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git commit -m "Update firmware version" -a
echo "updated-version-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
# When a GitHub Action pushes commits or tags, it does not trigger a new GitHub Action job
- name: Push changes
if: matrix.platform == 'bsom' && steps.compile-bsom.outputs.firmware-version-updated == 'true'
run: |
git push origin HEAD:${{ github.ref_name }}
- name: Create archive and rename firmware files for BSOM
if: matrix.platform == 'bsom' && steps.compile-bsom.outputs.firmware-version-updated == 'true'
run: |
tar -czf debug-objects-bsom.tar.gz ${{ steps.compile-bsom.outputs.target-path }}
# Copy firmware binary with version in filename
cp ${{ steps.compile-bsom.outputs.firmware-path }} firmware-bsom-${{ steps.compile-bsom.outputs.firmware-version }}.bin
- name: Create archive and rename firmware files for B5SOM
if: matrix.platform == 'b5som'
run: |
tar -czf debug-objects-b5som.tar.gz ${{ steps.compile-b5som.outputs.target-path }}
# Copy firmware binary with version in filename
VERSION=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name' | sed 's/^v//')
if [ "$VERSION" == "null" ] || [ -z "$VERSION" ]; then
VERSION="0.0.1"
fi
cp ${{ steps.compile-b5som.outputs.firmware-path }} firmware-b5som-$VERSION.bin
- name: Upload versioned firmware artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-versioned-firmware
path: firmware-${{ matrix.platform }}-*.bin
create-release:
name: Create GitHub Release
needs: release
runs-on: ubuntu-latest
if: needs.release.outputs.firmware-version-updated == 'true'
outputs:
release-url: ${{ steps.release.outputs.html_url }}
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write
- name: Download all versioned firmware artifacts
uses: actions/download-artifact@v4
with:
path: ./release-files
- name: Prepare release artifacts
run: |
find ./release-files -name "*.bin" | head -10
ls -la ./release-files/
- name: Create GitHub release
id: release
uses: ncipollo/release-action@v1
with:
artifacts: ./release-files/**/*.bin
generateReleaseNotes: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.release_notes == '' }}
body: ${{ github.event.inputs.release_notes }}
name: "Firmware v${{ needs.release.outputs.firmware-version }}"
tag: "v${{ needs.release.outputs.firmware-version }}"
token: ${{ steps.app-token.outputs.token }}
upload-bsom-to-particle:
name: Upload BSOM to Particle Projects
needs: [release, create-release]
runs-on: ubuntu-latest
# Only run if release job has completed and the firmware version was updated
if: needs.release.outputs.firmware-version-updated == 'true'
strategy:
matrix:
project:
- name: "GEMS Demo"
product_id_secret: "PARTICLE_GEMS_DEMO_PRODUCT_ID"
- name: "Runk Lab (B SoM)"
product_id_secret: "PARTICLE_RUNCK_LAB_BSOM_PRODUCT_ID"
- name: "WinterTurf - v3"
product_id_secret: "PARTICLE_WINTERTURF_PRODUCT_ID"
- name: "Plant Pathways"
product_id_secret: "PARTICLE_PLANT_PATHWAYS_PRODUCT_ID"
- name: "Sharma V3 Irrigation"
product_id_secret: "PARTICLE_SHARMA_V3_IRRIGATION_PRODUCT_ID"
- name: "Roadside Turf"
product_id_secret: "PARTICLE_ROADSIDE_TURF_PRODUCT_ID"
- name: "PepsiCo"
product_id_secret: "PARTICLE_PEPSICO_PRODUCT_ID"
- name: "Precision Ag Pilot"
product_id_secret: "PARTICLE_PRECISION_AG_PILOT_PRODUCT_ID"
- name: "Turf Disease Pilot"
product_id_secret: "PARTICLE_TURF_DISEASE_PILOT_PRODUCT_ID"
- name: "Legacy Irrigation"
product_id_secret: "PARTICLE_LEGACY_IRRIGATION_PRODUCT_ID"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download BSOM release artifacts
uses: actions/download-artifact@v4
with:
name: bsom-release-artifacts
path: ./bsom-release
- name: Find BSOM firmware binary
id: find_binary
run: |
FIRMWARE=$(find ./bsom-release -name "*.bin" -type f | head -n 1)
# Create a properly named firmware file
cp "$FIRMWARE" "firmware-bsom-${{ needs.release.outputs.firmware-version }}.bin"
echo "firmware-path=firmware-bsom-${{ needs.release.outputs.firmware-version }}.bin" >> $GITHUB_OUTPUT
- name: Upload BSOM firmware to ${{ matrix.project.name }}
uses: particle-iot/firmware-upload-action@v1
with:
particle-access-token: ${{ secrets.PARTICLE_ACCESS_TOKEN }}
firmware-path: ${{ steps.find_binary.outputs.firmware-path }}
firmware-version: ${{ needs.release.outputs.firmware-version }}
product-id: ${{ secrets[matrix.project.product_id_secret] }}
title: 'Firmware v${{ needs.release.outputs.firmware-version }}'
description: '[Firmware v${{ needs.release.outputs.firmware-version }} GitHub Release](${{ needs.create-release.outputs.release-url }})'
- name: Log upload success
run: |
echo "✅ Successfully uploaded BSOM firmware v${{ needs.release.outputs.firmware-version }} to ${{ matrix.project.name }}"
upload-b5som-to-particle:
name: Upload B5SOM to Particle Projects
needs: [release, create-release]
runs-on: ubuntu-latest
# Only run if release job has completed and the firmware version was updated
if: needs.release.outputs.firmware-version-updated == 'true'
strategy:
matrix:
project:
- name: "WinterTurf - v3 International"
product_id_secret: "PARTICLE_WINTERTURF_INTERNATIONAL_PRODUCT_ID"
- name: "Stellenbosch"
product_id_secret: "PARTICLE_STELLENBOSCH_PRODUCT_ID"
- name: "Runk Lab (B5 SoM)"
product_id_secret: "PARTICLE_RUNCK_LAB_B5SOM_PRODUCT_ID"
#- name: "LCCMR Irrigation Sensing"
#product_id_secret: "PARTICLE_LCCMR_IRRIGATION_SENSING_PRODUCT_ID"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download B5SOM release artifacts
uses: actions/download-artifact@v4
with:
name: b5som-release-artifacts
path: ./b5som-release
- name: Find B5SOM firmware binary
id: find_binary
run: |
FIRMWARE=$(find ./b5som-release -name "*.bin" -type f | head -n 1)
# Create a properly named firmware file
cp "$FIRMWARE" "firmware-b5som-${{ needs.release.outputs.firmware-version }}.bin"
echo "firmware-path=firmware-b5som-${{ needs.release.outputs.firmware-version }}.bin" >> $GITHUB_OUTPUT
- name: Upload B5SOM firmware to ${{ matrix.project.name }}
uses: particle-iot/firmware-upload-action@v1
with:
particle-access-token: ${{ secrets.PARTICLE_ACCESS_TOKEN }}
firmware-path: ${{ steps.find_binary.outputs.firmware-path }}
firmware-version: ${{ needs.release.outputs.firmware-version }}
product-id: ${{ secrets[matrix.project.product_id_secret] }}
title: 'Firmware v${{ needs.release.outputs.firmware-version }}'
description: '[Firmware v${{ needs.release.outputs.firmware-version }} GitHub Release](${{ needs.create-release.outputs.release-url }})'
- name: Log upload success
run: |
echo "✅ Successfully uploaded B5SOM firmware v${{ needs.release.outputs.firmware-version }} to ${{ matrix.project.name }}"