Skip to content

Commit e400964

Browse files
committed
Make sure the feature README is updated when the default Ruby version changes
1 parent 88af9e3 commit e400964

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

bin/add-ruby-version

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* 2. Check if the version already exists
1616
* 3. Add the version to the workflow matrix
1717
* 4. Update the default version if the new version is newer
18-
* 5. Bump the feature version when the default changes
19-
* 6. Update test files to use the new version
18+
* 5. Update the README.md default version
19+
* 6. Bump the feature version when the default changes
20+
* 7. Update test files to use the new version
2021
*
2122
* @author Rails Team
2223
* @version 1.0.0
@@ -45,6 +46,7 @@ const VERSION_REPLACEMENT_REGEX = new RegExp(`(${VERSION_PATTERN})`, 'g');
4546
// File paths
4647
const YAML_FILE = '.github/workflows/publish-new-image-version.yaml';
4748
const JSON_FILE = 'features/src/ruby/devcontainer-feature.json';
49+
const README_FILE = 'features/src/ruby/README.md';
4850
const TEST_FILES = [
4951
'features/test/ruby/test.sh',
5052
'features/test/ruby/with_rbenv.sh'
@@ -182,6 +184,28 @@ function updateVersionInTestFile(newVersion, testFile) {
182184
}
183185
}
184186

187+
/**
188+
* Updates the default version in the README.md file
189+
* @param {string} newVersion - The new default version
190+
* @param {string} readmeFile - Path to the README.md file
191+
* @returns {boolean} Success status
192+
*/
193+
function updateReadmeDefaultVersion(newVersion, readmeFile) {
194+
try {
195+
const content = fs.readFileSync(readmeFile, 'utf8');
196+
197+
// Update the default value in the options table
198+
// Look for the pattern: | version | ... | string | X.Y.Z |
199+
const readmeVersionRegex = /(\| version \| [^|]+ \| string \| )(\d+\.\d+\.\d+)( \|)/;
200+
const updatedContent = content.replace(readmeVersionRegex, `$1${newVersion}$3`);
201+
202+
fs.writeFileSync(readmeFile, updatedContent);
203+
return true;
204+
} catch (error) {
205+
throw new Error(`Could not update README file ${readmeFile}: ${error.message}`);
206+
}
207+
}
208+
185209
// === VERSION VALIDATION ===
186210
/**
187211
* Validates if a version string matches the expected format
@@ -199,6 +223,7 @@ function validateConfiguration() {
199223
// Check if files exist
200224
checkFileExists(YAML_FILE);
201225
checkFileExists(JSON_FILE);
226+
checkFileExists(README_FILE);
202227

203228
// Check if test files exist
204229
for (const testFile of TEST_FILES) {
@@ -360,13 +385,18 @@ function main() {
360385
updateDefaultInJson(newVersion, JSON_FILE);
361386
log(`${emoji.check} Updated default version to ${newVersion}`, 'green');
362387

388+
// Update README with new default version
389+
log(`Updating default version in ${README_FILE}...`);
390+
updateReadmeDefaultVersion(newVersion, README_FILE);
391+
log(`${emoji.check} Updated README default version to ${newVersion}`, 'green');
392+
363393
// Bump feature version when default changes
364394
log('');
365395
log(`${emoji.update} Bumping feature version...`, 'yellow');
366396
const versionInfo = bumpFeatureVersion(JSON_FILE);
367397
log(`${emoji.check} Feature version bumped from ${versionInfo.oldVersion} to ${versionInfo.newVersion}`, 'green');
368398

369-
filesModified.push(JSON_FILE);
399+
filesModified.push(JSON_FILE, README_FILE);
370400
} else {
371401
log('');
372402
log(`${emoji.info} New version ${newVersion} is not newer than current default ${currentDefault}`, 'cyan');

features/src/ruby/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Installs Ruby and a version manager (mise or rbenv) along with the dependencies
4040

4141
| Options Id | Description | Type | Default Value |
4242
|-----|-----|-----|-----|
43-
| version | The version of ruby to be installed | string | 3.4.1 |
43+
| version | The version of ruby to be installed | string | 3.4.7 |
4444
| versionManager | The version manager to use for Ruby (mise or rbenv) | string | mise |
4545

4646
## Customizations

0 commit comments

Comments
 (0)