Skip to content

Commit 6be381b

Browse files
Allow git describe formatted versions of node packs in workflows (#3518)
1 parent 8afe99f commit 6be381b

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/composables/nodePack/useWorkflowPacks.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export const useWorkflowPacks = (options: UseNodePacksOptions = {}) => {
3636
return undefined
3737
}
3838

39+
/**
40+
* Clean the version string to be used in the registry search.
41+
* Removes the leading 'v' and trims whitespace and line terminators.
42+
*/
43+
const cleanVersionString = (version: string) =>
44+
version.replace(/^v/, '').trim()
45+
3946
/**
4047
* Infer the pack for a node by searching the registry for packs that have nodes
4148
* with the same name.
@@ -70,7 +77,9 @@ export const useWorkflowPacks = (options: UseNodePacksOptions = {}) => {
7077
if (packId === CORE_NODES_PACK_NAME) return undefined
7178

7279
const version =
73-
typeof node.properties.ver === 'string' ? node.properties.ver : undefined
80+
typeof node.properties.ver === 'string'
81+
? cleanVersionString(node.properties.ver)
82+
: undefined
7483

7584
return {
7685
id: packId,

src/schemas/comfyWorkflowSchema.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,29 @@ const zAuxId = z
160160
)
161161
.transform(([username, repo]) => `${username}/${repo}`)
162162

163-
const zSemVer = z.union([
164-
z.string().regex(semverPattern, 'Invalid semantic version (x.y.z)'),
163+
const zGitHash = z.string().superRefine((val: string, ctx) => {
164+
if (!gitHashPattern.test(val)) {
165+
ctx.addIssue({
166+
code: z.ZodIssueCode.custom,
167+
message: `Node pack version has invalid Git commit hash: "${val}"`
168+
})
169+
}
170+
})
171+
const zSemVer = z.string().superRefine((val: string, ctx) => {
172+
if (!semverPattern.test(val)) {
173+
ctx.addIssue({
174+
code: z.ZodIssueCode.custom,
175+
message: `Node pack version has invalid semantic version: "${val}"`
176+
})
177+
}
178+
})
179+
const zVersion = z.union([
180+
z
181+
.string()
182+
.transform((ver) => ver.replace(/^v/, '')) // Strip leading 'v'
183+
.pipe(z.union([zSemVer, zGitHash])),
165184
z.literal('unknown')
166185
])
167-
const zGitHash = z.string().regex(gitHashPattern, 'Invalid Git commit hash')
168-
const zVersion = z.union([zSemVer, zGitHash])
169186

170187
const zProperties = z
171188
.object({

tests-ui/tests/comfyWorkflow.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ describe('parseComfyWorkflow', () => {
178178
// Git hash
179179
'080e6d4af809a46852d1c4b7ed85f06e8a3a72be',
180180
// Special case
181-
'unknown'
181+
'unknown',
182+
// Git describe
183+
'v0.3.9-7-g1419dee',
184+
'v0.3.9-7-g1419dee-dirty'
182185
]
183186
it.each(validVersionStrings)('valid version: %s', async (ver) => {
184187
const workflow = JSON.parse(JSON.stringify(defaultGraph))

0 commit comments

Comments
 (0)