Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ constexpr struct {
"
`;

exports[`updateReactNativeArtifacts should set nightly version: packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `
"version = \\"0.81.0-nightly-29282302-abcd1234\\\\
other text
version = \\"0.81.0-nightly-29282302-abcd1234\\\\"
`;

exports[`updateReactNativeArtifacts should set release version: packages/react-native/Libraries/Core/ReactNativeVersion.js 1`] = `
"/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
Expand Down Expand Up @@ -241,3 +247,9 @@ constexpr struct {
} // namespace facebook::react
"
`;

exports[`updateReactNativeArtifacts should set release version: packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `
"version = \\"0.81.0\\\\
other text
version = \\"0.81.0\\\\"
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`setVersion updates monorepo for nightly: ../../../../packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `"[omitted]"`;

exports[`setVersion updates monorepo for nightly: set-version/package.json 1`] = `
"{
\\"name\\": \\"@react-native/monorepo\\",
Expand Down Expand Up @@ -81,6 +83,8 @@ exports[`setVersion updates monorepo for nightly: set-version/packages/react-nat
"
`;

exports[`setVersion updates monorepo for release-candidate: ../../../../packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `"[omitted]"`;

exports[`setVersion updates monorepo for release-candidate: set-version/package.json 1`] = `
"{
\\"name\\": \\"@react-native/monorepo\\",
Expand Down Expand Up @@ -162,6 +166,8 @@ exports[`setVersion updates monorepo for release-candidate: set-version/packages
"
`;

exports[`setVersion updates monorepo for stable version: ../../../../packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap 1`] = `"[omitted]"`;

exports[`setVersion updates monorepo for stable version: set-version/package.json 1`] = `
"{
\\"name\\": \\"@react-native/monorepo\\",
Expand Down
14 changes: 14 additions & 0 deletions scripts/releases/__tests__/set-rn-artifacts-version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ describe('updateReactNativeArtifacts', () => {
) {
return 'VERSION_NAME=1000.0.0\n';
}

if (
filePath ===
path.join(
REPO_ROOT,
'packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap',
)
) {
return `
version = "1000.0.0\\
other text
version = "1000.0.0\\
`;
}
});
});

Expand Down
35 changes: 35 additions & 0 deletions scripts/releases/set-rn-artifacts-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ async function updateReactNativeArtifacts(
const versionInfo = parseVersion(version, buildType);

await updateSourceFiles(versionInfo);
await updateTestFiles(versionInfo);
await updateGradleFile(versionInfo.version);
}

Expand Down Expand Up @@ -116,6 +117,40 @@ function updateSourceFiles(
]);
}

function updateTestFiles(
versionInfo /*: Version */,
) /*: Promise<Array<void>>*/ {
const oldVersion = /"\d+\.\d+\.\d+(-rc\.\d+)?\\/g;
const newVersion = `"${versionInfo.version}\\`;

const snapshotTestPath = path.join(
__dirname,
'..',
'..',
'packages',
'react-native',
'scripts',
'codegen',
'__tests__',
'__snapshots__',
'generate-artifacts-executor-test.js.snap',
);

const promise /*: Promise<void> */ = new Promise(async (resolve, reject) => {
try {
let snapshot = String(await fs.readFile(snapshotTestPath, 'utf8')).trim();
// Replace all occurrences of the old version pattern with the new version
snapshot = snapshot.replaceAll(oldVersion, newVersion);
await fs.writeFile(snapshotTestPath, snapshot, {encoding: 'utf8'});
resolve();
} catch (error) {
reject(error);
}
});

return Promise.all([promise]);
}

async function updateGradleFile(version /*: string */) /*: Promise<void> */ {
const contents = await fs.readFile(GRADLE_FILE_PATH, 'utf-8');

Expand Down
Loading