Simplify version.json file write; standardize on matching SeedSigner OS builder output even in local dev
What changed, and why it matters
This commit refactors a small developer utility that writes a version.json file. It changes how the script decides whether it is running in the official build environment versus a local development copy, and makes the generated version file match the official build format even when built locally. There is no obvious security problem in the diff itself.
No security action required. Treat as a normal code-quality/refactoring change. If desired, verify that Version.get_instance() and VersionUtils helpers do not execute untrusted input, but the diff itself does not introduce such behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
tools/write_versionfile.py is rewritten to: (1) detect the SeedSigner OS builder environment, (2) if not present, derive version_name from local git state and temporarily inject it into the SEEDSIGNER_VERSION_NAME environment variable, (3) instantiate the Version singleton so it can reuse existing version-resolution logic, (4) write the resulting dict to version.json, and (5) delete the temporary env var. The change removes duplicated git-shell calls and aligns local-dev output with builder output. No input sanitization, privilege, crypto, or network changes are visible.
Changed components
tools/write_versionfile.pyInspect captured patch +20 / −22
diff --git a/tools/write_versionfile.py b/tools/write_versionfile.py
index 79c4c8b..861e8c9 100644
--- a/tools/write_versionfile.py
+++ b/tools/write_versionfile.py
@@ -1,6 +1,7 @@
import json
+import os
-from seedsigner.helpers.version import VersionUtils
+from seedsigner.helpers.version import Version, VersionUtils
"""
@@ -21,7 +22,8 @@ Version data:
* Check for the SEEDSIGNER_VERSION_NAME env var (provided in SeedSigner OS build
env).
* Will be the branch, tag, or commit hash being built.
- * In local dev will fall back to using `git` shell commands:
+ * If running in local dev instead, this script will try to populate that env var
+ using `git` shell commands:
* Current git branch name
* Current git tag name
* Current git commit hash
@@ -32,31 +34,23 @@ Version data:
* version_timestamp:
* Pulls last git commit time from `git log`.
- * version_commit_hash:
+ * short_commit_hash:
* Pulls current git commit hash from `git` shell command.
"""
-
if __name__ == "__main__":
- version_info = dict()
-
- for get_version_name_method in [
- VersionUtils._get_version_name_from_seedsigner_os_env_var,
- VersionUtils._get_version_name_from_git_shell,
- ]:
- version_name = get_version_name_method()
- if version_name:
- break
+ is_seedsigner_os_builder = VersionUtils._is_seedsigner_os_builder_env()
- version_timestamp = VersionUtils._get_version_timestamp_from_git_shell()
- version_commit_hash = VersionUtils._get_full_commit_hash_from_git_shell()
+ if not is_seedsigner_os_builder:
+ # Pull version_name from the current git state via `git` shell commands
+ version_name = VersionUtils._get_version_name_from_git_shell()
+
+ # Temporarily set the env var
+ os.environ[VersionUtils.ENV_VAR__SEEDSIGNER_OS_BUILDER__VERSION_NAME] = version_name
- if not version_name or not version_timestamp or not version_commit_hash:
- raise Exception("Could not determine version information from git.")
-
- version_info[VersionUtils.VERSIONFILE_ATTR__NAME] = version_name
- version_info[VersionUtils.VERSIONFILE_ATTR__FORK] = VersionUtils._get_version_fork_from_git_shell()
- version_info[VersionUtils.VERSIONFILE_ATTR__TIMESTAMP] = version_timestamp.isoformat()
- version_info[VersionUtils.VERSIONFILE_ATTR__COMMIT_HASH] = version_commit_hash[:7] # short hash
+ # When the `Version` singleton instantiates itself, it will determine for itself how to
+ # get the timestamp based on the SeedSigner OS builder env var being set or not.
+ version_instance = Version.get_instance()
+ version_info = version_instance.to_dict()
version_file_path = VersionUtils._get_version_file_path()
with open(version_file_path, "w") as f:
@@ -64,3 +58,7 @@ if __name__ == "__main__":
print(f"Wrote version info to: {version_file_path}")
print(json.dumps(version_info, indent=4))
+
+ # Clean up the temp env var if needed
+ if not is_seedsigner_os_builder:
+ del os.environ[VersionUtils.ENV_VAR__SEEDSIGNER_OS_BUILDER__VERSION_NAME]
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.