Skip to content

Commit 9fa6dfb

Browse files
committed
one job
1 parent 26243fa commit 9fa6dfb

File tree

1 file changed

+74
-91
lines changed

1 file changed

+74
-91
lines changed

.github/workflows/new build.yml

Lines changed: 74 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,23 @@
1-
name: build mpy with camera and jpeg
1+
name: build mpy with camera and jpeg (single job)
22

3-
# 触发条件:仅手动触发
3+
# 仅手动触发
44
on:
55
workflow_dispatch:
66

7-
# 并发控制:同一分支仅保留最新一次运行
7+
# 并发控制:同一分支只保留最新一次
88
concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010
cancel-in-progress: true
1111

1212
env:
13-
MICROPYTHON_DIR: ${{ github.workspace }}/micropython # MicroPython 的目录
14-
ESP_IDF_DIR: ${{ github.workspace }}/esp-idf # ESP-IDF 的目录
15-
ARTIFACTS_DIR: ${{ github.workspace }}/artifacts # 构建产物的目录
16-
MPY_VERSION: v1.25.0 # MicroPython 的版本
17-
ESP_IDF_VERSION: v5.4.1 # ESP-IDF 的版本
13+
MICROPYTHON_DIR: ${{ github.workspace }}/micropython
14+
ESP_IDF_DIR: ${{ github.workspace }}/esp-idf
15+
ARTIFACTS_DIR: ${{ github.workspace }}/artifacts
16+
MPY_VERSION: v1.25.0
17+
ESP_IDF_VERSION: v5.4.1
1818

1919
jobs:
20-
# 第一步:准备编译环境(ESP-IDF、MicroPython)
21-
setup-environment:
22-
runs-on: ubuntu-24.04
23-
steps:
24-
# 1.缓存 ESP-IDF 和 MicroPython
25-
- name: Cache ESP-IDF and MicroPython
26-
id: cache_esp_idf
27-
uses: actions/cache@v4
28-
with:
29-
path: | # 缓存路径
30-
${{ env.ESP_IDF_DIR }}
31-
~/.espressif/
32-
~/.cache/pip/
33-
${{ env.MICROPYTHON_DIR }}
34-
key: mpy-${{ env.MPY_VERSION }}-idf-${{ env.ESP_IDF_VERSION }} # 缓存键
35-
36-
# 2.安装依赖(如果未缓存)
37-
- name: Install dependencies (if not cached)
38-
if: steps.cache_esp_idf.outputs.cache-hit != 'true' # 如果缓存未命中
39-
run: |
40-
sudo apt-get update # 更新包列表
41-
sudo apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 # 安装依赖
42-
43-
# 3.克隆指定版本的 MicroPython(如果未缓存)
44-
- name: Clone MicroPython specific version (if not cached)
45-
if: steps.cache_esp_idf.outputs.cache-hit != 'true' # 如果缓存未命中
46-
run: |
47-
cd ${{ github.workspace }}
48-
git clone --depth 1 --branch ${{ env.MPY_VERSION }} https://github.com/micropython/micropython.git ${{ env.MICROPYTHON_DIR }} # 克隆 MicroPython
49-
cd ${{ env.MICROPYTHON_DIR }}
50-
git submodule update --init --depth 1 # 更新子模块
51-
cd mpy-cross && make # 编译 mpy-cross 工具
52-
53-
# 4.设置指定版本的 ESP-IDF(如果未缓存)
54-
- name: Set up ESP-IDF specific version (if not cached)
55-
if: steps.cache_esp_idf.outputs.cache-hit != 'true' # 如果缓存未命中
56-
run: |
57-
cd ${{ github.workspace }}
58-
git clone --depth 1 --branch ${{ env.ESP_IDF_VERSION }} https://github.com/espressif/esp-idf.git ${{ env.ESP_IDF_DIR }} # 克隆 ESP-IDF
59-
git -C ${{ env.ESP_IDF_DIR }} submodule update --init --recursive --filter=tree:0 # 更新子模块
60-
cd ${{ env.ESP_IDF_DIR }} && ./install.sh esp32,esp32s3,esp32c3 # 安装 ESP-IDF
61-
cd components
62-
# 使用 cnadler86 的 esp32-camera 分支(适配 MicroPython)
63-
git clone https://github.com/cnadler86/esp32-camera.git
64-
cd ${{ env.ESP_IDF_DIR }}
65-
source ./export.sh # 导入 ESP-IDF 的环境变量
66-
cd ${{ github.workspace }}
67-
# 拷贝 esp-adf-libs 中的 esp_new_jpeg 组件
68-
git clone https://github.com/espressif/esp-adf-libs.git
69-
cp -r ${{ github.workspace }}/esp-adf-libs/esp_new_jpeg ${{ env.ESP_IDF_DIR }}/components/
70-
71-
# 第二步:并行构建各开发板固件
7220
build:
73-
needs: setup-environment
7421
runs-on: ubuntu-24.04
7522
strategy:
7623
fail-fast: false
@@ -87,72 +34,108 @@ jobs:
8734
flash_size: 8
8835

