From 659793c6b84790e8813bb93b36cbbf3bbeb612f7 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:40:56 -0700 Subject: [PATCH] fix --- generate-all-mac.js | 16 ++-- generate-all.js | 15 ++-- new-release-tools.js | 178 +++++++++++++++++++++++++++++++++++++++++++ new-release.js | 161 +------------------------------------- wt-diffs | 1 + 5 files changed, 203 insertions(+), 168 deletions(-) create mode 100644 new-release-tools.js create mode 160000 wt-diffs diff --git a/generate-all-mac.js b/generate-all-mac.js index 6d69a431a8e..aede6d63a8f 100644 --- a/generate-all-mac.js +++ b/generate-all-mac.js @@ -3,6 +3,7 @@ const { execSync } = require("child_process"); const { join } = require("path"); const { existsSync } = require("fs"); +import { versionAlreadyExists } from './new-release-tools'; let onlyOne = false; @@ -24,11 +25,16 @@ function run() { matches[1] === "0" && Number.parseInt(matches[2]) >= 61; if (inVersionRange && (!isPrerelease || isPreviewRelease)) { - const newReleaseCmd = `node new-release.js ${rnwVersion} mac`; - console.log("Running: " + newReleaseCmd); - execSync(newReleaseCmd, { stdio: "inherit" }); - if (onlyOne){ - break; + + if (versionAlreadyExists(rnwVersion, true /*mac*/)) { + console.log(`Already generated diff for ${rnwVersion}`); + } else { + const newReleaseCmd = `node new-release.js ${rnwVersion} mac`; + console.log("Running: " + newReleaseCmd); + execSync(newReleaseCmd, { stdio: "inherit" }); + if (onlyOne) { + break; + } } } } diff --git a/generate-all.js b/generate-all.js index 1ee372bfaeb..17efaeac8f1 100644 --- a/generate-all.js +++ b/generate-all.js @@ -3,6 +3,7 @@ const { execSync } = require("child_process"); const { join } = require("path"); const { existsSync } = require("fs"); +import { versionAlreadyExists } from './new-release-tools'; let onlyOne = false; @@ -23,11 +24,15 @@ function run() { const inVersionRange = matches[1] === "0" && Number.parseInt(matches[2]) >= 61; if (inVersionRange && (!isPrerelease || isPreviewRelease)) { - const newReleaseCmd = `node new-release.js ${rnwVersion}`; - console.log("Running: " + newReleaseCmd); - execSync(newReleaseCmd, { stdio: "inherit" }); - if (onlyOne){ - break; + if (versionAlreadyExists(rnwVersion, false /*mac*/)) { + console.log(`Already generated diff for ${rnwVersion}`); + } else { + const newReleaseCmd = `node new-release.js ${rnwVersion}`; + console.log("Running: " + newReleaseCmd); + execSync(newReleaseCmd, { stdio: "inherit" }); + if (onlyOne) { + break; + } } } } diff --git a/new-release-tools.js b/new-release-tools.js new file mode 100644 index 00000000000..09f4d40d5df --- /dev/null +++ b/new-release-tools.js @@ -0,0 +1,178 @@ +// @ts-check +const { readFileSync, writeFileSync, existsSync, mkdirSync } = require("fs"); +const semver = require("semver"); + +// TODO Diffs need to ignore pfx files and android/ios dirs + +const path = require("path"); +const { execSync } = require("child_process"); + +function runCmd(cmd, cwd) { + console.log("Running: " + cmd); + const opts = cwd ? { cwd: cwd, stdio: "inherit" } : { stdio: "inherit" }; + execSync(cmd, opts); +} + +/** + * @param {string} [newRelease] - version of windows/macos + * @param {string} [rnVersion] - version of react-native to use with release + * @param {'cpp' | 'cs' | 'mac'} [apptype] - Either language to use for windows, or use mac + */ +function createNewRelease(newRelease, rnVersion, apptype) { + if (apptype !== "cpp" && apptype !== "cs" && apptype !== "mac") { + throw new Error("Must specify cpp or cs app type"); + } + + const appName = "RnDiffApp"; + const appBaseName = "app-base"; + + const wtAppPath = path.resolve(__dirname, "wt-app"); + const appDir = path.resolve(__dirname, "wt-app", appName); + + runCmd(`git worktree add wt-app ${appBaseName}`); + runCmd(`cd wt-app`); + + // clear any existing stuff + try { + runCmd(`rmdir /S /Q ${appName}`, wtAppPath); + } catch { + // Ignore failures + } + + runCmd(`git pull`, wtAppPath); + + // make a new branch + const branchName = `release/${apptype}/${newRelease}`; + try { + runCmd(`git branch -D "${branchName}"`, wtAppPath); + } catch { + // Ignore failures + } + runCmd(`git checkout -b "${branchName}"`, wtAppPath); + + runCmd( + `npx --yes react-native init "${appName}" --template react-native@${rnVersion}`, + wtAppPath + ); + if (apptype === "mac") { + runCmd( + `npx --yes react-native-macos-init --version ${newRelease} --overwrite`, + appDir + ); + } else { + runCmd( + `npx --yes react-native-windows-init --version ${newRelease} --overwrite --language ${apptype}`, + appDir + ); + // Modify some files to prevent new guids being generated and showing up in the diffs + runCmd(`node ../standardizeProj.js`, wtAppPath); + } + runCmd(`git add ${appName}`, wtAppPath); + runCmd(`git commit -m "Release ${apptype}/${newRelease}"`, wtAppPath); + runCmd( + `git push origin --delete "${branchName}" || git push origin "${branchName}"`, + wtAppPath + ); + runCmd(`git push --set-upstream origin "${branchName}"`, wtAppPath); + + // go back to master + runCmd(`rmdir /S /Q wt-app`); + runCmd(`git worktree prune`); +} + +let releasesWindows; +let releasesMac; +const releasesFileWindows = path.resolve(__dirname, "RELEASES"); +const releasesFileMac = path.resolve(__dirname, "RELEASES_MAC"); + +/** + * @param {boolean} [isMac] - get Mac releases instead of windows + */ +function getReleases(isMac) { + if (!isMac) { + if (!releasesWindows) { + releasesWindows = readFileSync(releasesFileWindows) + .toString() + .split("\n") + .map((_) => _.trim()); + } + + return releasesWindows; + } else { + if (!releasesMac) { + releasesMac = readFileSync(releasesFileMac) + .toString() + .split("\n") + .map((_) => _.trim()); + } + + return releasesMac; + } +} + +/** + * @param {string} [rnwVersion] + * @param {boolean} [mac] - mac vs windows + */ +function addReleaseToList(rnwVersion, mac) { + getReleases(mac).push(rnwVersion); + if (mac) { + releasesMac = releasesMac + .filter((a) => a) + .sort((a, b) => 0 - semver.compare(a, b)); + writeFileSync(releasesFileMac, releasesMac.join("\n")); + } else { + releasesWindows = releasesWindows + .filter((a) => a) + .sort((a, b) => 0 - semver.compare(a, b)); + writeFileSync(releasesFileWindows, releasesWindows.join("\n")); + } +} + +/** + * @param {string} [rnwVersion] + * @param {boolean} [mac] - mac vs windows + */ +function versionAlreadyExists(rnwVersion, mac) { + return getReleases(mac).indexOf(rnwVersion) >= 0; +} + +/** + * @param {string} [rnwVersion] + * @param {'cs' | 'cpp' | 'mac'} [apptype] + */ +function generateDiffs(rnwVersion, apptype) { + const wtDiffsDir = path.resolve(__dirname, "wt-diffs"); + + if (!existsSync("wt-diffs")) { + runCmd("git worktree add wt-diffs diffs"); + } + + runCmd("git pull", wtDiffsDir); + + if (!existsSync(path.resolve(wtDiffsDir, `diffs/${apptype}`))) { + mkdirSync(path.resolve(wtDiffsDir, `diffs/${apptype}`)); + } + + for (let existingRelease of getReleases(apptype === 'mac')) { + console.log("processing " + existingRelease); + if (existingRelease === rnwVersion) continue; + runCmd( + `git diff --binary origin/release/${apptype}/"${existingRelease}"..origin/release/${apptype}/"${rnwVersion}" > wt-diffs/diffs/${apptype}/"${existingRelease}".."${rnwVersion}".diff` + ); + runCmd( + `git diff --binary origin/release/${apptype}/"${rnwVersion}"..origin/release/${apptype}/"${existingRelease}" > wt-diffs/diffs/${apptype}/"${rnwVersion}".."${existingRelease}".diff` + ); + } + + runCmd("git add .", wtDiffsDir); + runCmd(`git commit -m "Add release ${rnwVersion} ${apptype} diffs"`, wtDiffsDir); + runCmd("git push", wtDiffsDir); +} + +module.exports = { + addReleaseToList, + createNewRelease, + generateDiffs, + versionAlreadyExists, +}; \ No newline at end of file diff --git a/new-release.js b/new-release.js index 869752a2f25..f23c31077e4 100644 --- a/new-release.js +++ b/new-release.js @@ -1,85 +1,12 @@ // @ts-check -const { readFileSync, writeFileSync, existsSync, mkdirSync } = require("fs"); const semver = require("semver"); +import {addReleaseToList, createNewRelease, generateDiffs, versionAlreadyExists} from './new-release-tools'; + // TODO Diffs need to ignore pfx files and android/ios dirs const path = require("path"); const { execSync } = require("child_process"); -const { exit } = require("process"); - -function runCmd(cmd, cwd) { - console.log("Running: " + cmd); - const opts = cwd ? { cwd: cwd, stdio: "inherit" } : { stdio: "inherit" }; - execSync(cmd, opts); -} - -/** - * @param {string} [newRelease] - version of windows/macos - * @param {string} [rnVersion] - version of react-native to use with release - * @param {'cpp' | 'cs' | 'mac'} [apptype] - Either language to use for windows, or use mac - */ -function createNewRelease(newRelease, rnVersion, apptype) { - if (apptype !== "cpp" && apptype !== "cs" && apptype !== "mac") { - throw new Error("Must specify cpp or cs app type"); - } - - const appName = "RnDiffApp"; - const appBaseName = "app-base"; - - const wtAppPath = path.resolve(__dirname, "wt-app"); - const appDir = path.resolve(__dirname, "wt-app", appName); - - runCmd(`git worktree add wt-app ${appBaseName}`); - runCmd(`cd wt-app`); - - // clear any existing stuff - try { - runCmd(`rmdir /S /Q ${appName}`, wtAppPath); - } catch { - // Ignore failures - } - - runCmd(`git pull`, wtAppPath); - - // make a new branch - const branchName = `release/${apptype}/${newRelease}`; - try { - runCmd(`git branch -D "${branchName}"`, wtAppPath); - } catch { - // Ignore failures - } - runCmd(`git checkout -b "${branchName}"`, wtAppPath); - - runCmd( - `npx --yes react-native init "${appName}" --template react-native@${rnVersion}`, - wtAppPath - ); - if (apptype === "mac") { - runCmd( - `npx --yes react-native-macos-init --version ${newRelease} --overwrite`, - appDir - ); - } else { - runCmd( - `npx --yes react-native-windows-init --version ${newRelease} --overwrite --language ${apptype}`, - appDir - ); - // Modify some files to prevent new guids being generated and showing up in the diffs - runCmd(`node ../standardizeProj.js`, wtAppPath); - } - runCmd(`git add ${appName}`, wtAppPath); - runCmd(`git commit -m "Release ${apptype}/${newRelease}"`, wtAppPath); - runCmd( - `git push origin --delete "${branchName}" || git push origin "${branchName}"`, - wtAppPath - ); - runCmd(`git push --set-upstream origin "${branchName}"`, wtAppPath); - - // go back to master - runCmd(`rmdir /S /Q wt-app`); - runCmd(`git worktree prune`); -} function usageAndExit() { console.log(`Usage: node ${process.argv[1]} [both|cpp|cs|mac]`); @@ -88,99 +15,17 @@ function usageAndExit() { process.exit(1); } -let releasesWindows; -let releasesMac; -const releasesFileWindows = path.resolve(__dirname, "RELEASES"); -const releasesFileMac = path.resolve(__dirname, "RELEASES_MAC"); - -/** - * @param {boolean} [isMac] - get Mac releases instead of windows - */ -function getReleases(isMac) { - if (!isMac) { - if (!releasesWindows) { - releasesWindows = readFileSync(releasesFileWindows) - .toString() - .split("\n") - .map((_) => _.trim()); - } - - return releasesWindows; - } else { - if (!releasesMac) { - releasesMac = readFileSync(releasesFileMac) - .toString() - .split("\n") - .map((_) => _.trim()); - } - - return releasesMac; - } -} - -/** - * @param {string} [rnwVersion] - * @param {boolean} [mac] - mac vs windows - */ -function addReleaseToList(rnwVersion, mac) { - getReleases(mac).push(rnwVersion); - if (mac) { - releasesMac = releasesMac - .filter((a) => a) - .sort((a, b) => 0 - semver.compare(a, b)); - writeFileSync(releasesFileMac, releasesMac.join("\n")); - } else { - releasesWindows = releasesWindows - .filter((a) => a) - .sort((a, b) => 0 - semver.compare(a, b)); - writeFileSync(releasesFileWindows, releasesWindows.join("\n")); - } -} - /** * @param {string} [rnwVersion] * @param {boolean} [mac] - mac vs windows */ function guardExisting(rnwVersion, mac) { - if (getReleases(mac).indexOf(rnwVersion) >= 0) { + if (versionAlreadyExists(rnwVersion, mac)) { console.error(`Already generated diff for ${rnwVersion}`); process.exit(0); } } -/** - * @param {string} [rnwVersion] - * @param {'cs' | 'cpp' | 'mac'} [apptype] - */ -function generateDiffs(rnwVersion, apptype) { - const wtDiffsDir = path.resolve(__dirname, "wt-diffs"); - - if (!existsSync("wt-diffs")) { - runCmd("git worktree add wt-diffs diffs"); - } - - runCmd("git pull", wtDiffsDir); - - if (!existsSync(path.resolve(wtDiffsDir, `diffs/${apptype}`))) { - mkdirSync(path.resolve(wtDiffsDir, `diffs/${apptype}`)); - } - - for (let existingRelease of getReleases(apptype === 'mac')) { - console.log("processing " + existingRelease); - if (existingRelease === rnwVersion) continue; - runCmd( - `git diff --binary origin/release/${apptype}/"${existingRelease}"..origin/release/${apptype}/"${rnwVersion}" > wt-diffs/diffs/${apptype}/"${existingRelease}".."${rnwVersion}".diff` - ); - runCmd( - `git diff --binary origin/release/${apptype}/"${rnwVersion}"..origin/release/${apptype}/"${existingRelease}" > wt-diffs/diffs/${apptype}/"${rnwVersion}".."${existingRelease}".diff` - ); - } - - runCmd("git add .", wtDiffsDir); - runCmd(`git commit -m "Add release ${rnwVersion} ${apptype} diffs"`, wtDiffsDir); - runCmd("git push", wtDiffsDir); -} - function run() { if (process.argv.length < 3) { usageAndExit(); diff --git a/wt-diffs b/wt-diffs new file mode 160000 index 00000000000..349762ca217 --- /dev/null +++ b/wt-diffs @@ -0,0 +1 @@ +Subproject commit 349762ca217fe59fc1128144dc63cfd75a605d63