Skip to content

Commit ecf9cf9

Browse files
committed
- add a plan for implementing @SInCE tag replacement
- add update-since-tags script - add npm script for running the update-since-tags script - add chalk as a dependency
1 parent 4da8a52 commit ecf9cf9

File tree

3 files changed

+248
-1
lines changed

3 files changed

+248
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# @since Tag Update Implementation Plan
2+
3+
## Overview
4+
5+
This document outlines the plan for implementing automated `@since` tag updates during the release process. The system will update placeholder version tags (such as `@since todo`, `@since next-version`, and `@since tbd`) with the actual version number during releases.
6+
7+
## Implementation Checklist
8+
9+
### 1. Package.json Updates
10+
- [ ] Add `chalk` to devDependencies
11+
- [ ] Add a new npm script for running the update-since-tags.js (e.g., `since-tags:update`)
12+
13+
### 2. Script Enhancements (update-since-tags.js)
14+
- [ ] Add better console output formatting using chalk
15+
- [ ] Enhance logging to provide detailed information about updated files
16+
- [ ] Add functionality to generate a summary of updates for release notes
17+
- [ ] Add documentation for supported placeholders (`todo`, `next-version`, `tbd`)
18+
- [ ] Add error handling for file operations
19+
- [ ] Add validation for version number input
20+
21+
### 3. Release Management Workflow Updates
22+
- [ ] Add new step in release-management.yml after version bump
23+
- [ ] Integrate since-tag updates into the workflow
24+
- [ ] Add logging output to release notes
25+
- [ ] Handle potential errors gracefully
26+
- [ ] Ensure changes are committed with version bump
27+
28+
### 4. Changeset Integration
29+
- [ ] Modify generate-changeset.yml to detect files with @since placeholders
30+
- [ ] Add @since placeholder information to changeset content
31+
- [ ] Update release PR template to include @since placeholder information
32+
- [ ] Ensure this information flows through to final release notes
33+
34+
### 5. Documentation Updates
35+
- [ ] Update SUMMARY.md with new functionality
36+
- [ ] Update main README.md with @since tag information
37+
- [ ] Update workflow documentation
38+
- [ ] Add examples of using @since placeholders
39+
- [ ] Document supported file types (PHP only for now)
40+
41+
### 6. Testing
42+
- [ ] Test script locally with various scenarios
43+
- [ ] Test workflow with actual PR and release
44+
- [ ] Test error scenarios
45+
- [ ] Test with multiple @since tags in single file
46+
- [ ] Test with no @since tags present
47+
48+
## Supported Placeholders
49+
50+
The following placeholders will be automatically updated during release:
51+
- `@since todo`
52+
- `@since next-version`
53+
- `@since tbd`
54+
55+
## File Types
56+
57+
Currently, the system only scans PHP files for @since placeholders. This may be expanded in future versions.
58+
59+
## Notes
60+
61+
- The script currently works as-is, so we won't refactor the module system (ES modules vs CommonJS) at this time
62+
- We'll focus on PHP files only for the initial implementation
63+
- Changes should be made incrementally to avoid disrupting existing workflows
64+
- Each change should be tested thoroughly before moving to the next item
65+
66+
## Future Considerations
67+
68+
- Support for additional file types (js, jsx, tsx, etc.)
69+
- Support for additional placeholder formats
70+
- Integration with other documentation tools
71+
- Automated testing for the script
72+
- Performance optimization for large codebases

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build": "node scripts/build.js",
1515
"release:prepare": "npm run version:bump && npm run changelogs:update",
1616
"test": "echo \"Error: no test specified\" && exit 1",
17-
"upgrade-notice:update": "node scripts/update-upgrade-notice.js"
17+
"upgrade-notice:update": "node scripts/update-upgrade-notice.js",
18+
"since-tags:update": "node scripts/update-since-tags.js"
1819
},
1920
"repository": {
2021
"type": "git",
@@ -35,6 +36,7 @@
3536
"homepage": "https://github.com/jasonbahl/automation-tests#readme",
3637
"devDependencies": {
3738
"archiver": "^5.3.1",
39+
"chalk": "^5.3.0",
3840
"dotenv": "^16.4.7",
3941
"fs-extra": "^11.1.1",
4042
"glob": "^10.3.3",

scripts/update-since-tags.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { glob } = require('glob');
4+
5+
/**
6+
* Find files containing @since todo tags
7+
*/
8+
async function findSinceTodoFiles(pattern = 'src/**/*.php') {
9+
try {
10+
console.log('\nDebug: Current working directory:', process.cwd());
11+
console.log('Debug: Looking for files matching pattern:', pattern);
12+
13+
// Use glob.sync instead of async glob for simpler handling
14+
const files = glob.sync(pattern, {
15+
ignore: [
16+
'node_modules/**',
17+
'vendor/**',
18+
'phpcs/**',
19+
'.github/**',
20+
'.wordpress-org/**',
21+
'bin/**',
22+
'build/**',
23+
'docker/**',
24+
'img/**',
25+
'phpstan/**',
26+
'docs/**'
27+
],
28+
dot: false, // Ignore dot directories
29+
cwd: process.cwd()
30+
});
31+
32+
console.log('Debug: Found files:', files);
33+
34+
return files || [];
35+
} catch (error) {
36+
console.error('Error finding files:', error);
37+
return [];
38+
}
39+
}
40+
41+
/**
42+
* Get all @since placeholders from a file
43+
*/
44+
function getSincePlaceholders(content) {
45+
// Update regex to match all our valid placeholders
46+
const regex = /@since\s+(todo|next-version|tbd)|@next-version/gi;
47+
const matches = content.match(regex);
48+
return matches ? matches.length : 0;
49+
}
50+
51+
/**
52+
* Update @since placeholders in a file
53+
*/
54+
function updateSinceTags(filePath, version) {
55+
try {
56+
let content = fs.readFileSync(filePath, 'utf8');
57+
const originalContent = content;
58+
59+
// Replace placeholders with the actual version
60+
content = content.replace(
61+
/@since\s+(todo|tbd|next-version)|@next-version/gi,
62+
`@since ${version}` // Use the provided version instead of 'next-version'
63+
);
64+
65+
// Only write if content changed
66+
if (content !== originalContent) {
67+
fs.writeFileSync(filePath, content);
68+
return true;
69+
}
70+
71+
return false;
72+
} catch (error) {
73+
throw new Error(`Error updating ${filePath}: ${error.message}`);
74+
}
75+
}
76+
77+
/**
78+
* Update all @since todo tags in the project
79+
*/
80+
async function updateAllSinceTags(version, pattern = '**/*.php') {
81+
const results = {
82+
updated: [],
83+
errors: []
84+
};
85+
86+
try {
87+
const files = await findSinceTodoFiles(pattern);
88+
console.log('Debug: Processing files:', files);
89+
90+
for (const file of files) {
91+
try {
92+
const content = fs.readFileSync(file, 'utf8');
93+
const count = getSincePlaceholders(content);
94+
console.log(`Debug: File ${file} has ${count} @since tags`);
95+
96+
if (count > 0) {
97+
const updated = updateSinceTags(file, version);
98+
if (updated) {
99+
results.updated.push(file);
100+
}
101+
}
102+
} catch (error) {
103+
results.errors.push({ file, error: error.message });
104+
}
105+
}
106+
107+
return results;
108+
} catch (error) {
109+
throw new Error(`Error updating @since tags: ${error.message}`);
110+
}
111+
}
112+
113+
/**
114+
* CLI command to update @since tags
115+
*/
116+
async function main() {
117+
const { default: chalk } = await import('chalk');
118+
119+
try {
120+
const version = process.argv[2];
121+
if (!version) {
122+
throw new Error('Version argument is required');
123+
}
124+
125+
console.log(chalk.blue('\nUpdating @since todo tags...'));
126+
const results = await updateAllSinceTags(version);
127+
128+
if (results.updated.length > 0) {
129+
console.log(chalk.green('\n✓ Updated files:'));
130+
results.updated.forEach(file => {
131+
console.log(chalk.gray(` - ${path.relative(process.cwd(), file)}`));
132+
});
133+
} else {
134+
console.log(chalk.yellow('\nNo @since todo tags found'));
135+
}
136+
137+
if (results.errors.length > 0) {
138+
console.log(chalk.red('\n❌ Errors:'));
139+
results.errors.forEach(({ file, error }) => {
140+
console.log(chalk.gray(` - ${path.relative(process.cwd(), file)}: ${error}`));
141+
});
142+
process.exit(1);
143+
}
144+
145+
process.exit(0);
146+
} catch (error) {
147+
console.error(chalk.red('\n❌ Error:'), error.message);
148+
process.exit(1);
149+
}
150+
}
151+
152+
// Run if called directly
153+
if (require.main === module) {
154+
main();
155+
}
156+
157+
/**
158+
* Get count of @since todo tags in content
159+
*/
160+
function getSinceTodoTags(content) {
161+
// Update to match all non-standard placeholders
162+
const regex = /@since\s+(todo|tbd)|@next-version/gi;
163+
const matches = content.match(regex);
164+
return matches ? matches.length : 0;
165+
}
166+
167+
module.exports = {
168+
findSinceTodoFiles,
169+
getSincePlaceholders,
170+
updateSinceTags,
171+
updateAllSinceTags,
172+
getSinceTodoTags
173+
};

0 commit comments

Comments
 (0)