Skip to content
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
41 changes: 22 additions & 19 deletions packages/app/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ const E2E_TEMP_DIR_PREFIX = "pkg-pr-new-e2e-";

let server: Awaited<ReturnType<ReturnType<typeof simulation>["listen"]>>;
let workerUrl: string;
let githubOutputDir: string;
let tempDir: string;
let githubOutputPath: string;

let worker: UnstableDevWorker;

const { stdout: gitRevParseOutput } = await ezSpawn.async(
"git rev-parse HEAD",
{ stdio: "overlapped" },
);
const gitRevParse = gitRevParseOutput.trim();

beforeAll(async () => {
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), E2E_TEMP_DIR_PREFIX));

const app = simulation({
initialState: {
users: [],
Expand Down Expand Up @@ -51,15 +60,12 @@ beforeAll(async () => {
`${import.meta.dirname}/dist/_worker.js/index.js`,
{
config: `${import.meta.dirname}/wrangler.toml`,
persistTo: path.join(tempDir, "worker"),
},
);
const url = `${worker.proxyData.userWorkerUrl.protocol}//${worker.proxyData.userWorkerUrl.hostname}:${worker.proxyData.userWorkerUrl.port}`;
workerUrl = url;

githubOutputDir = await fs.mkdtemp(
path.join(os.tmpdir(), E2E_TEMP_DIR_PREFIX),
);
githubOutputPath = path.join(githubOutputDir, "output");
githubOutputPath = path.join(tempDir, "output");
await fs.writeFile(githubOutputPath, "");

await ezSpawn.async(
Expand All @@ -74,8 +80,8 @@ beforeAll(async () => {

afterAll(async () => {
await server.ensureClose();
if (githubOutputDir?.includes(E2E_TEMP_DIR_PREFIX)) {
await fs.rm(githubOutputDir, { recursive: true, force: true });
if (tempDir?.includes(E2E_TEMP_DIR_PREFIX)) {
await fs.rm(tempDir, { recursive: true, force: true });
}
});

Expand Down Expand Up @@ -123,6 +129,7 @@ describe.sequential.each([
GITHUB_SHA: payload.workflow_run.head_sha,
GITHUB_ACTION: payload.workflow_run.id,
GITHUB_JOB: payload.workflow_run.name,
GITHUB_EVENT_NAME: payload.workflow_run.event,
GITHUB_REF_NAME: pr
? `${pr.payload.number}/merge`
: payload.workflow_run.head_branch,
Expand All @@ -147,14 +154,12 @@ describe.sequential.each([
expect(process.stderr).toContain("pkg-pr-new:");
expect(process.stderr).toContain("playground-a:");
expect(process.stderr).toContain("playground-b:");
}, 10_000);
}, 20_000);

it(`serves and installs playground-a for ${mode}`, async () => {
const [owner, repo] = payload.repository.full_name.split("/");
const { stdout: gitHeadSha } = await ezSpawn.async("git rev-parse HEAD", {
stdio: "overlapped",
});
const sha = gitHeadSha.trim().substring(0, 7);
const fullSha = pr ? payload.workflow_run.head_sha : gitRevParse;
const sha = fullSha.substring(0, 7);
const ref = pr?.payload.number ?? payload.workflow_run.head_branch;

// Test download with SHA
Expand Down Expand Up @@ -190,14 +195,12 @@ describe.sequential.each([
expect(installProcess.stdout).toContain(
"playground-a installed successfully!",
);
}, 10_000);
}, 20_000);

it(`serves and installs playground-b for ${mode}`, async () => {
const [owner, repo] = payload.repository.full_name.split("/");
const { stdout: gitHeadSha } = await ezSpawn.async("git rev-parse HEAD", {
stdio: "overlapped",
});
const sha = gitHeadSha.trim().substring(0, 7);
const fullSha = pr ? payload.workflow_run.head_sha : gitRevParse;
const sha = fullSha.substring(0, 7);

// Test download
const response = await worker.fetch(
Expand Down Expand Up @@ -225,7 +228,7 @@ describe.sequential.each([
expect(installProcess.stdout).toContain(
"playground-b installed successfully!",
);
}, 10_000);
}, 20_000);
});

describe("URL redirects", () => {
Expand Down
25 changes: 18 additions & 7 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,24 @@ const main = defineCommand({
process.exit(1);
}

const { stdout: gitShaOutput } = await ezSpawn.async(
"git rev-parse HEAD",
{
stdio: "overlapped",
},
);
const sha = gitShaOutput.trim();
let { sha } = await checkResponse.json();

// on pull_request events, GitHub creates a virtual merge commit that doesn't
// actually belong to the PR, so we use the workflow's head_sha instead
if (process.env.GITHUB_EVENT_NAME !== "pull_request") {
try {
const { stdout: gitRevParseOutput } = await ezSpawn.async(
"git rev-parse HEAD",
{ stdio: "overlapped" },
);

sha = gitRevParseOutput.trim();
} catch {
// git rev-parse fails when the CLI runs outside a git repository
// (e.g. the checkout was done in a separate job and only artifacts were restored here)
// falling back to the workflow's head_sha from checkResponse
}
}

const deps: Map<string, string> = new Map(); // pkg.pr.new versions of the package
const realDeps: Map<string, string> | null = isPeerDepsEnabled
Expand Down
Loading