-
Notifications
You must be signed in to change notification settings - Fork 29
302 lines (263 loc) · 11.2 KB
/
Copy pathBuildAndDeploy.yml
File metadata and controls
302 lines (263 loc) · 11.2 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# https://github.com/marketplace/actions/test-compile-for-arduino
# https://github.com/marketplace/actions/test-compile-for-arduino#multiple-boards-with-parameter-using-the-script-directly
# https://github.com/actions/upload-release-asset/issues/17
# https://github.com/dh1tw/remoteAudio/blob/master/.github/workflows/build.yml
name: Build&Deploy
on:
push:
branches:
- master
- stable
- prelive
- development
paths:
- '**.cpp'
- '**.h'
- '**.yml'
- '**.sh'
- '**.py'
- '**.json'
- '**.js'
- '**.css'
- '**.html'
jobs:
build:
name: BuildAndDeploy-${{ matrix.variant.firmware }}
runs-on: ubuntu-latest
env:
REPOSITORY: ${{ github.event.repository.name }}
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
GITHUB_RUN: ${{ github.run_number }}
outputs:
fw_version: ${{ steps.json_params.outputs.version }}
fw_build: ${{ steps.json_params.outputs.build }}
strategy:
matrix:
variant:
- firmware: firmware_ESP32
architecture: ESP32
subvariant: standard
- firmware: firmware_ESP32-S2
architecture: ESP32-S2
subvariant: standard
- firmware: firmware_ESP32-S3
architecture: ESP32-S3
subvariant: standard
- firmware: firmware_ESP32-C3
architecture: ESP32-C3
subvariant: standard
steps:
- name: checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@main
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -U platformio
pip install -U esptool
- name: Run PlatformIO
id: buildFw
run: |
platformio run -e ${{ matrix.variant.firmware }}
if [ -d "data" ]; then
platformio run --target buildfs -e ${{ matrix.variant.firmware }}
fi
python .github/scripts/createMergedFirmware.py \
--ChipFamily ${{ matrix.variant.architecture }} \
--BuildDir .pio/build/${{ matrix.variant.firmware }} \
--PathOfPartitionsCSV partitions.csv \
>> "$GITHUB_OUTPUT"
- name: Build merged Firmware
if: ${{ steps.buildFw.outputs.command != 'None' }}
run: |
${{steps.buildFw.outputs.command}}
- name: Display generated files
run: |
ls -R .pio/build/${{ matrix.variant.firmware }}/
- name: Schreibe Json/Manifest File
id: json_params
run: |
mkdir -p release artifacts
python .github/scripts/createManifest.py \
--arch ${{ matrix.variant.architecture }} \
--variant ${{ matrix.variant.subvariant }} \
--stage ${{ env.BRANCH_NAME }} \
--repository ${{ env.REPOSITORY }} \
--binarypath .pio/build/${{ matrix.variant.firmware }}/ \
--releasepath release \
--artifactpath artifacts \
--build ${{ github.run_number }} \
--releasefile include/_Release.h \
>> "$GITHUB_OUTPUT"
- name: Upload firmware artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.variant.firmware }}
path: artifacts/*
# - name: Upload to AWS S3
# uses: jakejarvis/s3-sync-action@master
# with:
# args: '--acl public-read --follow-symlinks'
# env:
# AWS_S3_BUCKET: 'tfa-releases'
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: 'eu-central-1' # optional: defaults to us-east-1
# SOURCE_DIR: 'release' # optional: defaults to entire repository
# DEST_DIR: ${{ env.REPOSITORY }}
web-installer:
needs: [build]
runs-on: ubuntu-latest
env:
REPOSITORY: ${{ github.event.repository.name }}
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
VersDir: "web-installer/firmware/v${{ needs.build.outputs.fw_version }}-${{ needs.build.outputs.fw_build }}-${{ github.base_ref || github.ref_name }}"
FwDir: "web-installer/firmware"
steps:
- name: Checkout web-installer Repository
uses: actions/checkout@v4
with:
ref: 'web-installer'
path: 'web-installer'
- name: Checkout Application Repository
uses: actions/checkout@v4
with:
path: 'app'
sparse-checkout: |
.github
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Download all Artifacts
uses: actions/download-artifact@v4
with:
path: ${{ env.VersDir }}
- name: Display generated files
run: |
ls -R ./
- name: create "manifestAll" and "versions" JSON
run: |
python -m pip install --upgrade pip
python app/.github/scripts/createManifestAll_VersionsFile.py --FwDir ${{ env.FwDir }} --VersDir ${{ env.VersDir }}
- name: Commit and push changes
run: |
cd web-installer
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add *
git commit -m "neue Firmware v${{ needs.build.outputs.fw_version }}-${{ needs.build.outputs.fw_build }}-${{ env.BRANCH_NAME }}"
git push origin web-installer
create_Release:
needs: [build]
runs-on: ubuntu-latest
if: endsWith(github.ref, 'master') || endsWith(github.ref, 'stable') || endsWith(github.ref, 'prelive')
env:
GITHUB_REPOSITORY: ${{ github.event.repository.name }}
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
GITHUB_OWNER: ${{ github.repository_owner }}
steps:
- name: Checkout web-installer Repository
uses: actions/checkout@v4
with:
ref: 'web-installer'
path: 'web-installer'
- name: Checkout Application Repository
uses: actions/checkout@v4
with:
path: 'app'
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ./release
- name: set Environment Variables
id: set_env_var
run: |
VERSION=$(sed 's/[^0-9|.]//g' app/include/_Release.h) # zb. 2.4.2
if [[ "master stable" == *${{ env.BRANCH_NAME }}* ]]; then IS_PRE='false'; else IS_PRE='true'; fi
if [[ "master stable" == *${{ env.BRANCH_NAME }}* ]]; then POSTFIX='' ; else POSTFIX='PRE'; fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "IS_PRERELEASE=${IS_PRE}" >> "$GITHUB_OUTPUT"
echo "RELEASENAME_POSTFIX=${POSTFIX}" >> "$GITHUB_OUTPUT"
RELEASEBODY=$(awk -v RS='Release ' '/'$VERSION':(.*)/ {print $0}' app/ChangeLog.md)
echo "${RELEASEBODY}" > CHANGELOG.md
echo "tagname=v.${VERSION}-${POSTFIX}-${{ github.run_id }}" >> "$GITHUB_OUTPUT"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.set_env_var.outputs.tagname }}
release_name: Release ${{ steps.set_env_var.outputs.version }} ${{ steps.set_env_var.outputs.RELEASENAME_POSTFIX }}
body_path: CHANGELOG.md
draft: false
prerelease: ${{ steps.set_env_var.outputs.IS_PRERELEASE }}
# erstelle das manifestAll.json speziell für das release mit den korrekten Pfaden
# füge gleichzeitg das ReleaseTag hinzu
#--ReleaseTagName ${{ steps.set_env_var.outputs.tagname }} \
- name: Create Release manifestAll JSON
run: |
python app/.github/scripts/createReleaseAssetManifestAll.py \
--ReleaseDir release \
--ReleaseURL "${{github.server_url}}/${{env.GITHUB_OWNER}}/${{ env.GITHUB_REPOSITORY }}/releases/download/${{ steps.set_env_var.outputs.tagname }}"
# suche alle Dateien aus dem Ordner release (siehe asset-download), incl aller unterordner und lade diese einzeln als release-asset hoch
# jede Datei behält ihren originalen Namen und contenttype. Identische Dateinamen werden überschrieben
- name: Upload Release Assets
env:
GH_TOKEN: ${{ github.token }}
run: |
for dir in $(find release -type d); do
for file in "$dir"/*; do
if [ -f "$file" ]; then
if [[ "$file" == *files.json || "$file" == *manifest.json ]]; then
continue
fi
echo "Uploading $file"
gh release upload -R ${{env.GITHUB_OWNER}}/${{ env.GITHUB_REPOSITORY }} ${{ steps.set_env_var.outputs.tagname }} "$file" --clobber
fi
done
done
# gehe durch alle verfügbaren releases im Repository durch, suche die manifestAll.json und filesAll.json.
# Lade diese herunter ins lokale verzeichnis ./manifests und erstelle auf dieser Grundlage die releases.json
- name: Download all Manifests, create ReleaseVersions
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir -p manifests
tagNames=$(gh release ls -R ${{env.GITHUB_OWNER}}/${{ env.GITHUB_REPOSITORY }} --json tagName)
for tag in $(echo "$tagNames" | jq -r '.[].tagName'); do
for asset in $(gh release view $tag -R ${{env.GITHUB_OWNER}}/${{ env.GITHUB_REPOSITORY }} --json assets --jq '.assets[].name' | grep -E 'manifestAll|filesAll'); do
echo "Downloading file: gh release download $tag -R ${{env.GITHUB_OWNER}}/${{ env.GITHUB_REPOSITORY }} --pattern '$asset' --dir 'manifests/${tag}/'"
gh release download $tag \
-R ${{env.GITHUB_OWNER}}/${{ env.GITHUB_REPOSITORY }} \
--pattern "$asset" \
--dir "manifests/${tag}/" || true
done
mkdir -p manifests/${tag}/
gh release view $tag -R ${{env.GITHUB_OWNER}}/${{ env.GITHUB_REPOSITORY }} --json assets > "manifests/${tag}/assets.json"
done
python app/.github/scripts/createReleaseVersions.py \
--ManifestDir manifests \
--TargetDir web-installer/firmware
ls -R ./manifests
ls -R ./release
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd web-installer
git pull
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add *
git commit -m "update releases.json"
git push origin web-installer
- name: Upload Changelog artifact
uses: actions/upload-artifact@v4
with:
name: CHANGELOG.md
path: CHANGELOG.md