Skip to content

Commit 007f23c

Browse files
authored
Update block.json versions during releases (#2659)
1 parent 7c51303 commit 007f23c

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

bin/__tests__/fixtures/block.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/block.json",
3+
"name": "activitypub/test-block",
4+
"apiVersion": 3,
5+
"version": "2.0.0",
6+
"title": "Test Block",
7+
"category": "widgets",
8+
"description": "A test block for version replacement testing.",
9+
"textdomain": "activitypub"
10+
}

bin/__tests__/release.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,65 @@ function old_function() {}`;
239239
} );
240240
} );
241241

242+
describe( 'Block.json file patterns (src/**/block.json)', () => {
243+
const patterns = [
244+
{
245+
search: /"version": "\d+\.\d+\.\d+"/,
246+
replace: `"version": "${ testVersion }"`,
247+
},
248+
];
249+
250+
test( 'replaces version field in block.json', () => {
251+
const content = `{
252+
"$schema": "https://schemas.wp.org/trunk/block.json",
253+
"name": "activitypub/follow-me",
254+
"version": "2.0.0",
255+
"title": "Follow me"
256+
}`;
257+
258+
const result = applyVersionReplacements( content, testVersion, patterns );
259+
expect( result ).toContain( `"version": "${ testVersion }"` );
260+
expect( result ).not.toContain( '"version": "2.0.0"' );
261+
} );
262+
263+
test( 'replaces version in block.json fixture file', () => {
264+
const fixturePath = path.join( __dirname, 'fixtures', 'block.json' );
265+
const content = fs.readFileSync( fixturePath, 'utf8' );
266+
267+
const result = applyVersionReplacements( content, testVersion, patterns );
268+
expect( result ).toContain( `"version": "${ testVersion }"` );
269+
expect( result ).not.toContain( '"version": "2.0.0"' );
270+
} );
271+
272+
test( 'preserves other JSON structure', () => {
273+
const content = `{
274+
"$schema": "https://schemas.wp.org/trunk/block.json",
275+
"name": "activitypub/test-block",
276+
"apiVersion": 3,
277+
"version": "1.5.0",
278+
"title": "Test Block",
279+
"category": "widgets"
280+
}`;
281+
282+
const result = applyVersionReplacements( content, testVersion, patterns );
283+
expect( result ).toContain( '"name": "activitypub/test-block"' );
284+
expect( result ).toContain( '"apiVersion": 3' );
285+
expect( result ).toContain( '"title": "Test Block"' );
286+
expect( result ).toContain( `"version": "${ testVersion }"` );
287+
} );
288+
289+
test( 'handles version field regardless of position', () => {
290+
const content = `{
291+
"version": "0.9.0",
292+
"name": "activitypub/early-version"
293+
}`;
294+
295+
const result = applyVersionReplacements( content, testVersion, patterns );
296+
expect( result ).toContain( `"version": "${ testVersion }"` );
297+
expect( result ).not.toContain( '"version": "0.9.0"' );
298+
} );
299+
} );
300+
242301
describe( 'Edge cases and complex scenarios', () => {
243302
test( 'handles multiple replacements in single file', () => {
244303
const content = `/**

bin/release.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,20 @@ async function createRelease() {
280280
] );
281281
} );
282282

283+
// Update version in block.json files
284+
const blockJsonFiles = execWithOutput( 'find src -name "block.json"' ).split( '\n' );
285+
286+
blockJsonFiles.forEach( ( filePath ) => {
287+
if ( filePath ) {
288+
updateVersionInFile( filePath, version, [
289+
{
290+
search: /"version": "\d+\.\d+\.\d+"/,
291+
replace: `"version": "${ version }"`,
292+
},
293+
] );
294+
}
295+
} );
296+
283297
// Stage and commit changes
284298
exec( 'git add .' );
285299
exec( `git commit -m "Release ${ version }"` );

0 commit comments

Comments
 (0)