Skip to content

Commit

Permalink
ci(GitHub): build ZIP release archives
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
leon0399 committed Nov 27, 2022
1 parent 8c8e131 commit 0f738c3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,36 @@ jobs:
pio upgrade --dev
pio pkg update --global
- name: Update build command (non-Windows)
run: |
sed -i '/\[env\]/p; s/\[env\]/upload_protocol = custom/' platformio.ini
sed -i '/\[env\]/p; s/\[env\]/upload_command = \$PYTHONEXE .\/scripts\/ci\/create-archive.py \$FLASH_EXTRA_IMAGES \$ESP32_APP_OFFSET \$SOURCE/' platformio.ini
- name: Build
run: |
pio run --environment ${{matrix.target}}
mkdir build
echo "::group::platformio.ini"
cat platformio.ini
echo "::endgroup::"
echo "::group::pio run"
pio run --environment ${{matrix.target}} --target upload
echo "::endgroup::"
unzip -l ./build/firmware.zip
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{matrix.target}}
path: ./.pio/build/${{matrix.target}}/firmware.bin
name: firmware-${{matrix.target}}
path: ./build/firmware.zip
retention-days: 5

- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
asset_name: ${{matrix.target}}.bin
file: ./.pio/build/${{matrix.target}}/firmware.bin
asset_name: ${{matrix.target}}.zip
file: ./build/firmware.zip
tag: ${{github.ref}}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
.piolibdeps
.clang_complete
.gcc-flags.json
/lib/
/lib/

# CI
/build/
31 changes: 31 additions & 0 deletions scripts/ci/create-archive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

import sys
from os import getcwd
from ntpath import basename
from zipfile import ZipFile
import json

n = 2
partitions_arg = sys.argv[1:]
partitions = final = [partitions_arg[i * n:(i + 1) * n] for i in range((len(partitions_arg) + n - 1) // n )]

with ZipFile('build/firmware.zip', 'w') as archive:
print('Creating "' + archive.filename + '"', end='\n')
parts = []

for [offset, path] in partitions:
filename = basename(path)
archive.write(path, filename)
partition = {
'path': filename,
'offset': int(offset, 16),
}
parts.append(partition)

manifest = {
'chipFamily': 'ESP32',
'parts': parts,
}
archive.writestr('manifest.json', json.dumps(manifest))

0 comments on commit 0f738c3

Please sign in to comment.