Skip to content

Commit 8a6c9d7

Browse files
committed
CI pipline
1 parent ccf1b28 commit 8a6c9d7

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

.github/workflows/platformio.yml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: platformio
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
jobs:
11+
12+
build:
13+
needs: test
14+
runs-on: ubuntu-22.04
15+
strategy:
16+
matrix:
17+
target: ['esp32', 'esp8266']
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Extract Version
21+
run: |
22+
echo "build_name=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
23+
echo "build_branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
24+
echo "build_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
25+
echo "build_sha=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_ENV
26+
27+
- name: Make Version
28+
run: |
29+
echo "build_file_devel=espfc_${{ env.build_sha }}_${{ matrix.target }}" >> $GITHUB_ENV
30+
echo "build_file_release=espfc_${{ env.build_tag }}_${{ matrix.target }}" >> $GITHUB_ENV
31+
32+
- name: Print Version
33+
run: |
34+
echo SHA: ${{ env.build_sha }}
35+
echo TAG: ${{ env.build_tag }}
36+
echo BRANCH: ${{ env.build_branch }}
37+
echo NAME: ${{ env.build_name }}
38+
echo DEVEL: ${{ env.build_file_devel }}
39+
echo RELEASE: ${{ env.build_file_release }}
40+
41+
- name: Cache pip
42+
uses: actions/cache@v4
43+
with:
44+
path: ~/.cache/pip
45+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
46+
restore-keys: |
47+
${{ runner.os }}-pip-
48+
49+
- name: Cache PlatformIO
50+
uses: actions/cache@v4
51+
with:
52+
path: ~/.platformio
53+
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
54+
55+
- name: Set up Python
56+
uses: actions/setup-python@v5
57+
with:
58+
python-version: '3.10'
59+
60+
- name: Install Dependencies
61+
run: |
62+
python -m pip install --upgrade pip
63+
pip install platformio
64+
65+
- name: Build Development Target
66+
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
67+
run: |
68+
platformio run -e ${{ matrix.target }}
69+
env:
70+
PLATFORMIO_BUILD_FLAGS: -DESPFC_REVISION=${{ env.build_sha }}
71+
72+
- name: Build Release Target
73+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
74+
run: |
75+
platformio run -e ${{ matrix.target }}
76+
env:
77+
PLATFORMIO_BUILD_FLAGS: -DESPFC_REVISION=${{ env.build_sha }} -DESPFC_VERSION=${{ env.build_tag }}
78+
79+
- name: Create Development Artifact
80+
uses: actions/upload-artifact@v4
81+
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
82+
with:
83+
name: ${{ env.build_file_devel }}.bin
84+
path: .pio/build/${{ matrix.target }}/firmware.bin
85+
86+
- name: Create Development Artifact Merged
87+
uses: actions/upload-artifact@v4
88+
if: ${{ !startsWith(github.ref, 'refs/tags/') && startsWith(matrix.target, 'esp32') }}
89+
with:
90+
name: "${{ env.build_file_devel }}_0x00.bin"
91+
path: .pio/build/${{ matrix.target }}/firmware_0x00.bin
92+
93+
94+
- name: Create Release Artifact
95+
uses: actions/upload-artifact@v4
96+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
97+
with:
98+
name: ${{ env.build_file_release }}.bin
99+
path: .pio/build/${{ matrix.target }}/firmware.bin
100+
101+
- name: Create Release Artifact Merged
102+
uses: actions/upload-artifact@v4
103+
if: ${{ startsWith(github.ref, 'refs/tags/') && startsWith(matrix.target, 'esp32') }}
104+
with:
105+
name: ${{ env.build_file_release }}_0x00.bin
106+
path: .pio/build/${{ matrix.target }}/firmware_0x00.bin

merge_firmware.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Import("env")
2+
3+
APP_BIN = "$BUILD_DIR/${PROGNAME}.bin"
4+
MERGED_BIN = "$BUILD_DIR/${PROGNAME}_0x00.bin"
5+
BOARD_CONFIG = env.BoardConfig()
6+
7+
8+
def merge_bin(source, target, env):
9+
# The list contains all extra images (bootloader, partitions, eboot) and
10+
# the final application binary
11+
flash_images = env.Flatten(env.get("FLASH_EXTRA_IMAGES", [])) + ["$ESP32_APP_OFFSET", APP_BIN]
12+
13+
# Run esptool to merge images into a single binary
14+
env.Execute(
15+
" ".join(
16+
[
17+
"$PYTHONEXE",
18+
"$OBJCOPY",
19+
"--chip",
20+
BOARD_CONFIG.get("build.mcu", "esp32"),
21+
"merge_bin",
22+
"--flash_size",
23+
BOARD_CONFIG.get("upload.flash_size", "4MB"),
24+
"-o",
25+
MERGED_BIN,
26+
]
27+
+ flash_images
28+
)
29+
)
30+
31+
# Add a post action that runs esptoolpy to merge available flash images
32+
env.AddPostAction(APP_BIN , merge_bin)
33+
34+
# Patch the upload command to flash the merged binary at address 0x0
35+
#env.Replace(
36+
# UPLOADERFLAGS=[
37+
# f
38+
# for f in env.get("UPLOADERFLAGS")
39+
# if f not in env.Flatten(env.get("FLASH_EXTRA_IMAGES"))
40+
# ]
41+
# + ["0x0", MERGED_BIN],
42+
# UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS',
43+
#)

platformio.ini

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ build_flags =
2525
platform = espressif32
2626
board = lolin32
2727
framework = arduino
28+
extra_scripts = merge_firmware.py
2829

2930
[env:esp8266]
3031
platform = espressif8266

0 commit comments

Comments
 (0)