Skip to content

Commit dc66bc0

Browse files
committed
docker: update ESP-IDF installation process
Refactor the ESP-IDF installation in the Dockerfile to remove the cleanup of the git directory after cloning. This change simplifies the build process and retains the git history for potential debugging. docs: update README for ESP32 build parameters Revise the README to clarify the supported platforms and input parameters for the GitHub Action. Removed references to 'target' and improved descriptions for 'repo_remote' and 'repo_ref'. action: remove target input from action.yml Eliminate the 'target' input from the action definition, streamlining the input parameters for the MicroPython port builder. entrypoint: enhance build process for multiple boards Refactor the entrypoint script to support building for multiple boards and variants. This includes improved artifact handling and clearer build output. Signed-off-by: Chiho Sin <[email protected]>
1 parent 943280e commit dc66bc0

File tree

4 files changed

+146
-77
lines changed

4 files changed

+146
-77
lines changed

Containerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ ENV IDF_TOOLS_PATH=/opt/esp-idf-tools
106106
ENV ESP_ROM_ELF_DIR=/opt/esp-idf-tools
107107

108108
ARG IDF_VERSION=v5.4.2
109-
RUN git clone -b "${IDF_VERSION}" --recursive --depth 1 --shallow-submodules https://github.com/espressif/esp-idf.git "${IDF_PATH}" \
110-
&& rm -rf "${IDF_PATH}"/.git
109+
RUN git clone -b "${IDF_VERSION}" --recursive --depth 1 --shallow-submodules https://github.com/espressif/esp-idf.git "${IDF_PATH}"
111110

112111
RUN --mount=type=cache,target=/root/.cache/pip \
113112
--mount=type=cache,target=/opt/esp-idf-tools/dist \

README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## Introduction
44

5-
`action-micropython-builder` is a GitHub Action designed to build MicroPython ports. It supports multiple platforms and targets, enabling developers to quickly build and release MicroPython projects.
5+
`action-micropython-builder` is a GitHub Action designed to build MicroPython ports. It supports multiple platforms and boards, enabling developers to quickly build MicroPython projects.
66

77
## Features
88

9-
- Supports multiple MicroPython platforms (e.g., espressif, nordic).
10-
- Supports build and release targets.
11-
- Allows specifying single or multiple boards for building.
9+
- Supports multiple MicroPython platforms (e.g., esp32, nrf).
10+
- Allows specifying custom repository remote and reference.
11+
- Supports building specific boards.
1212

1313
## Usage
1414

@@ -17,7 +17,6 @@
1717
Add the following to your GitHub Actions workflow file:
1818

1919
```yaml
20-
yaml
2120
jobs:
2221
build:
2322
runs-on: ubuntu-latest
@@ -30,24 +29,23 @@ jobs:
3029
uses: fobe-projects/action-micropython-builder@v1
3130
with:
3231
port: "esp32"
33-
target: "build"
3432
board: "FOBE_QUILL_ESP32S3_MESH"
3533
```
3634
3735
### 2. Input Parameters
3836
3937
| Parameter Name | Required | Default | Description |
4038
|-----------------|----------|----------|-----------------------------------------------|
41-
| `port` | Yes | None | MicroPython platform (e.g., espressif, nordic). |
42-
| `target` | No | `build` | Target to run, options are `build` or `release`. |
43-
| `board` | No | None | board to build (if target is `release`, specify multiple boards). |
39+
| `repo_remote` | No | `origin` | The MicroPython repository remote ('origin', 'upstream'). |
40+
| `repo_ref` | No | `main` | The MicroPython repository reference (branch, tag, commit). |
41+
| `port` | Yes | None | The MicroPython platform to build (esp32, nrf). |
42+
| `board` | No | `""` | The MicroPython board to build. |
4443

4544
### 3. Examples
4645

4746
#### Build a Single Board
4847

4948
```yaml
50-
yaml
5149
jobs:
5250
build:
5351
runs-on: ubuntu-latest
@@ -60,28 +58,44 @@ jobs:
6058
uses: fobe-projects/action-micropython-builder@v1
6159
with:
6260
port: "esp32"
63-
target: "build"
6461
board: "FOBE_QUILL_ESP32S3_MESH"
6562
```
6663

67-
#### Release Multiple Boards
64+
#### Build with Custom Repository Reference
6865