8936
steps:
90-
# 2. 恢复缓存
91-
- name: 2.恢复 ESP-IDF 与 MicroPython 缓存
92-
uses: actions/cache@v4 # 使用 GitHub Actions 的缓存功能
37+
# 1. 检出当前仓库(包含 board 配置、脚本等)
38+
- name: Checkout repo
39+
uses: actions/checkout@v4
40+
41+
# 2. 缓存 ESP-IDF 与 MicroPython
42+
- name: Cache ESP-IDF and MicroPython
43+
id: cache_all
44+
uses: actions/cache@v4
9345
with:
94-
path: | # 缓存路径
46+
path: |
9547
${{ env.ESP_IDF_DIR }}
9648
~/.espressif/
9749
~/.cache/pip/
9850
${{ env.MICROPYTHON_DIR }}
99-
key: mpy-${{ env.MPY_VERSION }}-idf-${{ env.ESP_IDF_VERSION }} # 缓存键
51+
key: mpy-${{ env.MPY_VERSION }}-idf-${{ env.ESP_IDF_VERSION }}
10052

101-
- name: 检出仓库
102-
uses: actions/checkout@v4
53+
# 3. 安装系统依赖(仅在缓存未命中时)
54+
- name: Install system dependencies
55+
if: steps.cache_all.outputs.cache-hit != 'true'
56+
run: |
57+
sudo apt-get update
58+
sudo apt-get install -y \
59+
git wget flex bison gperf python3 python3-pip python3-venv \
60+
cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
61+
62+
# 4. 克隆 MicroPython(仅在缓存未命中时)
63+
- name: Clone MicroPython
64+
if: steps.cache_all.outputs.cache-hit != 'true'
65+
run: |
66+
git clone --depth 1 --branch ${{ env.MPY_VERSION }} \
67+
https://github.com/micropython/micropython.git ${{ env.MICROPYTHON_DIR }}
68+
cd ${{ env.MICROPYTHON_DIR }}
69+
git submodule update --init --depth 1
70+
make -C mpy-cross
10371
104-
# 克隆 JPEG 模块
105-
- name: 克隆 JPEG 模块
72+
# 5. 克隆并配置 ESP-IDF(仅在缓存未命中时)
73+
- name: Clone & setup ESP-IDF
74+
if: steps.cache_all.outputs.cache-hit != 'true'
75+
run: |
76+
git clone --depth 1 --branch ${{ env.ESP_IDF_VERSION }} \
77+
https://github.com/espressif/esp-idf.git ${{ env.ESP_IDF_DIR }}
78+
git -C ${{ env.ESP_IDF_DIR }} submodule update --init --recursive --filter=tree:0
79+
${{ env.ESP_IDF_DIR }}/install.sh esp32,esp32s3,esp32c3
80+
81+
# 添加 esp32-camera(适配 MicroPython)
82+
git clone https://github.com/cnadler86/esp32-camera.git \
83+
${{ env.ESP_IDF_DIR }}/components/esp32-camera
84+
85+
# 添加 esp_new_jpeg
86+
git clone https://github.com/espressif/esp-adf-libs.git ${{ github.workspace }}/esp-adf-libs
87+
cp -r ${{ github.workspace }}/esp-adf-libs/esp_new_jpeg \
88+
${{ env.ESP_IDF_DIR }}/components/esp_new_jpeg
89+
90+
# 6. 导入 ESP-IDF 环境变量(每次都需要)
91+
- name: Export ESP-IDF environment
10692
run: |
107-
git clone https://github.com/cnadler86/mp_jpeg.git
93+
source ${{ env.ESP_IDF_DIR }}/export.sh
94+
echo "ESP-IDF ready."
10895
109-
# 生成聚合 user_modules.cmake
110-
- name: 生成聚合 user_modules.cmake
96+
# 7. 克隆 JPEG 模块
97+
- name: Clone JPEG module
98+
run: |
99+
git clone https://github.com/cnadler86/mp_jpeg.git ${{ github.workspace }}/mp_jpeg
100+
101+
# 8. 生成 user_modules.cmake(聚合本仓库与 JPEG 模块)
102+
- name: Generate user_modules.cmake
111103
run: |
112104
cat > ${{ github.workspace }}/user_modules.cmake <<'EOF'
113105
include("${CMAKE_CURRENT_LIST_DIR}/src/micropython.cmake")
114106
include("${CMAKE_CURRENT_LIST_DIR}/mp_jpeg/src/micropython.cmake")
115107
EOF
116108
117-
# 编译固件
118-
- name: 编译固件
109+
# 9. 编译固件
110+
- name: Build firmware
119111
run: |
120-
echo "检查 ESP-IDF 目录是否存在..."
121-
ls -la ${{ env.ESP_IDF_DIR }}
122-
echo "检查 export.sh 是否存在..."
123-
ls -la ${{ env.ESP_IDF_DIR }}/export.sh || echo "export.sh 不存在!"
124-
cd ${{ env.ESP_IDF_DIR }}
125-
source ./export.sh
112+
source ${{ env.ESP_IDF_DIR }}/export.sh
126113
cd ${{ env.MICROPYTHON_DIR }}/ports/esp32
127114
make BOARD=${{ matrix.board }} \
128115
BOARD_VARIANT=${{ matrix.variant }} \
129116
FLASH_SIZE=${{ matrix.flash_size }}MB \
130117
USER_C_MODULES="${{ github.workspace }}/user_modules.cmake" \
131118
-j$(nproc)
132119
133-
- name: 重命名并上传固件
120+
# 10. 重命名并收集固件
121+
- name: Rename firmware
134122
run: |
135123
mkdir -p ${{ env.ARTIFACTS_DIR }}
136-
137-
# 拼出构建目录名:board 与可选 variant 用 “-” 连接
138124
BOARD_NAME="${{ matrix.board }}"
139125
[[ -n "${{ matrix.variant }}" ]] && BOARD_NAME+="-${{ matrix.variant }}"
140-
# 计算固件真正所在路径
141126
FW_PATH="${{ env.MICROPYTHON_DIR }}/ports/esp32/build-${BOARD_NAME}/firmware.bin"
142-
143127
OUT_NAME="${{ matrix.board }}${{ matrix.variant && format('_{0}', matrix.variant) || '' }}_${{ matrix.flash_size }}MB.bin"
144128
145-
echo "编译输出目录内容:"
146-
ls -la ${{ env.MICROPYTHON_DIR }}/ports/esp32/build-${BOARD_NAME}
147-
129+
ls -la "${{ env.MICROPYTHON_DIR }}/ports/esp32/build-${BOARD_NAME}"
148130
if [[ -f "$FW_PATH" ]]; then
149-
cp $FW_PATH ${{ env.ARTIFACTS_DIR }}/$OUT_NAME
131+
cp "$FW_PATH" "${{ env.ARTIFACTS_DIR }}/$OUT_NAME"
150132
else
151133
echo "Firmware not found at $FW_PATH"
152134
exit 1
153135
fi
154136
155-
- name: 上传产物
137+
# 11. 上传构建产物
138+
- name: Upload artifact
156139
uses: actions/upload-artifact@v4
157140
with:
158141
name: mpy_cam-${{ matrix.board }}${{ matrix.variant && format('_{0}', matrix.variant) || '' }}_${{ matrix.flash_size }}MB

0 commit comments

Comments
 (0)