Skip to content

Commit 2a96a77

Browse files
Merge pull request #1 from Embed-Hub/feature/github-action
Feature/GitHub action
2 parents 45f46f2 + 0cf7516 commit 2a96a77

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Build and Upload Firmware
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-upload:
10+
runs-on: ubuntu-22.04
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
path: project
17+
persist-credentials: false
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: 3.12
23+
24+
- name: Setup Zephyr project
25+
uses: zephyrproject-rtos/action-zephyr-setup@v1
26+
with:
27+
app-path: project
28+
toolchains: riscv64-zephyr-elf
29+
30+
- name: Fetch Espressif HAL blobs
31+
working-directory: project
32+
shell: bash
33+
run: |
34+
west blobs fetch hal_espressif
35+
36+
- name: Build firmware for ESP32-C3
37+
working-directory: project
38+
shell: bash
39+
run: |
40+
west build -p always -b esp32c3_devkitm app -- -DBOARD_ROOT=.
41+
42+
- name: List build artifacts
43+
working-directory: project
44+
run: |
45+
echo "=== Build directory structure ==="
46+
find build -type f -name "*.bin" -o -name "*.elf" -o -name "*.hex" 2>/dev/null || echo "No binaries found"
47+
echo ""
48+
echo "=== Zephyr directory contents ==="
49+
ls -lh build/zephyr/ 2>/dev/null || echo "Zephyr directory not found"
50+
51+
- name: Get branch name
52+
id: branch
53+
run: |
54+
# Extract branch name from ref
55+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
56+
# Sanitize branch name for use in paths (replace / with -)
57+
BRANCH_NAME_SAFE=$(echo "$BRANCH_NAME" | sed 's/\//-/g')
58+
echo "name=$BRANCH_NAME_SAFE" >> $GITHUB_OUTPUT
59+
echo "Branch name: $BRANCH_NAME_SAFE"
60+
61+
- name: Rename binaries with commit ID
62+
working-directory: project/build/zephyr
63+
run: |
64+
echo "=== Renaming all .bin files with commit ID ==="
65+
BIN_COUNT=0
66+
for binfile in *.bin; do
67+
if [ -f "$binfile" ]; then
68+
# Extract basename without extension
69+
basename="${binfile%.bin}"
70+
# Create renamed version
71+
cp "$binfile" "${basename}_${{ github.sha }}.bin"
72+
echo "Renamed: $binfile -> ${basename}_${{ github.sha }}.bin"
73+
ls -lh "${basename}_${{ github.sha }}.bin"
74+
BIN_COUNT=$((BIN_COUNT + 1))
75+
fi
76+
done
77+
78+
if [ $BIN_COUNT -eq 0 ]; then
79+
echo "ERROR: No .bin files found in build/zephyr/"
80+
echo "Contents of build/zephyr/:"
81+
ls -lh
82+
exit 1
83+
fi
84+
85+
echo ""
86+
echo "=== Successfully renamed $BIN_COUNT binary file(s) ==="
87+
88+
- name: Upload firmware to EmbedHub
89+
if: github.event_name == 'push'
90+
uses: Embed-Hub/EmbedHub-GitHub-Action@master
91+
with:
92+
api-key: ${{ secrets.EMBEDHUB_API_KEY }}
93+
organization: ${{ secrets.EMBEDHUB_ORG }}
94+
project: ${{ secrets.EMBEDHUB_PROJECT }}
95+
files: 'project/build/zephyr/*_${{ github.sha }}.bin'
96+
path: 'releases/${{ steps.branch.outputs.name }}/'
97+
working-directory: '.'

0 commit comments

Comments
 (0)