From 6be381b15de5f732c04db7e855a2ef0a5eb0d464 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 20 Apr 2025 09:42:01 +0800 Subject: [PATCH] Allow `git describe` formatted versions of node packs in workflows (#3518) --- src/composables/nodePack/useWorkflowPacks.ts | 11 ++++++++- src/schemas/comfyWorkflowSchema.ts | 25 ++++++++++++++++---- tests-ui/tests/comfyWorkflow.test.ts | 5 +++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/composables/nodePack/useWorkflowPacks.ts b/src/composables/nodePack/useWorkflowPacks.ts index 959b527a7..27bbbbf30 100644 --- a/src/composables/nodePack/useWorkflowPacks.ts +++ b/src/composables/nodePack/useWorkflowPacks.ts @@ -36,6 +36,13 @@ export const useWorkflowPacks = (options: UseNodePacksOptions = {}) => { return undefined } + /** + * Clean the version string to be used in the registry search. + * Removes the leading 'v' and trims whitespace and line terminators. + */ + const cleanVersionString = (version: string) => + version.replace(/^v/, '').trim() + /** * Infer the pack for a node by searching the registry for packs that have nodes * with the same name. @@ -70,7 +77,9 @@ export const useWorkflowPacks = (options: UseNodePacksOptions = {}) => { if (packId === CORE_NODES_PACK_NAME) return undefined const version = - typeof node.properties.ver === 'string' ? node.properties.ver : undefined + typeof node.properties.ver === 'string' + ? cleanVersionString(node.properties.ver) + : undefined return { id: packId, diff --git a/src/schemas/comfyWorkflowSchema.ts b/src/schemas/comfyWorkflowSchema.ts index 74f7c7a8d..9d7bebe23 100644 --- a/src/schemas/comfyWorkflowSchema.ts +++ b/src/schemas/comfyWorkflowSchema.ts @@ -160,12 +160,29 @@ const zAuxId = z ) .transform(([username, repo]) => `${username}/${repo}`) -const zSemVer = z.union([ - z.string().regex(semverPattern, 'Invalid semantic version (x.y.z)'), +const zGitHash = z.string().superRefine((val: string, ctx) => { + if (!gitHashPattern.test(val)) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: `Node pack version has invalid Git commit hash: "${val}"` + }) + } +}) +const zSemVer = z.string().superRefine((val: string, ctx) => { + if (!semverPattern.test(val)) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: `Node pack version has invalid semantic version: "${val}"` + }) + } +}) +const zVersion = z.union([ + z + .string() + .transform((ver) => ver.replace(/^v/, '')) // Strip leading 'v' + .pipe(z.union([zSemVer, zGitHash])), z.literal('unknown') ]) -const zGitHash = z.string().regex(gitHashPattern, 'Invalid Git commit hash') -const zVersion = z.union([zSemVer, zGitHash]) const zProperties = z .object({ diff --git a/tests-ui/tests/comfyWorkflow.test.ts b/tests-ui/tests/comfyWorkflow.test.ts index dd17d14ae..ad40a3f1e 100644 --- a/tests-ui/tests/comfyWorkflow.test.ts +++ b/tests-ui/tests/comfyWorkflow.test.ts @@ -178,7 +178,10 @@ describe('parseComfyWorkflow', () => { // Git hash '080e6d4af809a46852d1c4b7ed85f06e8a3a72be', // Special case - 'unknown' + 'unknown', + // Git describe + 'v0.3.9-7-g1419dee', + 'v0.3.9-7-g1419dee-dirty' ] it.each(validVersionStrings)('valid version: %s', async (ver) => { const workflow = JSON.parse(JSON.stringify(defaultGraph))