Skip to content

switch e2e tests to use corepack #1632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2022
Merged
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
20 changes: 19 additions & 1 deletion .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,25 @@ jobs:
cache: pnpm

- name: Install dependencies
run: pnpm install
# corepack 0.10 has a race condition in it that can cause the inital
# package manger installs to fail.
# Once we update to a version of node that ships with corepack 0.12 or
# higher we can remove the second install command.
# Windows installs global packages to a directory that has lower priority than
# the default node install so we also need to edit $PATH
shell: bash
run: |
pnpm install;
if [ "$RUNNER_OS" == "Windows" ]; then
npm install --force --global corepack@latest
npm config get prefix >> $GITHUB_PATH
else
npm install --global corepack@latest
fi


- name: Debug CI @donotmerge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this will be taken out. I've been resorting to print debugging for some issues that only show up on Windows CI 🙃

run: which -a corepack; echo $PATH; corepack -v

- name: Build & Unit Test
run: pnpm -- turbo run test --filter=cli --color
Expand Down
16 changes: 14 additions & 2 deletions cli/scripts/e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const basicPipeline = {
// This is injected by github actions
process.env.TURBO_TOKEN = "";

const COREPACK_BIN_DIR = setupCorepack();

let suites = [];
for (let npmClient of ["yarn", "berry", "pnpm", "npm"] as const) {
const Suite = uvu.suite(`${npmClient}`);
const repo = new Monorepo("basics");
const repo = new Monorepo("basics", COREPACK_BIN_DIR);
repo.init(npmClient, basicPipeline);
repo.install();
repo.addPackage("a", ["b"]);
Expand All @@ -48,7 +50,7 @@ for (let npmClient of ["yarn", "berry", "pnpm", "npm"] as const) {
repo.linkPackages();
repo.expectCleanGitStatus();
runSmokeTests(Suite, repo, npmClient);
const sub = new Monorepo("in-subdirectory");
const sub = new Monorepo("in-subdirectory", COREPACK_BIN_DIR);
sub.init(npmClient, basicPipeline, "js");
sub.install();
sub.addPackage("a", ["b"]);
Expand Down Expand Up @@ -590,3 +592,13 @@ function getCachedLogFilePathForTask(
): string {
return path.join(cacheDir, pathToPackage, ".turbo", `turbo-${taskName}.log`);
}

// Setup corepack and provide the dir to the binaries that corepack installs
// It is important that this dir has a higher priority in $PATH than any other
// dirs that may versions of package managers installed by other mechanisms
// e.g. homebrew or pnpm
function setupCorepack(): string {
execa.sync("corepack", ["enable"]);
const corepack_path = execa.sync("which", ["corepack"]).stdout;
return path.dirname(corepack_path);
}
21 changes: 17 additions & 4 deletions cli/scripts/monorepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Monorepo {
static tmpdir = os.tmpdir();
static yarnCache = path.join(__dirname, "yarn-cache-");
root: string;
corepackDir?: string;
subdir?: string;
name: string;
npmClient: NPMClient;
Expand All @@ -21,9 +22,16 @@ export class Monorepo {
? path.join(this.root, this.subdir, "node_modules")
: path.join(this.root, "node_modules");
}
get binPath() {
const path_delimiter = process.platform == "win32" ? ";" : ":";
return this.corepackDir
? `${this.corepackDir}${path_delimiter}${process.env.PATH}`
: process.env.PATH;
}

constructor(name) {
constructor(name: string, corepackDir?: string) {
this.root = fs.mkdtempSync(path.join(__dirname, `turbo-monorepo-${name}-`));
this.corepackDir = corepackDir;
}

init(npmClient: NPMClient, turboConfig = {}, subdir?: string) {
Expand Down Expand Up @@ -116,12 +124,14 @@ importers:
});
execa.sync("pnpm", ["install", "--recursive"], {
cwd,
env: { PATH: this.binPath },
});
return;
}
if (this.npmClient == "npm") {
execa.sync("npm", ["install"], {
cwd,
env: { PATH: this.binPath },
});
this.commitAll();
return;
Expand Down Expand Up @@ -154,13 +164,11 @@ importers:
this.commitFiles({ "yarn.lock": yarnYaml });

if (this.npmClient == "berry") {
execa.sync("yarn", ["set", "version", "stable"], {
cwd,
});
execa.sync("yarn", ["install"], {
cwd,
env: {
YARN_ENABLE_IMMUTABLE_INSTALLS: "false",
PATH: this.binPath,
},
});
this.commitAll();
Expand Down Expand Up @@ -323,6 +331,7 @@ fs.copyFileSync(
return execa.sync(turboPath, [command, ...resolvedArgs], {
cwd: this.root,
shell: true,
env: { PATH: this.binPath },
...options,
});
}
Expand All @@ -333,24 +342,28 @@ fs.copyFileSync(
return execa.sync("yarn", [command, ...(args || [])], {
cwd: this.root,
shell: true,
env: { PATH: this.binPath },
...options,
});
case "berry":
return execa.sync("yarn", [command, ...(args || [])], {
cwd: this.root,
shell: true,
env: { PATH: this.binPath },
...options,
});
case "pnpm":
return execa.sync("pnpm", [command, ...(args || [])], {
cwd: this.root,
shell: true,
env: { PATH: this.binPath },
...options,
});
case "npm":
return execa.sync("npm", ["run", command, ...(args || [])], {
cwd: this.root,
shell: true,
env: { PATH: this.binPath },
...options,
});
default:
Expand Down