Skip to content

Commit 3fc9ffc

Browse files
Setup PR build workflow
That way each PR is identifiable and generates artifacts that we can test locally if desired
1 parent b83d188 commit 3fc9ffc

30 files changed

Lines changed: 707 additions & 254 deletions

.github/workflows/build.yml

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
name: Build
1+
name: Build PR
22

33
on:
4-
push:
5-
branches:
6-
- 'main'
7-
84
pull_request:
95
branches:
106
- '**'
@@ -18,6 +14,42 @@ jobs:
1814
- name: Checkout code
1915
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2016

17+
- name: Export build number as env variable
18+
run: echo "BUILD_NUMBER=${{ github.run_number }}" >> $GITHUB_ENV
19+
20+
- name: Extract current SHA
21+
run: echo "CURRENT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
22+
23+
- name: Retrieve PR number
24+
run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
25+
26+
- name: Extract version
27+
run: |
28+
VERSION_FILE="include/nspm-bin-version.h"
29+
30+
# Use grep to extract the version string from the define statement
31+
VERSION=$(grep -oP '#define NSPanelManagerFirmwareVersion "\K([^"]+)' $VERSION_FILE)
32+
33+
# Store the version in an environment variable
34+
echo "VERSION=$VERSION" >> $GITHUB_ENV
35+
36+
# Optional: Print version to verify
37+
echo "Version in environment variable: ${{ env.VERSION }}"
38+
39+
- name: Replace version in nspm-bin-version.h
40+
run: |
41+
echo "FIRMWARE_IDENTIFIER=${{ env.VERSION }}-${{ env.BUILD_NUMBER }}#PR${{ env.PR_NUMBER }}" >> $GITHUB_ENV
42+
echo "This build will generate firmware identifier ${{ env.FIRMWARE_IDENTIFIER }}"
43+
44+
- name: Replace version and sha in nspm-bin-version.h
45+
run: |
46+
VERSION_FILE="include/nspm-bin-version.h"
47+
48+
# Replace the version string in the header file using sed
49+
sed -i 's/#define NSPanelManagerFirmwareVersion ".*"/#define NSPanelManagerFirmwareVersion "${{ env.VERSION }}-${{ env.BUILD_NUMBER }}#PR${{ env.PR_NUMBER }}"/' $VERSION_FILE
50+
sed -i "s/#define NSPanelManagerFirmwareCommitSha \".*\"/#define NSPanelManagerFirmwareCommitSha \"$GITHUB_SHA\"/" $VERSION_FILE
51+
52+
cat $VERSION_FILE
2153
- name: Set up Python
2254
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
2355
with:
@@ -34,11 +66,35 @@ jobs:
3466
run: |
3567
make install
3668
37-
- name: Compile firmware
38-
run: |
39-
make build
40-
4169
- name: Perform pre-commit checks
4270
# ensure files are correctly formatted, Markdown, yaml, end of file etc.
4371
run: |
44-
make pre-commit
72+
make pre-commit
73+
74+
- name: Build firmware.bin
75+
run: |
76+
make build-firmware
77+
78+
- name: Build littlefs.bin
79+
run: |
80+
make build-littlefs
81+
82+
- name: Build AIO (all in one image)
83+
# includes bootloader + partitions + firmware + littlefs
84+
# used only the first time an NSPanel is flashed over serial
85+
# not for OTA updates
86+
run: |
87+
make build-aio
88+
89+
- name: Store firmware .bin as build artifact
90+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
91+
with:
92+
name: firmware-${{ env.FIRMWARE_IDENTIFIER }}
93+
path: |
94+
.pio/build/esp32dev/firmware.bin
95+
.pio/build/esp32dev/firmware.bin.md5
96+
.pio/build/esp32dev/littlefs.bin
97+
.pio/build/esp32dev/littlefs.bin.md5
98+
.pio/build/esp32dev/firmware-aio.bin
99+
.pio/build/esp32dev/firmware-aio.bin.md5
100+
retention-days: 1 # Retention policy for 1 day

.gitignore

