Skip to content

Commit 79e2298

Browse files
authored
[RN][Release] Fix set-rn-version to consider also the codegen snapshot tests (#51156)
1 parent 619a0db commit 79e2298

6 files changed

Lines changed: 80 additions & 3 deletions

File tree

3077396185.mdt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Summary:
2+
This change fixes the script that updates the RN Version to also update the Codegen snapshots so that they are in sync with the current version of React Native.
3+
It also updates the Snapshot as it was failing in rc.0
4+
5+
## Changelog:
6+
[Internal] - Fixed script that updates the react native versions
7+
8+
## Test Plan:
9+
Tested locally by running `node ./scripts/releases/set-rn-artifacts-version --built-type release --to-version 0.80.0-rc.0` and verifying that the snapshot file was getting updated. I then run the `yarn test
10+
generate-artifacts-executor-test.js` command to verify that the tests were passing.

packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ exports[`execute "ReactAppDependencyProvider.podspec" should match snapshot 1`]
363363
# This source code is licensed under the MIT license found in the
364364
# LICENSE file in the root directory of this source tree.
365365
366-
version = \\"1000.0.0\\"
366+
version = \\"0.80.0-rc.0\\"
367367
source = { :git => 'https://github.com/facebook/react-native.git' }
368368
if version == '1000.0.0'
369369
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
@@ -401,7 +401,7 @@ exports[`execute "ReactCodegen.podspec" should match snapshot 1`] = `
401401
# This source code is licensed under the MIT license found in the
402402
# LICENSE file in the root directory of this source tree.
403403
404-
version = \\"1000.0.0\\"
404+
version = \\"0.80.0-rc.0\\"
405405
source = { :git => 'https://github.com/facebook/react-native.git' }
406406
if version == '1000.0.0'
407407
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
@@ -503,4 +503,4 @@ SCRIPT
503503
504504
end
505505
"
506-
`;
506+
`;

scripts/releases/__tests__/__snapshots__/set-rn-artifacts-version-test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ constexpr struct {
121121
"
122122
`;
123123
124+
exports[`updateReactNativeArtifacts should set nightly version: packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `
125+
"version = \\"0.81.0-nightly-29282302-abcd1234\\\\
126+
other text
127+
version = \\"0.81.0-nightly-29282302-abcd1234\\\\"
128+
`;
129+
124130
exports[`updateReactNativeArtifacts should set release version: packages/react-native/Libraries/Core/ReactNativeVersion.js 1`] = `
125131
"/**
126132
* Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -241,3 +247,9 @@ constexpr struct {
241247
} // namespace facebook::react
242248
"
243249
`;
250+
251+
exports[`updateReactNativeArtifacts should set release version: packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `
252+
"version = \\"0.81.0\\\\
253+
other text
254+
version = \\"0.81.0\\\\"
255+
`;

scripts/releases/__tests__/__snapshots__/set-version-test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`setVersion updates monorepo for nightly: ../../../../packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `"[omitted]"`;
4+
35
exports[`setVersion updates monorepo for nightly: set-version/package.json 1`] = `
46
"{
57
\\"name\\": \\"@react-native/monorepo\\",
@@ -81,6 +83,8 @@ exports[`setVersion updates monorepo for nightly: set-version/packages/react-nat
8183
"
8284
`;
8385

86+
exports[`setVersion updates monorepo for release-candidate: ../../../../packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `"[omitted]"`;
87+
8488
exports[`setVersion updates monorepo for release-candidate: set-version/package.json 1`] = `
8589
"{
8690
\\"name\\": \\"@react-native/monorepo\\",
@@ -162,6 +166,8 @@ exports[`setVersion updates monorepo for release-candidate: set-version/packages
162166
"
163167
`;
164168

169+
exports[`setVersion updates monorepo for stable version: ../../../../packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `"[omitted]"`;
170+
165171
exports[`setVersion updates monorepo for stable version: set-version/package.json 1`] = `
166172
"{
167173
\\"name\\": \\"@react-native/monorepo\\",

scripts/releases/__tests__/set-rn-artifacts-version-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ describe('updateReactNativeArtifacts', () => {
3737
) {
3838
return 'VERSION_NAME=1000.0.0\n';
3939
}
40+
41+
if (
42+
filePath ===
43+
path.join(
44+
REPO_ROOT,
45+
'packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap',
46+
)
47+
) {
48+
return `
49+
version = "1000.0.0\\
50+
other text
51+
version = "1000.0.0\\
52+
`;
53+
}
4054
});
4155
});
4256

scripts/releases/set-rn-artifacts-version.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ async function updateReactNativeArtifacts(
7979
const versionInfo = parseVersion(version, buildType);
8080

8181
await updateSourceFiles(versionInfo);
82+
await updateTestFiles(versionInfo);
8283
await updateGradleFile(versionInfo.version);
8384
}
8485

@@ -116,6 +117,40 @@ function updateSourceFiles(
116117
]);
117118
}
118119

120+
function updateTestFiles(
121+
versionInfo /*: Version */,
122+
) /*: Promise<Array<void>>*/ {
123+
const oldVersion = /"\d+\.\d+\.\d+(-rc\.\d+)?\\/g;
124+
const newVersion = `"${versionInfo.version}\\`;
125+
126+
const snapshotTestPath = path.join(
127+
__dirname,
128+
'..',
129+
'..',
130+
'packages',
131+
'react-native',
132+
'scripts',
133+
'codegen',
134+
'__tests__',
135+
'__snapshots__',
136+
'generate-artifacts-executor-test.js.snap',
137+
);
138+
139+
const promise /*: Promise<void> */ = new Promise(async (resolve, reject) => {
140+
try {
141+
let snapshot = String(await fs.readFile(snapshotTestPath, 'utf8')).trim();
142+
// Replace all occurrences of the old version pattern with the new version
143+
snapshot = snapshot.replaceAll(oldVersion, newVersion);
144+
await fs.writeFile(snapshotTestPath, snapshot, {encoding: 'utf8'});
145+
resolve();
146+
} catch (error) {
147+
reject(error);
148+
}
149+
});
150+
151+
return Promise.all([promise]);
152+
}
153+
119154
async function updateGradleFile(version /*: string */) /*: Promise<void> */ {
120155
const contents = await fs.readFile(GRADLE_FILE_PATH, 'utf-8');
121156

0 commit comments

Comments
 (0)