diff --git a/packages/@rnw-scripts/prepare-release/src/beachballBump.ts b/packages/@rnw-scripts/prepare-release/src/beachballBump.ts index 8658d308d5e..23dcbb0655f 100644 --- a/packages/@rnw-scripts/prepare-release/src/beachballBump.ts +++ b/packages/@rnw-scripts/prepare-release/src/beachballBump.ts @@ -47,3 +47,19 @@ export async function bumpVersions(opts: { {cwd: opts.cwd}, ); } + +/** + * Regenerate yarn.lock so it matches the versions beachball just bumped. + * + * beachball rewrites package.json/changelogs but never touches the lockfile, so + * without this the lockfile drifts and every downstream `yarn install + * --immutable` fails with YN0028. `--mode=update-lockfile` refreshes the + * lockfile without touching node_modules; immutable installs are on by default + * under CI, so disable that for this one call. + */ +export async function updateLockfile(opts: {cwd: string}): Promise { + await exec('yarn install --mode=update-lockfile', { + cwd: opts.cwd, + env: {YARN_ENABLE_IMMUTABLE_INSTALLS: 'false'}, + }); +} diff --git a/packages/@rnw-scripts/prepare-release/src/prepareRelease.ts b/packages/@rnw-scripts/prepare-release/src/prepareRelease.ts index 3056f061de0..765f0875429 100644 --- a/packages/@rnw-scripts/prepare-release/src/prepareRelease.ts +++ b/packages/@rnw-scripts/prepare-release/src/prepareRelease.ts @@ -20,7 +20,7 @@ import findRepoRoot from '@react-native-windows/find-repo-root'; import {GitRepo} from './git'; import {findPR, createPR, updatePR} from './github'; -import {hasChangeFiles, bumpVersions} from './beachballBump'; +import {hasChangeFiles, bumpVersions, updateLockfile} from './beachballBump'; import { collectBumpedPackages, generatePRBody, @@ -288,6 +288,11 @@ async function detectRemote(git: GitRepo, repoUrl: string): Promise { cwd: repoRoot, }); + // 10b. Refresh yarn.lock to match the bumped versions so the release + // commit stays installable under `yarn install --immutable`. + console.log(colorize('Updating yarn.lock...', ansi.bright)); + await updateLockfile({cwd: repoRoot}); + // 11. Check if beachball actually changed anything const status = await git.statusPorcelain(); if (!status) {