6966
```yaml
70-
yaml
7167
jobs:
72-
release:
68+
build:
7369
runs-on: ubuntu-latest
7470
7571
steps:
7672
- name: Checkout repository
7773
uses: actions/checkout@v3
7874
79-
- name: Release MicroPython for multiple boards
75+
- name: Build MicroPython from specific branch
8076
uses: fobe-projects/action-micropython-builder@v1
8177
with:
78+
repo_remote: "upstream"
79+
repo_ref: "v1.20.0"
8280
port: "nrf"
83-
target: "release"
84-
board: "board1 board2 board3"
81+
board: "pca10040"
82+
```
83+
84+
#### Build without Specifying Board
85+
86+
```yaml
87+
jobs:
88+
build:
89+
runs-on: ubuntu-latest
90+
91+
steps:
92+
- name: Checkout repository
93+
uses: actions/checkout@v3
94+
95+
- name: Build MicroPython for ESP32 platform
96+
uses: fobe-projects/action-micropython-builder@v1
97+
with:
98+
port: "esp32"
8599
```
86100

87101
## License

action.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ inputs:
1717
port:
1818
description: The MicroPython platform to build (esp32, nrf)
1919
required: true
20-
target:
21-
description: The MicroPython run target (default is 'build')
22-
required: false
23-
default: build
2420
board:
25-
description: The MicroPython board to build (if target is release, specify multiple boards)
21+
description: The MicroPython board to build
2622
default: ""
2723
required: false
2824

@@ -35,13 +31,11 @@ runs:
3531
--env GITHUB_ACTIONS \
3632
--env REPO_REMOTE \
3733
--env REPO_REF \
38-
--env MPY_TARGET \
39-
--env MPY_BOARD \
34+
--env BOARD \
4035
-v $GITHUB_WORKSPACE/bin:/workspace/bin \
4136
ghcr.io/fobe-projects/action-micropython-builder:main-${{ inputs.port }}
4237
shell: bash
4338
env:
4439
REPO_REMOTE: ${{ inputs.repo_remote }}
4540
REPO_REF: ${{ inputs.repo_ref }}
46-
MPY_TARGET: ${{ inputs.target }}
47-
MPY_BOARD: ${{ inputs.board }}
41+
BOARD: ${{ inputs.board }}

entrypoint.sh

Lines changed: 111 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,139 @@
11
#!/usr/bin/env bash
2+
23
set -euo pipefail
34

5+
WORKSPACE=/workspace
6+
JOBS=$(nproc)
7+
48
# Define vars (use safe defaults so -u won't fail)
59
: "${GITHUB_ACTIONS:=false}"
6-
710
# Inputs (provide safe defaults)
811
: "${REPO_REMOTE:=origin}"
912
: "${REPO_REF:=main}"
10-
: "${MPY_TARGET:=build}"
11-
: "${MPY_BOARD:=}"
12-
: "${MPY_FLAGS:=}"
13+
: "${BOARD:=}"
1314

1415
# Reset to the target SHA
1516
git fetch origin --tags --prune
1617
git fetch upstream --tags --prune
1718
git fetch "${REPO_REMOTE}" "${REPO_REF}"
1819
git reset --hard FETCH_HEAD
1920
git repack -d
20-
# trunk-ignore(shellcheck/SC2312)
21-
echo "Repository firmware version: $(git describe --tags --dirty --always --match 'v[1-9].*')"
21+
22+
# Make the firmware tag
23+
# final filename will be <BOARD><-VARIANT>-<DATE>-v<SEMVER>.ext
24+
# where SEMVER is vX.Y.Z or vX.Y.Z-preview.N.gHASH or vX.Y.Z-preview.N.gHASH.dirty
25+
FW_DATE=$(date '+%Y%m%d')
26+
# same logic as makeversionhdr.py, convert git-describe output into semver-compatible
27+
FW_GIT_TAG="$(git describe --tags --dirty --always --match 'v[1-9].*')"
28+
FW_SEMVER_MAJOR_MINOR_PATCH="$(echo "${FW_GIT_TAG}" | cut -d'-' -f1)"
29+
FW_SEMVER_PRERELEASE="$(echo "${FW_GIT_TAG}" | cut -s -d'-' -f2-)"
30+
if [[ -z ${FW_SEMVER_PRERELEASE} ]]; then
31+
FW_SEMVER="${FW_SEMVER_MAJOR_MINOR_PATCH}"
32+
else
33+
FW_SEMVER="${FW_SEMVER_MAJOR_MINOR_PATCH}-$(echo "${FW_SEMVER_PRERELEASE}" | tr - .)"
34+
fi
35+
FW_TAG="-${FW_DATE}-${FW_SEMVER}"
36+
echo "Firmware version: ${FW_SEMVER}"
37+
echo "Firmware tag: ${FW_TAG}"
2238

