Skip to content

Commit 120b84c

Browse files
authored
Merge pull request #76 from lightspeedwp/claude/add-frontmatter-validation-011CV45rVq7VRb6yu5sJpGGc
PR: Implement per-file versioning & frontmatter reference validation system
2 parents ef5de88 + c7ef239 commit 120b84c

File tree

4 files changed

+905
-4
lines changed

4 files changed

+905
-4
lines changed

docs/VERSIONING.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,142 @@ git push origin main --tags
143143
5. **Follow WordPress and SemVer guidelines**
144144
6. **Automate version updates and verification** whenever possible
145145
7. **Communicate changes** to users via changelog and release notes
146+
147+
---
148+
149+
## Alternative: Per-File Versioning Strategy (Experimental)
150+
151+
> **Note**: This is an alternative versioning approach for documentation and configuration files. The unified versioning strategy above remains the recommended default.
152+
153+
### Overview
154+
155+
For documentation-heavy repositories (like `.github`), individual files may evolve independently. This strategy allows per-file semantic versioning whilst maintaining coordination with the repository version.
156+
157+
### Rules
158+
159+
- **Repository version** (`/VERSION`): Uses `X.Y.0` format for coordinated releases
160+
- **File version** (`version:` in frontmatter): Independent `X.Y.Z` versioning per file
161+
- **Guardrail**: A file's minor version (`X.Y`) **must not exceed** the repository's minor version
162+
163+
### Version Bump Types
164+
165+
#### Patch Bump (`X.Y.Z``X.Y.Z+1`)
166+
- Content edits, typo fixes, clarifications
167+
- No schema or structural changes
168+
- Safe for all consumers
169+
170+
#### Minor Bump (`X.Y.Z``X.Y+1.0`)
171+
- Schema-related key changes in that file
172+
- New required fields or breaking changes for agents
173+
- Must not exceed repository minor version
174+
175+
### Examples
176+
177+
**Scenario 1: Edit instruction prose**
178+
- Current: `version: 0.1.3`
179+
- Action: Fix typos, clarify instructions
180+
- Result: `version: 0.1.4` (patch bump)
181+
182+
**Scenario 2: Add required frontmatter field**
183+
- Current: `version: 0.2.5`, Repo: `0.2.0`
184+
- Action: Add new required `applyTo` field
185+
- Result: Cannot bump to `0.3.0` (would exceed repo `0.2.0`)
186+
- Must wait for repo bump to `0.3.0` first
187+
188+
**Scenario 3: Coordinated release**
189+
- Repo bumps: `0.2.0``0.3.0`
190+
- Files with breaking changes: bump to `0.3.0`
191+
- Files with only content edits: remain at `0.2.x` or bump patch
192+
193+
### Guardrails
194+
195+
A file **must not** have a minor version exceeding the repository minor version:
196+
197+
- ✓ File `0.2.8` with Repo `0.2.0` (valid)
198+
- ✓ File `0.2.0` with Repo `0.3.0` (valid)
199+
- ✗ File `0.3.0` with Repo `0.2.0` (invalid - exceeds repo minor)
200+
201+
### Automation
202+
203+
Use `scripts/versioning/bump-file-version.js` for single or bulk version bumps:
204+
205+
```bash
206+
# Bump patch version of a single file
207+
node scripts/versioning/bump-file-version.js .github/instructions/coding-standards.instructions.md patch
208+
209+
# Bump minor version (with guardrail check)
210+
node scripts/versioning/bump-file-version.js .github/prompts/review.prompt.md minor
211+
212+
# Bulk bump patch versions
213+
node scripts/versioning/bump-file-version.js --bulk ".github/instructions/**/*.md" patch
214+
```
215+
216+
The script will:
217+
- Automatically update the `version` field
218+
- Update `last_updated` to current date
219+
- Enforce the guardrail (file minor ≤ repo minor)
220+
- Exit with error if guardrail would be violated
221+
222+
### CI Validation
223+
224+
Add a CI check to ensure file versions don't exceed repository version:
225+
226+
```yaml
227+
- name: Validate file versions
228+
run: |
229+
REPO_VERSION=$(cat VERSION)
230+
node scripts/versioning/validate-versions.js --repo-version $REPO_VERSION
231+
```
232+
233+
### When to Use
234+
235+
**Use per-file versioning when:**
236+
- Documentation/instructions evolve independently
237+
- Fine-grained change tracking is valuable
238+
- Multiple maintainers update different files
239+
240+
**Use unified versioning when:**
241+
- Coordinated releases are preferred
242+
- Simplicity is more important than granularity
243+
- All files change together
244+
245+
---
246+
247+
## Automation Scripts
248+
249+
### Available Scripts
250+
251+
#### `scripts/versioning/bump-file-version.cjs`
252+
Bump individual or bulk file versions with guardrails:
253+
254+
```bash
255+
# Single file
256+
node scripts/versioning/bump-file-version.cjs <file> [patch|minor]
257+
258+
# Bulk update
259+
node scripts/versioning/bump-file-version.cjs --bulk "<pattern>" [patch|minor]
260+
261+
# Help
262+
node scripts/versioning/bump-file-version.cjs --help
263+
```
264+
265+
#### `scripts/maintenance/fix-references.cjs`
266+
Validate and fix broken reference links in frontmatter:
267+
268+
```bash
269+
# Scan and fix all references
270+
node scripts/maintenance/fix-references.cjs
271+
272+
# Show current fix map
273+
node scripts/maintenance/fix-references.cjs --fix-map
274+
275+
# Help
276+
node scripts/maintenance/fix-references.cjs --help
277+
```
278+
279+
### Integration with CI/CD
280+
281+
Consider adding these scripts to GitHub Actions workflows for:
282+
- Pre-commit hooks (validate versions before commit)
283+
- Pull request checks (ensure references are valid)
284+
- Release automation (bulk bump versions on release)

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@
121121
"lint:md": "markdownlint '**/*.md' --fix",
122122
"format:js": "prettier '**/*.{js,jsx,ts,tsx}' --write && prettier '**/*.json' --write && eslint '**/*.{js,jsx,ts,tsx}' --fix --format && eslint '**/*.json' --fix --format",
123123
"format:md": "prettier '**/*.md' --write && markdownlint '**/*.md' --fix",
124-
<<<<<<< Updated upstream
125124
"format": "npm run format:js && npm run format:md",
126-
=======
127-
"format": "npm run format:js && npm run format:md",
128-
>>>>>>> Stashed changes
129125
"sync-version": "node scripts/sync-version.js",
130126
"metrics:run": "node metrics/frontmatter-metrics.js",
131127
"metrics:ci": "node metrics/frontmatter-metrics.js",

0 commit comments

Comments
 (0)