Versioning & GitFlow
Versioning & GitFlow
Relevant source files
The following files were used as context for generating this wiki page:
This page documents the automated versioning pipeline and the Git branching strategy used in the Primebrick Frontend. The system ensures that the version declared in package.json remains synchronized with Git tags and branch names, enforcing a strict release and hotfix lifecycle.
Automated Version Synchronization
The project utilizes a custom script, version-sync.mjs, to automate the update of the package.json version field based on the current Git context. This script acts as a safeguard to prevent version mismatches during the build and release processes.
Implementation Details
The script is located at scripts/version-sync.mjs and is integrated into the development lifecycle via package.json scripts. It is executed automatically as a prebuild hook package.json:9-9.
Key Functions:
latestTagVersion(): Scans the Git history for tags matching the0.*.*pattern, parses them, and returns the highest version found scripts/version-sync.mjs:33-46.nextVersion(kind, latest): Calculates the next semantic version. Areleaseincrements the minor version and resets the patch to 0, while ahotfixincrements the patch version scripts/version-sync.mjs:48-52.parseTag(tag): Uses a regex^(0)\.(\d+)\.(\d+)$to ensure tags follow the strictly required format without avprefix scripts/version-sync.mjs:16-21.
Data Flow: Version Validation
The script follows a specific logic flow to determine if package.json should be updated or if the build should fail:
- Branch Detection: It identifies the current branch name using
git rev-parse. - Kind Identification: It checks if the branch starts with
release/orhotfix/. If it is a feature or development branch, the script exits silently scripts/version-sync.mjs:69-75. - Validation: It calculates the "Expected Version" based on the latest tag. If the current branch name does not match
kind/expected-version, the process exits with an error, blocking the build scripts/version-sync.mjs:81-91. - Update: If the branch name is valid but
package.jsonstill reflects an old version, the script overwrites theversionfield inpackage.jsonscripts/version-sync.mjs:97-104.
Version Sync Logic Diagram
Code
Sources: scripts/version-sync.mjs:1-109, package.json:8-10
GitFlow Conventions
The repository follows a strict GitFlow workflow to manage features, releases, and production fixes.
Branch Types
| Branch Prefix | Base Branch | Merge Target | Purpose |
|---|---|---|---|
feature/ | develop | develop | New functionality or UI changes. |
release/ | develop | main & develop | Preparing for a new production deployment (Minor bump). |
hotfix/ | main | main & develop | Urgent fixes for production (Patch bump). |
Branch Management Rules
- No Direct Commits: Working directly on
developormainis strictly prohibited docs/gitflow.md:18-18. - Merge Strategy: All merges into
mainordevelopfrom a feature/release/hotfix branch must use the--no-ff(no-fast-forward) flag to preserve the branch history docs/gitflow.md:34-36. - Cleanup: After a successful merge and push to origin, branches must be deleted both locally and on the remote (
origin) docs/gitflow.md:40-42.
Tag Naming Rules
The project enforces a specific format for Git tags to ensure compatibility with the automated scripts:
- No 'v' Prefix: Tags must be
0.32.0, notv0.32.0docs/gitflow.md:70-71. - Derivation: The tag must exactly match the version number in the
release/orhotfix/branch name docs/gitflow.md:72-72.
Sources: docs/gitflow.md:16-75, AGENTS.md:48-53
Commit & Hook Policy
Pre-commit Hook
The repository includes a .githooks/pre-commit hook (managed via the workspace setup). This hook ensures that code quality is maintained before any commit is finalized. It typically triggers the pnpm run check command, which executes svelte-check and tsc package.json:13-13.
AI Agent Constraints
AI agents (like Devin or Windsurf) are subject to critical restrictions regarding Git operations:
- Explicit Instruction: Agents MUST NEVER commit automatically. They must wait for a user to explicitly say "commit" or "procedi con il commit" AGENTS.md:3-9.
- New Tasks: When starting a new task, agents must infer a slug and create a
feature/<slug>branch before making any changes docs/gitflow.md:107-114.
GitFlow Entity Mapping Diagram
This diagram maps the natural language GitFlow concepts to the specific code entities and scripts that enforce them.
Code
Sources: scripts/version-sync.mjs:1-109, package.json:1-14, docs/gitflow.md:46-66
Release & Hotfix Workflow
Standard Release Procedure
- Create a branch:
git checkout -b release/0.X.0fromdevelop. - Run
pnpm run build. Theversion-sync.mjsscript will detect the branch and updatepackage.jsonto0.X.0docs/gitflow.md:57-58. - Merge to
mainusing--no-ff. - Tag the commit on
mainwith0.X.0. - Merge
mainback intodevelopto ensure the version update and any final release tweaks are propagated docs/gitflow.md:62-62.
Hotfix Procedure
- Create a branch:
git checkout -b hotfix/0.X.Yfrommain. - The
version-sync.mjsscript ensures the patch versionYis correctly incremented based on the last tag scripts/version-sync.mjs:50-50. - Follow the same merge and tagging steps as the release procedure.
Sources: docs/gitflow.md:56-66, scripts/version-sync.mjs:48-52