2339
# Espressif IDF
2440
if [[ ${MPY_PORT} == "esp32" ]]; then
25-
export IDF_PATH=/opt/esp-idf
26-
export IDF_TOOLS_PATH=/opt/esp-idf-tools
27-
export ESP_ROM_ELF_DIR=/opt/esp-idf-tools
28-
# trunk-ignore(shellcheck/SC1091)
29-
source "${IDF_PATH}/export.sh"
41+
export IDF_PATH=/opt/esp-idf
42+
export IDF_TOOLS_PATH=/opt/esp-idf-tools
43+
export ESP_ROM_ELF_DIR=/opt/esp-idf-tools
44+
# trunk-ignore(shellcheck/SC1091)
45+
source "${IDF_PATH}/export.sh"
3046
fi
3147

32-
JOBS=$(nproc)
33-
3448
make -j"${JOBS}" -C mpy-cross
3549
make -C ports/"${MPY_PORT}" submodules
3650

3751
# Build
38-
if [[ ${MPY_TARGET} == "build" ]]; then
39-
echo "Building MicroPython: ${MPY_PORT}:${MPY_BOARD}"
40-
# trunk-ignore(shellcheck/SC2312)
41-
# trunk-ignore(shellcheck/SC2086)
42-
# trunk-ignore(shellcheck/SC2250)
43-
make -j"${JOBS}" -C "ports/${MPY_PORT}" BOARD="${MPY_BOARD}" $MPY_FLAGS
44-
# trunk-ignore(shellcheck/SC2231)
45-
for OUTDIR in /workspace/ports/${MPY_PORT}/build-${MPY_BOARD}*; do
46-
if [[ -d "${OUTDIR}" ]]; then
47-
DESTDIR="/workspace/bin/${MPY_BOARD}"
48-
mkdir -p "${DESTDIR}"
49-
find "${OUTDIR}" -maxdepth 1 -type f \( -name '*.uf2' -o -name '*.bin' -o -name '*.hex' -o -name '*.elf' -o -name '*.dfu' -o -name '*.map' \) -exec cp {} "${DESTDIR}" \;
52+
echo "Build ${MPY_PORT} firmware: ${BOARD}"
53+
mkdir -p "${WORKSPACE}/bin"
54+
55+
function copy_artefacts {
56+
local dest_dir=$1
57+
local descr=$2
58+
local fw_tag=$3
59+
local build_dir=$4
60+
shift 4
61+
for ext in "$@"; do
62+
dest=${dest_dir}/${descr}${fw_tag}.${ext}
63+
if [[ -r ${build_dir}/firmware.${ext} ]]; then
64+
mv "${build_dir}"/firmware."${ext}" "${dest}"
65+
elif [[ -r ${build_dir}/micropython.${ext} ]]; then
66+
# esp32 has micropython.elf, etc
67+
mv "${build_dir}"/micropython."${ext}" "${dest}"
68+
# trunk-ignore(shellcheck/SC2292)
69+
# trunk-ignore(shellcheck/SC2166)
70+
elif [ "${ext}" = app-bin -a -r "${build_dir}"/micropython.bin ]; then
71+
# esp32 has micropython.bin which is just the application
72+
mv "${build_dir}"/micropython.bin "${dest}"
73+
fi
74+
done
75+
}
76+
77+
function build_board {
78+
# trunk-ignore(shellcheck/SC2002)
79+
DESCR=$(cat ports/"${MPY_PORT}"/boards/"${BOARD}"/board.json | python3 -c "import json,sys; print(json.load(sys.stdin).get('id', '${BOARD}'))")
80+
# Build the "default" variant. For most boards this is the only thing we build.
81+
echo "building ${DESCR}"
82+
make -j"${JOBS}" -C ports/"${MPY_PORT}" BOARD="${BOARD}"
83+
if [[ ! -d ports/"${MPY_PORT}"/build-"${BOARD}" ]]; then
84+
mv ports/"${MPY_PORT}"/build-"${BOARD}"-* ports/"${MPY_PORT}"/build-"${BOARD}"
85+
fi
86+
copy_artefacts "${WORKSPACE}/bin" "${DESCR}" "${FW_TAG}" ports/"${MPY_PORT}"/build-"${BOARD}" "$@"
87+
# Query variants from board.json and build them.
88+
# trunk-ignore(shellcheck/SC2002)
89+
for VARIANT in $(cat ports/"${MPY_PORT}"/boards/"${BOARD}"/board.json | python3 -c "import json,sys; print(' '.join(json.load(sys.stdin).get('variants', {}).keys()))"); do
90+
echo "building variant ${DESCR} ${VARIANT}"
91+
make -j"${JOBS}" -C ports/"${MPY_PORT}" BOARD="${BOARD}" BOARD_VARIANT="${VARIANT}"
92+
if [[ ! -d ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}" ]]; then
93+
mv ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}"-* ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}"
5094
fi
51-
done
52-
echo "Build artifacts are located at: /workspace/bin"
95+
copy_artefacts "${WORKSPACE}/bin" "${DESCR}-${VARIANT}" "${FW_TAG}" ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}" "$@"
96+
done
97+
}
98+
99+
if [[ ${MPY_PORT} == "alif" ]]; then
100+
build_board zip
53101
fi
54102

