diff --git a/.yarn/versions/d7044db8.yml b/.yarn/versions/d7044db8.yml new file mode 100644 index 000000000000..2d6a48f178d8 --- /dev/null +++ b/.yarn/versions/d7044db8.yml @@ -0,0 +1,34 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/core": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@yarnpkg/plugin-exec" + - "@yarnpkg/plugin-file" + - "@yarnpkg/plugin-git" + - "@yarnpkg/plugin-github" + - "@yarnpkg/plugin-http" + - "@yarnpkg/plugin-init" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-link" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm" + - "@yarnpkg/plugin-npm-cli" + - "@yarnpkg/plugin-pack" + - "@yarnpkg/plugin-patch" + - "@yarnpkg/plugin-pnp" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-stage" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/plugin-version" + - "@yarnpkg/plugin-workspace-tools" + - "@yarnpkg/builder" + - "@yarnpkg/doctor" + - "@yarnpkg/extensions" + - "@yarnpkg/nm" + - "@yarnpkg/pnpify" + - "@yarnpkg/sdks" diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/install.test.ts b/packages/acceptance-tests/pkg-tests-specs/sources/commands/install.test.ts index 36fb175c4fa4..e97d7d862d07 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/install.test.ts +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/install.test.ts @@ -187,7 +187,6 @@ describe(`Commands`, () => { }), ); - test( `it should not enable --refresh-lockfile --immutable in private PR CIs`, makeTemporaryEnv({ @@ -221,6 +220,65 @@ describe(`Commands`, () => { }), ); + test( + `it should not enable --refresh-lockfile --immutable if the GH environment file is missing`, + makeTemporaryEnv({ + dependencies: { + [`one-fixed-dep`]: `1.0.0`, + }, + }, async ({path, run, source}) => { + await run(`install`); + + const lockfilePath = ppath.join(path, Filename.lockfile); + const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`); + const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`); + await xfs.writeFilePromise(lockfilePath, modifiedLockfile); + + const eventPath = ppath.join(path, `github-event-file.json`); + + await run(`install`); + + await run(`install`, { + env: { + GITHUB_ACTIONS: `true`, + GITHUB_EVENT_NAME: `pull_request`, + GITHUB_EVENT_PATH: npath.fromPortablePath(eventPath), + }, + }); + }), + ); + + test( + `it should not enable --refresh-lockfile --immutable if the GH environment file is weird`, + makeTemporaryEnv({ + dependencies: { + [`one-fixed-dep`]: `1.0.0`, + }, + }, async ({path, run, source}) => { + await run(`install`); + + const lockfilePath = ppath.join(path, Filename.lockfile); + const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`); + const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`); + await xfs.writeFilePromise(lockfilePath, modifiedLockfile); + + const eventPath = ppath.join(path, `github-event-file.json`); + await xfs.writeJsonPromise(eventPath, { + hello: `world`, + }); + + await run(`install`); + + await run(`install`, { + env: { + GITHUB_ACTIONS: `true`, + GITHUB_EVENT_NAME: `pull_request`, + GITHUB_EVENT_PATH: npath.fromPortablePath(eventPath), + }, + }); + }), + ); + test( `it should accept to add files to the cache when using --immutable without --immutable-cache`, makeTemporaryEnv({ diff --git a/packages/yarnpkg-core/sources/Configuration.ts b/packages/yarnpkg-core/sources/Configuration.ts index 2e579a08a16d..40ea4966e819 100644 --- a/packages/yarnpkg-core/sources/Configuration.ts +++ b/packages/yarnpkg-core/sources/Configuration.ts @@ -30,9 +30,18 @@ import * as semverUtils import * as structUtils from './structUtils'; import {IdentHash, Package, Descriptor, PackageExtension, PackageExtensionType, PackageExtensionStatus, Locator} from './types'; -const isPublicRepository = GITHUB_ACTIONS && process.env.GITHUB_EVENT_PATH - ? !(xfs.readJsonSync(npath.toPortablePath(process.env.GITHUB_EVENT_PATH)).repository?.private ?? true) - : false; +const isPublicRepository = (function () { + if (GITHUB_ACTIONS && process.env.GITHUB_EVENT_PATH) { + const githubEventPath = npath.toPortablePath(process.env.GITHUB_EVENT_PATH); + try { + return !(xfs.readJsonSync(githubEventPath).repository?.private ?? true); + } catch (err) { + return false; + } + } + + return false; +})(); export const LEGACY_PLUGINS = new Set([ `@yarnpkg/plugin-constraints`,