Allow git describe formatted versions of node packs in workflows (#3518)

This commit is contained in:
Christian Byrne
2025-04-20 09:42:01 +08:00
committed by GitHub
parent 8afe99f48c
commit 6be381b15d
3 changed files with 35 additions and 6 deletions

View File

@@ -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,

View File

@@ -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({

View File

@@ -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))