Skip to content

Commit be30681

Browse files
committed
chore: add version sync tooling and CI check
1 parent b14da0c commit be30681

File tree

5 files changed

+209
-4
lines changed

5 files changed

+209
-4
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
- name: Install dependencies
3939
run: pnpm install --frozen-lockfile
4040

41+
- name: Check version sync
42+
run: pnpm run version:check
43+
4144
- name: Build site
4245
run: pnpm run docs:build
4346

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
.vercel
33
.env*.local
4-
site/
4+
site/
5+
md_notes/

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
2-
"name": "variables-contract",
2+
"name": "variable-design-standard",
33
"private": true,
4-
"version": "0.3.7",
4+
"version": "0.4.0",
55
"packageManager": "pnpm@10.26.0",
66
"scripts": {
77
"dev": "docmd dev",
88
"build": "docmd build",
99
"docs:dev": "docmd dev",
10-
"docs:build": "docmd build"
10+
"docs:build": "docmd build",
11+
"version:sync": "node scripts/sync-version.js",
12+
"version:check": "node scripts/check-version.js"
1113
},
1214
"devDependencies": {
1315
"@mgks/docmd": "^0.3.2"

scripts/check-version.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Version Check Script
5+
*
6+
* Validates that version numbers in documentation files match package.json version.
7+
* Exits with error code 1 if mismatches are found (for CI).
8+
*/
9+
10+
const fs = require('fs');
11+
const path = require('path');
12+
13+
// Read version from package.json
14+
const pkgPath = path.join(__dirname, '..', 'package.json');
15+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
16+
const expectedVersion = pkg.version;
17+
18+
if (!expectedVersion) {
19+
console.error('Error: No version found in package.json');
20+
process.exit(1);
21+
}
22+
23+
console.log(`Checking version consistency (expected: ${expectedVersion})...\n`);
24+
25+
// Define files and their patterns to check
26+
const files = [
27+
{
28+
path: path.join(__dirname, '..', 'README.md'),
29+
patterns: [
30+
{
31+
regex: /\*\*Version:\*\* (\d+\.\d+\.\d+)/,
32+
name: 'Version field'
33+
}
34+
]
35+
},
36+
{
37+
path: path.join(__dirname, '..', 'docs', 'index.md'),
38+
patterns: [
39+
{
40+
regex: /\| \*\*Version\*\* \| (\d+\.\d+\.\d+)/,
41+
name: 'Version field'
42+
}
43+
]
44+
},
45+
{
46+
path: path.join(__dirname, '..', 'docs', 'faq.md'),
47+
patterns: [
48+
{
49+
regex: /Version (\d+\.\d+\.\d+) is in Draft status/,
50+
name: 'Production-ready answer'
51+
}
52+
]
53+
},
54+
{
55+
path: path.join(__dirname, '..', 'docs', 'meta', 'change-log.md'),
56+
patterns: [
57+
{
58+
regex: /## Version (\d+\.\d+\.\d+) \(Current\)/,
59+
name: 'Current version header'
60+
}
61+
]
62+
}
63+
];
64+
65+
let hasMismatches = false;
66+
67+
// Check each file
68+
files.forEach(({ path: filePath, patterns }) => {
69+
if (!fs.existsSync(filePath)) {
70+
console.warn(`Warning: File not found: ${filePath}`);
71+
return;
72+
}
73+
74+
const content = fs.readFileSync(filePath, 'utf8');
75+
const relativePath = path.relative(process.cwd(), filePath);
76+
77+
patterns.forEach(({ regex, name }) => {
78+
const match = content.match(regex);
79+
if (match) {
80+
const foundVersion = match[1];
81+
if (foundVersion !== expectedVersion) {
82+
console.error(`✗ ${relativePath} (${name}): Found ${foundVersion}, expected ${expectedVersion}`);
83+
hasMismatches = true;
84+
} else {
85+
console.log(`✓ ${relativePath} (${name}): ${foundVersion}`);
86+
}
87+
} else {
88+
console.warn(`⚠ ${relativePath} (${name}): Pattern not found`);
89+
}
90+
});
91+
});
92+
93+
console.log('');
94+
95+
if (hasMismatches) {
96+
console.error('Version mismatch detected! Run "pnpm run version:sync" to fix.');
97+
process.exit(1);
98+
} else {
99+
console.log('All version numbers are in sync.');
100+
process.exit(0);
101+
}

scripts/sync-version.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Version Synchronization Script
5+
*
6+
* Reads version from package.json and updates version numbers in:
7+
* - README.md
8+
* - docs/index.md
9+
* - docs/faq.md
10+
* - docs/meta/change-log.md
11+
*/
12+
13+
const fs = require('fs');
14+
const path = require('path');
15+
16+
// Read version from package.json
17+
const pkgPath = path.join(__dirname, '..', 'package.json');
18+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
19+
const version = pkg.version;
20+
21+
if (!version) {
22+
console.error('Error: No version found in package.json');
23+
process.exit(1);
24+
}
25+
26+
console.log(`Syncing version ${version} across documentation files...\n`);
27+
28+
// Define files and their patterns
29+
const files = [
30+
{
31+
path: path.join(__dirname, '..', 'README.md'),
32+
patterns: [
33+
{
34+
regex: /\*\*Version:\*\* \d+\.\d+\.\d+/,
35+
replacement: `**Version:** ${version}`
36+
}
37+
]
38+
},
39+
{
40+
path: path.join(__dirname, '..', 'docs', 'index.md'),
41+
patterns: [
42+
{
43+
regex: /\| \*\*Version\*\* \| \d+\.\d+\.\d+/,
44+
replacement: `| **Version** | ${version}`
45+
}
46+
]
47+
},
48+
{
49+
path: path.join(__dirname, '..', 'docs', 'faq.md'),
50+
patterns: [
51+
{
52+
regex: /Version \d+\.\d+\.\d+ is in Draft status/,
53+
replacement: `Version ${version} is in Draft status`
54+
}
55+
]
56+
},
57+
{
58+
path: path.join(__dirname, '..', 'docs', 'meta', 'change-log.md'),
59+
patterns: [
60+
{
61+
regex: /## Version \d+\.\d+\.\d+ \(Current\)/,
62+
replacement: `## Version ${version} (Current)`
63+
}
64+
]
65+
}
66+
];
67+
68+
let updatedCount = 0;
69+
70+
// Process each file
71+
files.forEach(({ path: filePath, patterns }) => {
72+
if (!fs.existsSync(filePath)) {
73+
console.warn(`Warning: File not found: ${filePath}`);
74+
return;
75+
}
76+
77+
let content = fs.readFileSync(filePath, 'utf8');
78+
let fileUpdated = false;
79+
80+
patterns.forEach(({ regex, replacement }) => {
81+
if (regex.test(content)) {
82+
content = content.replace(regex, replacement);
83+
fileUpdated = true;
84+
}
85+
});
86+
87+
if (fileUpdated) {
88+
fs.writeFileSync(filePath, content, 'utf8');
89+
const relativePath = path.relative(process.cwd(), filePath);
90+
console.log(`✓ Updated ${relativePath}`);
91+
updatedCount++;
92+
} else {
93+
const relativePath = path.relative(process.cwd(), filePath);
94+
console.log(`- No changes needed in ${relativePath}`);
95+
}
96+
});
97+
98+
console.log(`\nSync complete. Updated ${updatedCount} file(s).`);

0 commit comments

Comments
 (0)