feat: Add git branch to version information on settings screen#1225
feat: Add git branch to version information on settings screen#1225daveallie merged 2 commits intocrosspoint-reader:masterfrom
Conversation
📝 WalkthroughWalkthroughAdds a PlatformIO pre-build script that reads base version from config, obtains the current git branch (or short SHA), composes a "-dev+" version string, and injects it into the default environment build as the Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer/CI
participant PIO as PlatformIO (pre-build)
participant Script as scripts/git_branch.py
participant INI as platformio.ini
participant Git as Git repo
participant Env as Build Environment
Dev->>PIO: start build for PIOENV=default
PIO->>Script: run inject_version(env)
Script->>INI: read [crosspoint] version
Script->>Git: get current branch or short SHA
Git-->>Script: branch/sha (or error)
INI-->>Script: base version (or default)
Script->>Script: sanitize & construct "<base>-dev+<branch>"
Script->>Env: append CPPDEFINES CROSSPOINT_VERSION="..."
Env-->>PIO: updated build defines
PIO->>Dev: continue build with injected CROSSPOINT_VERSION
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
scripts/git_branch.py (1)
39-41: Consider narrowing the exception type.The generic
Exceptioncatch is a defensive fallback, but it may mask unexpected issues. SinceFileNotFoundErrorandCalledProcessErrorcover the expected git failures, consider replacing withOSErrorto catch remaining I/O-related errors while letting truly unexpected exceptions propagate.♻️ Optional: Narrow exception scope
- except Exception as e: - warn(f'Unexpected error reading git branch: {e}; branch suffix will be "unknown"') - return 'unknown' + except OSError as e: + warn(f'OS error reading git branch: {e}; branch suffix will be "unknown"') + return 'unknown'🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/git_branch.py` around lines 39 - 41, Replace the broad "except Exception as e" handler that logs via warn(...) and returns 'unknown' with a narrower "except OSError as e" so only I/O-related errors (e.g., missing git or filesystem issues) are caught while letting other unexpected exceptions propagate; keep the existing warn(...) message and the return 'unknown' behavior but change the exception type to OSError to narrow the scope.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@scripts/git_branch.py`:
- Around line 39-41: Replace the broad "except Exception as e" handler that logs
via warn(...) and returns 'unknown' with a narrower "except OSError as e" so
only I/O-related errors (e.g., missing git or filesystem issues) are caught
while letting other unexpected exceptions propagate; keep the existing warn(...)
message and the return 'unknown' behavior but change the exception type to
OSError to narrow the scope.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
platformio.iniscripts/git_branch.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cppcheck
- GitHub Check: build
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-02-23T19:55:14.329Z
Learnt from: martinbrook
Repo: crosspoint-reader/crosspoint-reader PR: 1136
File: scripts/patch_jpegdec.py:20-23
Timestamp: 2026-02-23T19:55:14.329Z
Learning: PlatformIO pre-build scripts in the crosspoint-reader project use the standard SCons pattern `Import("env")` and callback signature `def patch_jpegdec(source, target, env):` without noqa comments or underscore-prefixing unused parameters, following the convention used in other scripts in the project.
Applied to files:
scripts/git_branch.pyplatformio.ini
📚 Learning: 2026-02-23T19:55:03.054Z
Learnt from: martinbrook
Repo: crosspoint-reader/crosspoint-reader PR: 1136
File: scripts/patch_jpegdec.py:20-23
Timestamp: 2026-02-23T19:55:03.054Z
Learning: In the crosspoint-reader project, enable Python linters (e.g., Ruff or Flake8) in CI for all Python scripts. Run linting as part of the CI workflow and fix reported issues to maintain code quality. Do not skip linting for any Python files.
Applied to files:
scripts/git_branch.py
🪛 Ruff (0.15.2)
scripts/git_branch.py
[error] 22-22: Starting a process with a partial executable path
(S607)
[error] 28-28: Starting a process with a partial executable path
(S607)
[warning] 39-39: Do not catch blind exception: Exception
(BLE001)
🔇 Additional comments (6)
platformio.ini (1)
49-49: LGTM!The pre-build script integration is clean. Adding it to
[base]ensures it runs for all environments, while the script's internal check forPIOENV == 'default'correctly limits version injection to dev builds. Release environments retain their explicitCROSSPOINT_VERSIONdefinitions in build_flags.Also applies to: 66-66
scripts/git_branch.py (5)
1-12: LGTM!Clear docstring with example output format, and minimal standard-library-only dependencies.
15-16: LGTM!Simple and appropriate warning function for build script output.
44-54: LGTM!Robust version reading with appropriate fallbacks and warnings. The path handling is platform-independent.
57-69: LGTM!Clean environment check, well-formatted version string following semver conventions (
-devprerelease ++branchmetadata), and correct SCons CPPDEFINES escaping.
72-83: LGTM!The dual-mode entry point is well-designed. The
Import('env')pattern is standard SCons, and thenoqacomments are appropriate sinceImportis a runtime-injected builtin. The_Envmock enables standalone validation without requiring a full PlatformIO build.
znelson
left a comment
There was a problem hiding this comment.
Nice! This sounds useful because I find myself in the same situation, questioning which version I most recently flashed. What would you think about adding the short commit SHA, too, like "30d8a8d"?
…point-reader#1225) * **What is the goal of this PR?** During my development I am frequently jumping from branch to branch flashing test versions on my device. It becomes sometimes quite difficult to figure out which version of the software I am currently looking at. * **What changes are included?** - Dev builds now display the current git branch in the version string shown on the Settings screen (e.g. 1.1.0-dev+feat-my-feature), making it easier to identify which firmware is running on the device when switching between branches frequently. - Release, RC, and slim builds are unaffected — they continue to set their version string statically in platformio.ini. <img width="480" height="800" alt="after" src="https://github.com/user-attachments/assets/d2ab3d69-ab6b-47a1-8eb7-1b40b1d3b106" /> A new PlatformIO pre-build script (scripts/git_branch.py) runs automatically before every dev build. It reads the base version from the [crosspoint] section of platformio.ini, queries git rev-parse --abbrev-ref HEAD for the current branch, and injects the combined string as the CROSSPOINT_VERSION preprocessor define. In a detached HEAD state it falls back to the short commit SHA. If git is unavailable it warns and falls back to unknown. The script can also be run directly with python scripts/git_branch.py for validation without triggering a full build. --- While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< YES | PARTIALLY | NO >**_
Cherry-picked upstream fixes and features applied via rescue-1.0.0 worktree: - fix: properly implement requestUpdateAndWait() (crosspoint-reader#1218) - fix: Hide unusable button hints in empty directory (crosspoint-reader#1253) - fix: add missing keyboard metrics to Lyra3CoversTheme (crosspoint-reader#1101) - fix: remove bookProgressBarHeight from Lyra3CoversTheme - feat: replace picojpeg with JPEGDEC for JPEG decoding (crosspoint-reader#1136) - feat: WIFI pill, feed log fix, JPEGDEC version string - feat: Add git branch to version string (crosspoint-reader#1225) - fix: navigate directly to QR code after DZ auto-connect - perf: Removed unused ConfirmationActivity member (crosspoint-reader#1234) - refactor: Simplify new setting introduction (crosspoint-reader#1086) - fix: UI fonts, settings stack overflow, PULSR theme name - fix: convert SettingsList to push_back (prevent stack overflow) All commits built and verified on device (confirmed 1.1.0-dev+d1e786a).
Summary
What is the goal of this PR? During my development I am frequently jumping from branch to branch flashing test versions on my device. It becomes sometimes quite difficult to figure out which version of the software I am currently looking at.
What changes are included?
Additional Context
A new PlatformIO pre-build script (scripts/git_branch.py) runs automatically before every dev build. It reads the base version from the [crosspoint] section of platformio.ini, queries git rev-parse --abbrev-ref HEAD for the current branch, and injects the combined string as the CROSSPOINT_VERSION preprocessor define. In a detached HEAD state it falls back to the short commit SHA. If git is unavailable it warns and falls back to unknown.
The script can also be run directly with python scripts/git_branch.py for validation without triggering a full build.
AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? < YES | PARTIALLY | NO >