Skip to content

Commit 130fb7f

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Fix set-rn-version to account for codegen snapshot test files (#51157)
Summary: Pull Request resolved: #51157 test-js jobs are failing because the codegen snapshot tests generates a Podspecs withan hardcoded version that does not matches the version we are about to release. This fix updates the script that set the RN version to make sure it also updates the Codegen snapshots. This is a porting to `main` of [this PR](#51156). ## Changelog: [Internal] - Fix set-rn-version to account for codegen snapshot test files Reviewed By: fabriziocucci, cortinico Differential Revision: D74321590 fbshipit-source-id: 6837e60a0a2834030680f7ec0c7584bf2622f33e
1 parent 56b2690 commit 130fb7f

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

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)