55-
# Release
56-
if [[ ${MPY_TARGET} == "release" ]]; then
57-
echo "Building MicroPython release: ${MPY_PORT}:${MPY_BOARD}"
58-
for BOARD in ${MPY_BOARD}; do
59-
echo "Building for board: ${BOARD}"
60-
# trunk-ignore(shellcheck/SC2312)
61-
# trunk-ignore(shellcheck/SC2086)
62-
# trunk-ignore(shellcheck/SC2250)
63-
make -j"${JOBS}" -C "ports/${MPY_PORT}" BOARD="${BOARD}" $MPY_FLAGS || true
64-
done
65-
mkdir -p /workspace/bin
66-
for BOARD in ${MPY_BOARD}; do
67-
# trunk-ignore(shellcheck/SC2231)
68-
for OUTDIR in /workspace/ports/${MPY_PORT}/build-${BOARD}*; do
69-
if [[ -d ${OUTDIR} ]]; then
70-
DESTDIR="/workspace/bin/${BOARD}"
71-
mkdir -p "${DESTDIR}"
72-
find "${OUTDIR}" -maxdepth 1 -type f \( -name '*.uf2' -o -name '*.bin' -o -name '*.hex' -o -name '*.elf' -o -name '*.dfu' -o -name '*.map' \) -exec cp {} "${DESTDIR}" \;
73-
fi
74-
done
75-
done
76-
echo "Build artifacts are located at: /workspace/bin/"
103+
if [[ ${MPY_PORT} == "cc3200" ]]; then
104+
build_board zip
77105
fi
106+
107+
if [[ ${MPY_PORT} == "esp32" ]]; then
108+
build_board bin elf map uf2 app-bin
109+
fi
110+
111+
if [[ ${MPY_PORT} == "esp8266" ]]; then
112+
build_board bin elf map
113+
fi
114+
115+
if [[ ${MPY_PORT} == "mimxrt" ]]; then
116+
build_board bin hex uf2
117+
fi
118+
119+
if [[ ${MPY_PORT} == "nrf" ]]; then
120+
build_board bin hex uf2
121+
fi
122+
123+
if [[ ${MPY_PORT} == "renesas_ra" ]]; then
124+
build_board bin hex
125+
fi
126+
127+
if [[ ${MPY_PORT} == "rp2" ]]; then
128+
build_board uf2
129+
fi
130+
131+
if [[ ${MPY_PORT} == "samd" ]]; then
132+
build_board uf2
133+
fi
134+
135+
if [[ ${MPY_PORT} == "stm32" ]]; then
136+
build_board dfu hex
137+
fi
138+
139+
echo "Build artifacts are located at: ${WORKSPACE}/bin"

0 commit comments

Comments
 (0)