diff --git a/.env b/.env index 99f7962..8c5a4bf 100644 --- a/.env +++ b/.env @@ -4,7 +4,7 @@ FORK_OWNER="ComfyNodePRs" FORK_PREFIX="PR-" -DASHBOARD_ISSUE_URL="https://github.com/drip-art/Comfy-Registry-PR/issues/1" +DASHBOARD_ISSUE_URL="https://github.com/Comfy-Org/Comfy-PR/issues/1" DASHBOARD_ISSUE_USER__IS='snomiao' GIT_USERNAME=snomiao diff --git a/src/GIT_USEREMAIL.ts b/src/GIT_USEREMAIL.ts deleted file mode 100644 index 8578e5d..0000000 --- a/src/GIT_USEREMAIL.ts +++ /dev/null @@ -1,5 +0,0 @@ -import DIE from "@snomiao/die"; -import { ghUser } from "./ghUser"; - -export const GIT_USEREMAIL = - process.env.GIT_USEREMAIL || (ghUser.email && ghUser.email) || DIE("Missing env.GIT_USEREMAIL"); diff --git a/src/GIT_USERNAME.ts b/src/GIT_USERNAME.ts deleted file mode 100644 index 39948f1..0000000 --- a/src/GIT_USERNAME.ts +++ /dev/null @@ -1,9 +0,0 @@ -import DIE from "@snomiao/die"; -import { GIT_USEREMAIL } from "./GIT_USEREMAIL"; -import { ghUser } from "./ghUser"; - -export const GIT_USERNAME = - process.env.GIT_USERNAME || (ghUser.email && ghUser.name) || DIE("Missing env.GIT_USERNAME"); - -// read env/parameters -console.log(`GIT COMMIT USER: ${GIT_USERNAME} <${GIT_USEREMAIL}>`); diff --git a/src/clone_modify_push_Branches.ts b/src/clone_modify_push_Branches.ts index 17d4e18..1e45897 100644 --- a/src/clone_modify_push_Branches.ts +++ b/src/clone_modify_push_Branches.ts @@ -2,14 +2,9 @@ import { makePublishcrBranch } from "./makePublishBranch"; import { makePyprojectBranch } from "./makeTomlBranch"; export async function clone_modify_push_Branches(upstreamUrl: string, forkUrl: string) { - return ( - await Promise.all([ - makePyprojectBranch(upstreamUrl, forkUrl), - makePublishcrBranch(upstreamUrl, forkUrl), - // makeLicenseUpdateBranch(upstreamUrl, forkUrl), - ]) - ) - .flatMap((e) => (e ? [e] : [])) + const pyprojectBranchInfo = makePyprojectBranch(upstreamUrl, forkUrl); + const publishcrBranchInfo = makePublishcrBranch(upstreamUrl, forkUrl); + return (await Promise.all([pyprojectBranchInfo, publishcrBranchInfo])) .map(({ body, branch, title, type }) => ({ body, branch, diff --git a/src/createComfyRegistryPullRequests.ts b/src/createComfyRegistryPullRequests.ts index 1ca8173..8f79f5e 100644 --- a/src/createComfyRegistryPullRequests.ts +++ b/src/createComfyRegistryPullRequests.ts @@ -1,15 +1,19 @@ import pMap from "p-map"; -// import { chalk } from "zx"; import { clone_modify_push_Branches } from "./clone_modify_push_Branches"; import { createGithubForkForRepo } from "./createGithubForkForRepo"; import { createGithubPullRequest } from "./createGithubPullRequest"; import type { GithubPull } from "./gh/GithubPull"; -import { makeUpdateTomlLicenseBranch } from "./makeUpdateTomlLicenseBranch"; import { parsePulls } from "./parsePullsState"; - +if (import.meta.main) { + // test repo + const test_repo = "https://github.com/snomiao/ComfyNode-Registry-test"; + console.info(await createComfyRegistryPullRequests(test_repo)); +} export async function createComfyRegistryPullRequests(upstreamRepoUrl: string) { + console.log("forking " + upstreamRepoUrl); const forkedRepo = await createGithubForkForRepo(upstreamRepoUrl); + console.log("modifing " + forkedRepo.html_url); const PR_REQUESTS = await clone_modify_push_Branches(upstreamRepoUrl, forkedRepo.html_url); const prs = await pMap(PR_REQUESTS, async ({ type, ...prInfo }) => await createGithubPullRequest({ ...prInfo })); @@ -17,16 +21,3 @@ export async function createComfyRegistryPullRequests(upstreamRepoUrl: string) { return ([...prs] as GithubPull[]).map((e) => parsePulls([e])[0]); } - -export async function clone_modify_push_Branches_for_updateTomlLicense(upstreamUrl: string, forkUrl: string) { - return (await Promise.all([makeUpdateTomlLicenseBranch(upstreamUrl, forkUrl)])) - .flatMap((e) => (e ? [e] : [])) - .map(({ body, branch, title, type }) => ({ - body, - branch, - title, - type, - srcUrl: forkUrl, - dstUrl: upstreamUrl, - })); -} diff --git a/src/ghUser.ts b/src/ghUser.ts index b5e9d86..6506c39 100644 --- a/src/ghUser.ts +++ b/src/ghUser.ts @@ -1,9 +1,24 @@ import type { Task } from "@/packages/mongodb-pipeline-ts/Task"; +import DIE from "@snomiao/die"; import { gh } from "./gh"; import type { AwaitedReturnType } from "./types/AwaitedReturnType"; -export const ghUser = (await gh.users.getAuthenticated()).data; +export const ghUser = ( + await gh.users.getAuthenticated().catch((error) => { + throw new Error( + `FAIL TO GET AUTHENTICATED USER INFO, CHECK ${!!process.env.GH_TOKEN ? "[?]" : "[ ]"}GH_TOKEN and ${!!process.env.GH_TOKEN_COMFY_PR ? "[?]" : "[ ]"}GH_TOKEN_COMFY_PR`, + { cause: error }, + ); + }) +).data; console.log("Fetch Current Github User..."); -console.log(`Current Github User: ${ghUser.login} <${ghUser.email}>`); +console.log(`GH_TOKEN User: ${ghUser.login} <${ghUser.email}>`); export type GHUser = Task["data"]>; +export const GIT_USEREMAIL = + process.env.GIT_USEREMAIL || (ghUser.email && ghUser.email) || DIE("Missing env.GIT_USEREMAIL"); +export const GIT_USERNAME = + process.env.GIT_USERNAME || (ghUser.email && ghUser.name) || DIE("Missing env.GIT_USERNAME"); + +// read env/parameters +console.log(`GIT COMMIT USER: ${GIT_USERNAME} <${GIT_USEREMAIL}>`); diff --git a/src/makePublishBranch.ts b/src/makePublishBranch.ts index ab56505..b39418d 100644 --- a/src/makePublishBranch.ts +++ b/src/makePublishBranch.ts @@ -1,10 +1,9 @@ import { readFile } from "fs/promises"; import { dirname } from "path"; -import { GIT_USEREMAIL } from "./GIT_USEREMAIL"; -import { GIT_USERNAME } from "./GIT_USERNAME"; import { $ } from "./cli/echoBunShell"; import { getBranchWorkingDir } from "./getBranchWorkingDir"; import { gh } from "./gh"; +import { GIT_USEREMAIL, GIT_USERNAME } from "./ghUser"; import { parseUrlRepoOwner, stringifyGithubOrigin, stringifyGithubRepoUrl } from "./parseOwnerRepo"; import { parseTitleBodyOfMarkdown } from "./parseTitleBodyOfMarkdown"; @@ -31,16 +30,18 @@ export async function makePublishcrBranch(upstreamUrl: string, forkUrl: Readonly } const cwd = await getBranchWorkingDir(upstreamUrl, forkUrl, branch); - + const upsreamOwner = parseUrlRepoOwner(upstreamUrl).owner; const file = `${cwd}/.github/workflows/publish.yml`; const publishYmlPath = "./templates/publish.yaml"; - + const publishYmlTemplate = await readFile(publishYmlPath, "utf8"); + const repalcedContent = publishYmlTemplate.replace("NODE_AUTHOR_OWNER", upsreamOwner); + if (publishYmlTemplate === repalcedContent) throw new Error("fail to replace NODE_AUTHOR_OWNER"); // commit & push changes await $` git clone ${upstreamUrl} ${cwd} mkdir -p ${dirname(file)} -cat ${publishYmlPath} > ${file} +echo "${repalcedContent}" > ${file} cd ${cwd} @@ -50,7 +51,7 @@ git checkout -b ${branch} && \ git add . && \ git commit -am "chore(${branch}): ${title}" && \ git push "${origin}" ${branch}:${branch} - `; +`; const branchUrl = `${stringifyGithubRepoUrl(repo)}/tree/${branch}`; console.log(`Branch Push OK: ${branchUrl}`); diff --git a/src/makeTomlBranch.ts b/src/makeTomlBranch.ts index 8dbbb91..ae7c36a 100644 --- a/src/makeTomlBranch.ts +++ b/src/makeTomlBranch.ts @@ -1,9 +1,8 @@ import { readFile } from "fs/promises"; -import { GIT_USEREMAIL } from "./GIT_USEREMAIL"; -import { GIT_USERNAME } from "./GIT_USERNAME"; import { $ } from "./cli/echoBunShell"; import { getBranchWorkingDir } from "./getBranchWorkingDir"; import { gh } from "./gh"; +import { GIT_USEREMAIL, GIT_USERNAME } from "./ghUser"; import { parseUrlRepoOwner, stringifyGithubOrigin } from "./parseOwnerRepo"; import { parseTitleBodyOfMarkdown } from "./parseTitleBodyOfMarkdown"; import { tomlFillDescription } from "./tomlFillDescription"; diff --git a/src/makeUpdateTomlLicenseBranch.ts b/src/makeUpdateTomlLicenseBranch.ts index 5e6bd90..f7323b3 100644 --- a/src/makeUpdateTomlLicenseBranch.ts +++ b/src/makeUpdateTomlLicenseBranch.ts @@ -6,17 +6,16 @@ import { readFile } from "fs/promises"; import type { WithId } from "mongodb"; import { basename, dirname } from "path"; import sflow, { nil } from "sflow"; -import { CNRepos } from "./CNRepos"; -import { GIT_USEREMAIL } from "./GIT_USEREMAIL"; -import { GIT_USERNAME } from "./GIT_USERNAME"; import { isRepoBypassed } from "./bypassRepos"; import { $ } from "./cli/echoBunShell"; +import { CNRepos } from "./CNRepos"; import { createGithubForkForRepo } from "./createGithubForkForRepo"; import { createGithubPullRequest } from "./createGithubPullRequest"; import { $filaten, $stale, db } from "./db"; import { getBranchWorkingDir } from "./getBranchWorkingDir"; import { gh } from "./gh"; import type { GithubPull } from "./gh/GithubPull"; +import { GIT_USEREMAIL, GIT_USERNAME } from "./ghUser"; import { parseUrlRepoOwner, stringifyGithubOrigin } from "./parseOwnerRepo"; import { parseTitleBodyOfMarkdown } from "./parseTitleBodyOfMarkdown"; diff --git a/templates/outdated/publish-v2.yaml b/templates/outdated/publish-v2.yaml new file mode 100644 index 0000000..7c8c686 --- /dev/null +++ b/templates/outdated/publish-v2.yaml @@ -0,0 +1,26 @@ +name: Publish to Comfy registry +on: + workflow_dispatch: + push: + branches: + - main + - master + paths: + - "pyproject.toml" + +jobs: + publish-node: + name: Publish Custom Node to registry + runs-on: ubuntu-latest + # if this is a forked repository. Skipping the workflow. + if: github.event.repository.fork == false + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + submodules: true + - name: Publish Custom Node + uses: Comfy-Org/publish-node-action@main + with: + ## Add your own personal access token to your Github Repository secrets and reference it here. + personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }} diff --git a/templates/publish.yaml b/templates/publish.yaml index 7c8c686..1318f3e 100644 --- a/templates/publish.yaml +++ b/templates/publish.yaml @@ -12,8 +12,7 @@ jobs: publish-node: name: Publish Custom Node to registry runs-on: ubuntu-latest - # if this is a forked repository. Skipping the workflow. - if: github.event.repository.fork == false + if: ${{ github.repository_owner == 'NODE_AUTHOR_OWNER' }} steps: - name: Check out code uses: actions/checkout@v4