Lines changed: 191 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,192 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,intellij+all,windows,macos,linux,platformio
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,intellij+all,windows,macos,linux,platformio
3+
4+
### Intellij+all ###
5+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
6+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7+
8+
# User-specific stuff
9+
.idea/**/workspace.xml
10+
.idea/**/tasks.xml
11+
.idea/**/usage.statistics.xml
12+
.idea/**/dictionaries
13+
.idea/**/shelf
14+
15+
# AWS User-specific
16+
.idea/**/aws.xml
17+
18+
# Generated files
19+
.idea/**/contentModel.xml
20+
21+
# Sensitive or high-churn files
22+
.idea/**/dataSources/
23+
.idea/**/dataSources.ids
24+
.idea/**/dataSources.local.xml
25+
.idea/**/sqlDataSources.xml
26+
.idea/**/dynamic.xml
27+
.idea/**/uiDesigner.xml
28+
.idea/**/dbnavigator.xml
29+
30+
# Gradle
31+
.idea/**/gradle.xml
32+
.idea/**/libraries
33+
34+
# Gradle and Maven with auto-import
35+
# When using Gradle or Maven with auto-import, you should exclude module files,
36+
# since they will be recreated, and may cause churn. Uncomment if using
37+
# auto-import.
38+
# .idea/artifacts
39+
# .idea/compiler.xml
40+
# .idea/jarRepositories.xml
41+
# .idea/modules.xml
42+
# .idea/*.iml
43+
# .idea/modules
44+
# *.iml
45+
# *.ipr
46+
47+
# CMake
48+
cmake-build-*/
49+
50+
# Mongo Explorer plugin
51+
.idea/**/mongoSettings.xml
52+
53+
# File-based project format
54+
*.iws
55+
56+
# IntelliJ
57+
out/
58+
59+
# mpeltonen/sbt-idea plugin
60+
.idea_modules/
61+
62+
# JIRA plugin
63+
atlassian-ide-plugin.xml
64+
65+
# Cursive Clojure plugin
66+
.idea/replstate.xml
67+
68+
# SonarLint plugin
69+
.idea/sonarlint/
70+
71+
# Crashlytics plugin (for Android Studio and IntelliJ)
72+
com_crashlytics_export_strings.xml
73+
crashlytics.properties
74+
crashlytics-build.properties
75+
fabric.properties
76+
77+
# Editor-based Rest Client
78+
.idea/httpRequests
79+
80+
# Android studio 3.1+ serialized cache file
81+
.idea/caches/build_file_checksums.ser
82+
83+
### Intellij+all Patch ###
84+
# Ignore everything but code style settings and run configurations
85+
# that are supposed to be shared within teams.
86+
87+
.idea/*
88+
89+
!.idea/codeStyles
90+
!.idea/runConfigurations
91+
92+
### Linux ###
93+
*~
94+
95+
# temporary files which can be created if a process still has a handle open of a deleted file
96+
.fuse_hidden*
97+
98+
# KDE directory preferences
99+
.directory
100+
101+
# Linux trash folder which might appear on any partition or disk
102+
.Trash-*
103+
104+
# .nfs files are created when an open file is removed but is still being accessed
105+
.nfs*
106+
107+
### macOS ###
108+
# General
109+
.DS_Store
110+
.AppleDouble
111+
.LSOverride
112+
113+
# Icon must end with two \r
114+
Icon
115+
116+
117+
# Thumbnails
118+
._*
119+
120+
# Files that might appear in the root of a volume
121+
.DocumentRevisions-V100
122+
.fseventsd
123+
.Spotlight-V100
124+
.TemporaryItems
125+
.Trashes
126+
.VolumeIcon.icns
127+
.com.apple.timemachine.donotpresent
128+
129+
# Directories potentially created on remote AFP share
130+
.AppleDB
131+
.AppleDesktop
132+
Network Trash Folder
133+
Temporary Items
134+
.apdisk
135+
136+
### macOS Patch ###
137+
# iCloud generated files
138+
*.icloud
139+
140+
### PlatformIO ###
141+
.pioenvs
142+
.piolibdeps
143+
.clang_complete
144+
.gcc-flags.json
1145
.pio
2-
.vscode/.browse.c_cpp.db*
3-
.vscode/c_cpp_properties.json
4-
.vscode/launch.json
5-
.vscode/ipch
146+
147+
### VisualStudioCode ###
148+
.vscode/*
149+
!.vscode/settings.json
150+
!.vscode/tasks.json
151+
!.vscode/launch.json
152+
!.vscode/extensions.json
153+
!.vscode/*.code-snippets
154+
155+
# Local History for Visual Studio Code
156+
.history/
157+
158+
# Built Visual Studio Code Extensions
159+
*.vsix
160+
161+
### VisualStudioCode Patch ###
162+
# Ignore all local history of files
163+
.history
164+
.ionide
165+
166+
### Windows ###
167+
# Windows thumbnail cache files
168+
Thumbs.db
169+
Thumbs.db:encryptable
170+
ehthumbs.db
171+
ehthumbs_vista.db
172+
173+
# Dump file
174+
*.stackdump
175+
176+
# Folder config file
177+
[Dd]esktop.ini
178+
179+
# Recycle Bin used on file shares
180+
$RECYCLE.BIN/
181+
182+
# Windows Installer files
183+
*.cab
184+
*.msi
185+
*.msix
186+
*.msm
187+
*.msp
188+
189+
# Windows shortcuts
190+
*.lnk
191+
192+
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,intellij+all,windows,macos,linux,platformio

Makefile

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,55 @@
1-
# Makefile for PlatformIO with Pipenv
1+
SCRIPT_DIR := scripts
2+
.PHONY: build-firmware build-littlefs build-aio clean upload monitor install pre-commit
23

3-
# Default target
4-
all: build
4+
# Print help
5+
help:
6+
@awk '/^#/{c=substr($$0,3);next}c&&/^[[:alpha:]][[:alnum:]_-]+:/{print substr($$1,1,index($$1,":")),c}1{c=0}' $(MAKEFILE_LIST) | column -s: -t
57

6-
# Run a build
7-
build:
8-
@echo "Building the project..."
9-
pipenv run platformio run
8+
# Build the firmware
9+
build-firmware:
10+
@echo "Building firmware..."
11+
@bash $(SCRIPT_DIR)/build-firmware.sh
12+
13+
# Build the littlefs file
14+
build-littlefs:
15+
@echo "Building littlefs..."
16+
@bash $(SCRIPT_DIR)/build-littlefs.sh
17+
18+
# Build the aio firmware
19+
build-aio: build-firmware build-littlefs
20+
@echo "Building firmware-aio.bin..."
21+
@bash $(SCRIPT_DIR)/build-aio.sh
1022

1123
# Clean build files
1224
clean:
1325
@echo "Cleaning the project..."
14-
pipenv run platformio run --target clean
26+
@pipenv run platformio run --target clean
27+
@rm -rf .pio # Remove additional build artifacts
1528

1629
# Upload firmware to the device
17-
upload:
30+
upload: build-firmware
1831
@echo "Uploading the firmware..."
19-
pipenv run platformio run --target upload
32+
@pipenv run platformio run --target upload
33+
34+
upload-aio: build-aio
35+
@echo "Flash NSPanel with the all in one firmware..."
36+
@bash $(SCRIPT_DIR)/flash-aio.sh
2037

2138
# Open serial monitor
2239
monitor:
2340
@echo "Opening serial monitor..."
24-
pipenv run platformio device monitor
41+
@pipenv run platformio device monitor
2542

2643
# Install dependencies
2744
install:
2845
@echo "Installing dependencies..."
29-
pipenv install --ignore-pipfile
46+
@pipenv install --ignore-pipfile
47+
48+
build-compile-commands:
49+
@echo "Build compile commands..."
50+
@bash $(SCRIPT_DIR)/build-compile-commands.sh
3051

52+
# Run sanity checks
3153
pre-commit:
3254
@echo "Run pre-commit checks..."
33-
pipenv run pre-commit run --all-files
55+
@pipenv run pre-commit run --all-files

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ name = "pypi"
66
[packages]
77
platformio = "*"
88
pre-commit = "*"
9+
esptool = "*"
910

1011
[dev-packages]
1112

0 commit comments

Comments
 (0)