@@ -109,6 +109,42 @@ function updateDefaultInJson(newVersion, jsonFile) {
109109 }
110110}
111111
112+ function updateVersionInTestFile ( newVersion , testFile ) {
113+ try {
114+ const content = fs . readFileSync ( testFile , 'utf8' ) ;
115+
116+ // Replace version in the test file using regex to find the version pattern
117+ const versionRegex = / ( \d + \. \d + \. \d + ) / g;
118+ const updatedContent = content . replace ( versionRegex , newVersion ) ;
119+
120+ fs . writeFileSync ( testFile , updatedContent ) ;
121+ return true ;
122+ } catch ( error ) {
123+ throw new Error ( `Could not update test file ${ testFile } : ${ error . message } ` ) ;
124+ }
125+ }
126+
127+ function bumpFeatureVersion ( jsonFile ) {
128+ try {
129+ const content = fs . readFileSync ( jsonFile , 'utf8' ) ;
130+ const data = JSON . parse ( content ) ;
131+
132+ // Parse current version and increment patch version
133+ const currentVersion = data . version ;
134+ const incrementedVersion = semver . inc ( currentVersion , 'patch' ) ;
135+
136+ data . version = incrementedVersion ;
137+ fs . writeFileSync ( jsonFile , JSON . stringify ( data , null , 4 ) + '\n' ) ;
138+
139+ return {
140+ oldVersion : currentVersion ,
141+ newVersion : incrementedVersion
142+ } ;
143+ } catch ( error ) {
144+ throw new Error ( `Could not bump feature version: ${ error . message } ` ) ;
145+ }
146+ }
147+
112148function main ( ) {
113149 // Check command line arguments
114150 const args = process . argv . slice ( 2 ) ;
@@ -122,6 +158,10 @@ function main() {
122158 const newVersion = args [ 0 ] ;
123159 const yamlFile = '.github/workflows/publish-new-image-version.yaml' ;
124160 const jsonFile = 'features/src/ruby/devcontainer-feature.json' ;
161+ const testFiles = [
162+ 'features/test/ruby/test.sh' ,
163+ 'features/test/ruby/with_rbenv.sh'
164+ ] ;
125165
126166 // Validate version format
127167 if ( ! validateVersionFormat ( newVersion ) ) {
@@ -140,6 +180,14 @@ function main() {
140180 process . exit ( 1 ) ;
141181 }
142182
183+ // Check if test files exist
184+ for ( const testFile of testFiles ) {
185+ if ( ! fs . existsSync ( testFile ) ) {
186+ log ( `${ emoji . error } Error: ${ testFile } not found` , 'red' ) ;
187+ process . exit ( 1 ) ;
188+ }
189+ }
190+
143191 try {
144192 // Check if version already exists
145193 if ( versionExistsInYaml ( newVersion , yamlFile ) ) {
@@ -170,13 +218,29 @@ function main() {
170218 log ( `Updating default version in ${ jsonFile } ...` ) ;
171219 updateDefaultInJson ( newVersion , jsonFile ) ;
172220 log ( `${ emoji . check } Updated default version to ${ newVersion } ` , 'green' ) ;
221+
222+ // Bump feature version when default changes
223+ log ( '' ) ;
224+ log ( `${ emoji . update } Bumping feature version...` , 'yellow' ) ;
225+ const versionInfo = bumpFeatureVersion ( jsonFile ) ;
226+ log ( `${ emoji . check } Feature version bumped from ${ versionInfo . oldVersion } to ${ versionInfo . newVersion } ` , 'green' ) ;
227+
173228 filesModified . push ( jsonFile ) ;
174229 } else {
175230 log ( '' ) ;
176231 log ( `${ emoji . info } New version ${ newVersion } is not newer than current default ${ currentDefault } ` , 'cyan' ) ;
177232 log ( 'Default version remains unchanged' ) ;
178233 }
179234
235+ // Update test files
236+ log ( '' ) ;
237+ log ( `${ emoji . edit } Updating test files...` , 'blue' ) ;
238+ for ( const testFile of testFiles ) {
239+ updateVersionInTestFile ( newVersion , testFile ) ;
240+ log ( `${ emoji . check } Updated ${ testFile } ` , 'green' ) ;
241+ filesModified . push ( testFile ) ;
242+ }
243+
180244 // Success message
181245 log ( '' ) ;
182246 log ( `${ emoji . party } Successfully added Ruby version ${ newVersion } !` , 'green' ) ;
0 commit comments