1+ name : Build Release Binaries
2+
3+ on :
4+ push :
5+ tags : ['v*'] # Trigger on version tags like v2.1.0
6+ workflow_dispatch : # Manual trigger for testing
7+ inputs :
8+ version_override :
9+ description : ' Override version (e.g., 2.1.0-beta)'
10+ required : false
11+ type : string
12+
13+ jobs :
14+ build :
15+ runs-on : ubuntu-latest
16+
17+ strategy :
18+ matrix :
19+ environment : [esp32s3-supermini, esp32s3-xiao]
20+
21+ steps :
22+ - name : Checkout repository
23+ uses : actions/checkout@v4
24+
25+ - name : Set up Python
26+ uses : actions/setup-python@v4
27+ with :
28+ python-version : ' 3.x'
29+
30+ - name : Install PlatformIO
31+ run : |
32+ pip install platformio
33+ pio upgrade --dev
34+ pio pkg update
35+
36+ - name : Extract version information
37+ id : version
38+ run : |
39+ if [[ $GITHUB_REF == refs/tags/* ]]; then
40+ # Extract version from git tag (remove 'v' prefix)
41+ VERSION=${GITHUB_REF#refs/tags/v}
42+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
43+ echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
44+ elif [[ -n "${{ github.event.inputs.version_override }}" ]]; then
45+ # Use manual override
46+ VERSION="${{ github.event.inputs.version_override }}"
47+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
48+ echo "IS_RELEASE=false" >> $GITHUB_OUTPUT
49+ else
50+ # Development build
51+ VERSION="dev-$(date +%Y%m%d)"
52+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
53+ echo "IS_RELEASE=false" >> $GITHUB_OUTPUT
54+ fi
55+
56+ # Extract build info
57+ BUILD_NUMBER=$GITHUB_RUN_NUMBER
58+ COMMIT_HASH=$(git rev-parse --short HEAD)
59+ BUILD_DATE=$(date -u +"%b %d %Y")
60+ BUILD_TIME=$(date -u +"%H:%M:%S")
61+
62+ echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_OUTPUT
63+ echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_OUTPUT
64+ echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_OUTPUT
65+ echo "BUILD_TIME=$BUILD_TIME" >> $GITHUB_OUTPUT
66+
67+ echo "Building version: $VERSION"
68+ echo "Build number: $BUILD_NUMBER"
69+ echo "Commit: $COMMIT_HASH"
70+
71+ - name : Build firmware
72+ run : |
73+ # Set build flags with version info
74+ export PLATFORMIO_BUILD_FLAGS="\
75+ -DWEIGHMYBRU_BUILD_NUMBER=${{ steps.version.outputs.BUILD_NUMBER }} \
76+ -DWEIGHMYBRU_COMMIT_HASH=\\\"${{ steps.version.outputs.COMMIT_HASH }}\\\" \
77+ -DWEIGHMYBRU_BUILD_DATE=\\\"${{ steps.version.outputs.BUILD_DATE }}\\\" \
78+ -DWEIGHMYBRU_BUILD_TIME=\\\"${{ steps.version.outputs.BUILD_TIME }}\\\""
79+
80+ echo "Building ${{ matrix.environment }} with flags: $PLATFORMIO_BUILD_FLAGS"
81+
82+ # Build firmware
83+ pio run -e ${{ matrix.environment }}
84+
85+ # Build filesystem
86+ pio run -e ${{ matrix.environment }} -t buildfs
87+
88+ - name : Prepare release files
89+ run : |
90+ mkdir -p release
91+
92+ # Determine board suffix for file naming
93+ if [[ "${{ matrix.environment }}" == "esp32s3-supermini" ]]; then
94+ BOARD_SUFFIX="supermini"
95+ else
96+ BOARD_SUFFIX="xiao"
97+ fi
98+
99+ # Copy and rename binaries with version
100+ cp .pio/build/${{ matrix.environment }}/firmware.bin \
101+ release/weighmybru-${BOARD_SUFFIX}-v${{ steps.version.outputs.VERSION }}.bin
102+
103+ # Check if LittleFS was built
104+ if [[ -f .pio/build/${{ matrix.environment }}/littlefs.bin ]]; then
105+ cp .pio/build/${{ matrix.environment }}/littlefs.bin \
106+ release/weighmybru-${BOARD_SUFFIX}-v${{ steps.version.outputs.VERSION }}-littlefs.bin
107+ fi
108+
109+ # Copy bootloader and partitions for complete flashing
110+ if [[ -f .pio/build/${{ matrix.environment }}/bootloader.bin ]]; then
111+ cp .pio/build/${{ matrix.environment }}/bootloader.bin \
112+ release/weighmybru-${BOARD_SUFFIX}-v${{ steps.version.outputs.VERSION }}-bootloader.bin
113+ fi
114+
115+ if [[ -f .pio/build/${{ matrix.environment }}/partitions.bin ]]; then
116+ cp .pio/build/${{ matrix.environment }}/partitions.bin \
117+ release/weighmybru-${BOARD_SUFFIX}-v${{ steps.version.outputs.VERSION }}-partitions.bin
118+ fi
119+
120+ echo "BOARD_SUFFIX=$BOARD_SUFFIX" >> $GITHUB_ENV
121+
122+ - name : Generate ESP32 Web Tools manifest
123+ run : |
124+ BOARD_SUFFIX=${{ env.BOARD_SUFFIX }}
125+ VERSION=${{ steps.version.outputs.VERSION }}
126+
127+ # Determine board-specific settings
128+ if [[ "$BOARD_SUFFIX" == "supermini" ]]; then
129+ BOARD_NAME="WeighMyBru² - ESP32-S3 Supermini"
130+ CHIP_FAMILY="ESP32-S3"
131+ else
132+ BOARD_NAME="WeighMyBru² - XIAO ESP32S3"
133+ CHIP_FAMILY="ESP32-S3"
134+ fi
135+
136+ # Create ESP32 Web Tools manifest
137+ cat > release/manifest-${BOARD_SUFFIX}.json << EOF
138+ {
139+ "name": "$BOARD_NAME",
140+ "version": "$VERSION",
141+ "home_assistant_domain": "weighmybru",
142+ "new_install_prompt_erase": true,
143+ "funding_url": "https://github.com/031devstudios/weighmybru2",
144+ "builds": [
145+ {
146+ "chipFamily": "$CHIP_FAMILY",
147+ "parts": [
148+ {
149+ "path": "weighmybru-${BOARD_SUFFIX}-v${VERSION}-bootloader.bin",
150+ "offset": 0
151+ },
152+ {
153+ "path": "weighmybru-${BOARD_SUFFIX}-v${VERSION}-partitions.bin",
154+ "offset": 32768
155+ },
156+ {
157+ "path": "weighmybru-${BOARD_SUFFIX}-v${VERSION}.bin",
158+ "offset": 65536
159+ },
160+ {
161+ "path": "weighmybru-${BOARD_SUFFIX}-v${VERSION}-littlefs.bin",
162+ "offset": 2686976
163+ }
164+ ]
165+ }
166+ ]
167+ }
168+ EOF
169+
170+ echo "Generated manifest for $BOARD_NAME v$VERSION"
171+
172+ - name : Create build info file
173+ run : |
174+ cat > release/build-info-${{ env.BOARD_SUFFIX }}.json << EOF
175+ {
176+ "version": "${{ steps.version.outputs.VERSION }}",
177+ "board": "${{ matrix.environment }}",
178+ "build_number": ${{ steps.version.outputs.BUILD_NUMBER }},
179+ "commit_hash": "${{ steps.version.outputs.COMMIT_HASH }}",
180+ "build_date": "${{ steps.version.outputs.BUILD_DATE }}",
181+ "build_time": "${{ steps.version.outputs.BUILD_TIME }}",
182+ "is_release": ${{ steps.version.outputs.IS_RELEASE }},
183+ "github_run_id": "${{ github.run_id }}",
184+ "github_sha": "${{ github.sha }}"
185+ }
186+ EOF
187+
188+ - name : Upload release artifacts
189+ uses : actions/upload-artifact@v3
190+ with :
191+ name : weighmybru-${{ env.BOARD_SUFFIX }}-v${{ steps.version.outputs.VERSION }}
192+ path : release/
193+ retention-days : 90
194+
195+ create-release :
196+ needs : build
197+ runs-on : ubuntu-latest
198+ if : startsWith(github.ref, 'refs/tags/')
199+
200+ steps :
201+ - name : Download all artifacts
202+ uses : actions/download-artifact@v3
203+
204+ - name : Extract version from tag
205+ id : version
206+ run : |
207+ VERSION=${GITHUB_REF#refs/tags/v}
208+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
209+
210+ - name : Organize release files
211+ run : |
212+ mkdir -p release-final
213+
214+ # Combine all artifacts into one release folder
215+ find . -name "*.bin" -o -name "*.json" | while read file; do
216+ cp "$file" release-final/
217+ done
218+
219+ ls -la release-final/
220+
221+ - name : Create GitHub Release
222+ uses : softprops/action-gh-release@v1
223+ with :
224+ tag_name : v${{ steps.version.outputs.VERSION }}
225+ name : WeighMyBru² v${{ steps.version.outputs.VERSION }}
226+ files : release-final/*
227+ body : |
228+ ## WeighMyBru² v${{ steps.version.outputs.VERSION }}
229+
230+ ### 📦 Release Binaries
231+
232+ **ESP32-S3 Supermini:**
233+ - `weighmybru-supermini-v${{ steps.version.outputs.VERSION }}.bin` - Main firmware
234+ - `weighmybru-supermini-v${{ steps.version.outputs.VERSION }}-littlefs.bin` - Web interface files
235+ - `manifest-supermini.json` - ESP32 Web Tools manifest
236+
237+ **XIAO ESP32S3:**
238+ - `weighmybru-xiao-v${{ steps.version.outputs.VERSION }}.bin` - Main firmware
239+ - `weighmybru-xiao-v${{ steps.version.outputs.VERSION }}-littlefs.bin` - Web interface files
240+ - `manifest-xiao.json` - ESP32 Web Tools manifest
241+
242+ ### 🚀 Installation Options
243+
244+ 1. **Web-based (Recommended):** Use ESP32 Web Tools on [weighmybru.com](https://weighmybru.com)
245+ 2. **Manual:** Download binaries and flash with esptool or PlatformIO
246+
247+ ### 📋 Requirements
248+ - ESP32-S3 Supermini or XIAO ESP32S3 board
249+ - Load cell and HX711 amplifier
250+ - See [README.md](https://github.com/031devstudios/weighmybru2/blob/master/README.md) for wiring
251+
252+ ### 🔧 Build Information
253+ - Build: #${{ github.run_number }}
254+ - Commit: ${{ github.sha }}
255+ - Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
256+ draft : false
257+ prerelease : false
258+ env :
259+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments