diff --git a/README.md b/README.md index c1799e45..e4984d4e 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ pkg.pr.new uses `npm pack --json` under the hood, in case you face issues, you c -pkg.pr.new is not available in your local environment and it only works in workflows. +pkg.pr.new is not available in your local environment and it only works in workflows since it is not a js registry. ### Examples diff --git a/e2e/publish.test.mts b/e2e/publish.test.mts index 50eeac9c..c313166f 100644 --- a/e2e/publish.test.mts +++ b/e2e/publish.test.mts @@ -72,6 +72,7 @@ for (const [{ payload }, pr] of [ GITHUB_ACTOR_ID: payload.sender.id, GITHUB_SHA: payload.workflow_job.head_sha, GITHUB_ACTION: payload.workflow_job.id, + GITHUB_JOB: payload.workflow_job.name, GITHUB_REF_NAME: pr ? `${pr.payload.number}/merge` : payload.workflow_job.head_branch, diff --git a/packages/backend/server/routes/webhook.post.ts b/packages/backend/server/routes/webhook.post.ts index 16dc019e..8fa2d2bc 100644 --- a/packages/backend/server/routes/webhook.post.ts +++ b/packages/backend/server/routes/webhook.post.ts @@ -9,6 +9,8 @@ const prMarkEvents: PullRequestEvent["action"][] = [ "opened", "reopened", "synchronize", + "enqueued", + "dequeued", ]; export default eventHandler(async (event) => { @@ -25,12 +27,19 @@ export default eventHandler(async (event) => { const [owner, repo] = payload.repository.full_name.split("/"); const metadata = { - url: payload.workflow_job.html_url.split("/job/")[0], // run url: (https://github.com/stackblitz-labs/pkg.pr.new/actions/runs/8390507718)/job/23004786296 + owner, + repo, + job: payload.workflow_job.name, + runId: payload.workflow_job.run_id, attempt: payload.workflow_job.run_attempt, actor: payload.sender.id, }; const hashKey = hash(metadata); - if (payload.action === "queued") { + + if (payload.action === "completed") { + // Publishing is not available anymore + await workflowsBucket.removeItem(hashKey); + } else { const prData: PullRequestData = { owner, repo, @@ -52,9 +61,6 @@ export default eventHandler(async (event) => { // Publishing is only available throughout the lifetime of a workflow_job await workflowsBucket.setItem(hashKey, data); - } else if (payload.action === "completed") { - // Publishing is not available anymore - await workflowsBucket.removeItem(hashKey); } }; @@ -71,7 +77,6 @@ export default eventHandler(async (event) => { const prDataHash = hash(key); if (prMarkEvents.includes(payload.action)) { await pullRequestNumbersBucket.setItem(prDataHash, payload.number); - // TODO: send comment here if the workflow was run before (for in repo pull requests) } else if (payload.action === "closed") { await pullRequestNumbersBucket.removeItem(prDataHash); diff --git a/packages/cli/environments.ts b/packages/cli/environments.ts index 16603f4b..b8ef1a06 100644 --- a/packages/cli/environments.ts +++ b/packages/cli/environments.ts @@ -25,6 +25,8 @@ declare global { GITHUB_EVENT_PATH: string; // A unique number for each workflow run within a repository. This number does not change if you re-run the workflow run. For example, 1658821493. GITHUB_RUN_ID: string; + // The job_id of the current job. For example, greeting_job. + GITHUB_JOB: string; // A unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run. For example, 3. GITHUB_RUN_ATTEMPT: string; } diff --git a/packages/cli/index.ts b/packages/cli/index.ts index b41df44d..f1949b80 100644 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -1,4 +1,4 @@ -import { defineCommand, runMain, parseArgs } from "citty"; +import { defineCommand, runMain } from "citty"; import assert from "node:assert"; import path from "path"; import ezSpawn from "@jsdevtools/ez-spawn"; @@ -71,28 +71,32 @@ const main = defineCommand({ ); process.exit(1); } - const octokit = new Octokit(); + + new Octokit(); // gh authentication const { - GITHUB_SERVER_URL, GITHUB_REPOSITORY, GITHUB_RUN_ID, GITHUB_RUN_ATTEMPT, GITHUB_ACTOR_ID, + GITHUB_JOB } = process.env; const [owner, repo] = GITHUB_REPOSITORY.split("/"); - // Note: If you need to use a workflow run's URL from within a job, you can combine these variables: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID - const url = `${GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${GITHUB_RUN_ID}`; - const metadata = { - url, + owner, + repo, + job: GITHUB_JOB, + runId: Number(GITHUB_RUN_ID), attempt: Number(GITHUB_RUN_ATTEMPT), actor: Number(GITHUB_ACTOR_ID), }; + console.log('metadata', metadata) + console.log(process.env) const key = hash(metadata); + console.log('key', key) const checkResponse = await fetch(new URL("/check", API_URL), { method: "POST",