Skip to content

Commit 2872bf6

Browse files
authored
Add GitHub Actions workflow for building firmware
1 parent 63f1977 commit 2872bf6

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

.github/workflows/build.yml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
name: Build ESP-Hosted Firmware
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ['v*']
7+
pull_request:
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: 'ESP-Hosted-MCU version to build'
12+
type: string
13+
default: '2.7.3'
14+
release:
15+
description: 'Create a release'
16+
type: boolean
17+
default: true
18+
19+
env:
20+
ESP_IDF_VERSION: v5.5.1
21+
ESP_HOSTED_VERSION: ${{ inputs.version || '2.7.3' }}
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
container:
27+
image: espressif/idf:v5.5.1
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
target:
32+
- esp32
33+
- esp32s2
34+
- esp32s3
35+
- esp32c2
36+
- esp32c3
37+
- esp32c5
38+
- esp32c6
39+
- esp32c61
40+
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
45+
- name: Create project from esp_hosted slave example
46+
run: |
47+
. $IDF_PATH/export.sh
48+
idf.py create-project-from-example "espressif/esp_hosted==${{ env.ESP_HOSTED_VERSION }}:slave"
49+
50+
- name: Build firmware
51+
working-directory: slave
52+
run: |
53+
. $IDF_PATH/export.sh
54+
idf.py set-target ${{ matrix.target }}
55+
idf.py build
56+
57+
- name: Prepare artifacts
58+
run: |
59+
mkdir -p artifacts
60+
cp slave/build/network_adapter.bin artifacts/network_adapter_${{ matrix.target }}.bin
61+
sha256sum artifacts/network_adapter_${{ matrix.target }}.bin > artifacts/network_adapter_${{ matrix.target }}.bin.sha256
62+
63+
- name: Upload artifacts
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: firmware-${{ matrix.target }}
67+
path: artifacts/
68+
69+
release:
70+
needs: build
71+
runs-on: ubuntu-latest
72+
if: startsWith(github.ref, 'refs/tags/v') || inputs.release
73+
permissions:
74+
contents: write
75+
76+
steps:
77+
- name: Download all artifacts
78+
uses: actions/download-artifact@v4
79+
with:
80+
path: firmware
81+
merge-multiple: true
82+
83+
- name: Create Release
84+
uses: softprops/action-gh-release@v2
85+
with:
86+
tag_name: v${{ env.ESP_HOSTED_VERSION }}
87+
files: firmware/*
88+
generate_release_notes: true
89+
90+
manifest:
91+
needs: release
92+
runs-on: ubuntu-latest
93+
permissions:
94+
contents: write
95+
strategy:
96+
matrix:
97+
target:
98+
- esp32
99+
- esp32s2
100+
- esp32s3
101+
- esp32c2
102+
- esp32c3
103+
- esp32c5
104+
- esp32c6
105+
- esp32c61
106+
107+
steps:
108+
- name: Generate manifest
109+
env:
110+
GH_TOKEN: ${{ github.token }}
111+
run: |
112+
TARGET="${{ matrix.target }}"
113+
REPO="${{ github.repository }}"
114+
115+
# Get all release tags
116+
TAGS=$(gh release list --repo "$REPO" --json tagName -q '.[].tagName')
117+
118+
# Build manifest using jq
119+
echo '{"versions":[]}' > manifest.json
120+
121+
for TAG in $TAGS; do
122+
# Skip manifest tag
123+
if [ "$TAG" = "manifest" ]; then
124+
continue
125+
fi
126+
127+
VERSION="${TAG#v}"
128+
SHA256_FILE="network_adapter_${TARGET}.bin.sha256"
129+
130+
# Download SHA256 file using gh CLI (handles auth properly)
131+
if gh release download "$TAG" --repo "$REPO" --pattern "$SHA256_FILE" --clobber 2>/dev/null; then
132+
SHA256=$(awk '{print $1}' "$SHA256_FILE")
133+
rm -f "$SHA256_FILE"
134+
135+
if [ -n "$SHA256" ] && [ ${#SHA256} -eq 64 ]; then
136+
BIN_URL="https://github.com/${REPO}/releases/download/${TAG}/network_adapter_${TARGET}.bin"
137+
138+
# Add to manifest using jq
139+
jq --arg ver "$VERSION" --arg url "$BIN_URL" --arg sha "$SHA256" \
140+
'.versions += [{"version": $ver, "url": $url, "sha256": $sha}]' \
141+
manifest.json > tmp.json && mv tmp.json manifest.json
142+
fi
143+
fi
144+
done
145+
146+
# Sort versions descending (newest first)
147+
jq '.versions |= sort_by(.version | split(".") | map(tonumber)) | .versions |= reverse' \
148+
manifest.json > ${TARGET}.json
149+
150+
- name: Upload manifest to release
151+
env:
152+
GH_TOKEN: ${{ github.token }}
153+
run: |
154+
# Create manifest release if it doesn't exist
155+
gh release view manifest --repo "${{ github.repository }}" >/dev/null 2>&1 || \
156+
gh release create manifest --repo "${{ github.repository }}" --title "Firmware Manifests" --notes "JSON manifests listing all firmware versions for each target."
157+
158+
gh release upload manifest \
159+
--repo "${{ github.repository }}" \
160+
--clobber \
161+
${{ matrix.target }}.json
162+

0 commit comments

Comments
 (0)