Skip to content

Commit 43b93d7

Browse files
authored
[CI] Update build patcher - throw on fail, extensible (#1042)
- Patch step runs outside CI - Build fails when core patch fails - Improve patch script - allows generic patching
1 parent f70ff46 commit 43b93d7

File tree

5 files changed

+65
-13
lines changed

5 files changed

+65
-13
lines changed

.github/actions/build/macos/comfy/action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ runs:
1919
run: |
2020
python -m pip install --upgrade pip
2121
yarn make:assets
22-
yarn patch:core:frontend
2322
2423
- name: Unzip Sign Lib/Bin Rezip
2524
if: ${{inputs.sign-and-publish == 'true'}}

.github/actions/build/windows/app/action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ runs:
4747
run: |
4848
set -x
4949
yarn make:assets
50-
yarn patch:core:frontend
5150
shell: bash
5251

5352
- name: Make app

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"make:nvidia": "yarn run make -- --nvidia",
3737
"notarize": "node debug/notarize.js",
3838
"package": "yarn run vite:compile && todesktop build --code-sign=false --async",
39-
"patch:core:frontend": "node scripts/patchComfyUI.js",
39+
"patch:core:frontend": "node scripts/patchComfyUI.js frontend requirements",
4040
"postinstall": "node .husky/install.mjs",
4141
"publish": "yarn run vite:compile && todesktop build",
4242
"publish:staging": "yarn run vite:compile && todesktop build --config=./todesktop.staging.json --async",

scripts/makeComfy.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ execSync(`git clone ${managerRepo} assets/ComfyUI/custom_nodes/ComfyUI-Manager`)
1616
execSync(`cd assets/ComfyUI/custom_nodes/ComfyUI-Manager && git checkout ${pkg.config.managerCommit} && cd ../../..`);
1717
execSync(`yarn run make:frontend`);
1818
execSync(`yarn run download:uv all`);
19+
execSync(`yarn run patch:core:frontend`);

scripts/patchComfyUI.js

+63-10
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,85 @@ import { applyPatch } from 'diff';
22
import fs from 'node:fs/promises';
33

44
/**
5-
* @param {string} filePath
6-
* @param {string} patchFilePath
5+
* Patches files based on the {@link tasks} list.
6+
*
7+
* Each CLI argument is treated as a task name.
8+
*
9+
* Paths are relative to the project root.
10+
* @example
11+
* ```bash
12+
* node scripts/patchComfyUI.js frontend requirements
13+
* ```
714
*/
8-
async function patchFile(filePath, patchFilePath) {
15+
const tasks = new Map([
16+
[
17+
'frontend',
18+
{
19+
target: './assets/ComfyUI/app/frontend_management.py',
20+
patch: './scripts/core-remove-frontend.patch',
21+
},
22+
],
23+
[
24+
'requirements',
25+
{
26+
target: './assets/ComfyUI/requirements.txt',
27+
patch: './scripts/core-requirements.patch',
28+
},
29+
],
30+
]);
31+
32+
// Main execution
33+
const args = process.argv.slice(2);
34+
35+
// Error if no args / any invalid args
36+
37+
if (args.length === 0) {
38+
console.error('No arguments provided');
39+
process.exit(15);
40+
}
41+
42+
const invalidArgs = args.filter((arg) => !tasks.has(arg));
43+
44+
if (invalidArgs.length > 0) {
45+
console.error(`Invalid argument(s): ${invalidArgs.map((arg) => `"${arg}"`).join(', ')}`);
46+
process.exit(255);
47+
}
48+
49+
// Apply patches
50+
const promises = args.map((arg) => patchFile(tasks.get(arg).target, tasks.get(arg).patch));
51+
await Promise.all(promises);
52+
53+
//#region Functions
54+
55+
/**
56+
* Applies a regular diff patch to a single file
57+
* @param {string} targetPath Target file path
58+
* @param {string} patchFilePath Patch file to apply to the target file
59+
*/
60+
async function patchFile(targetPath, patchFilePath) {
961
try {
1062
// Read the original file and patch file
1163
const [originalContent, patchContent] = await Promise.all([
12-
fs.readFile(filePath, 'utf8'),
64+
fs.readFile(targetPath, 'utf8'),
1365
fs.readFile(patchFilePath, 'utf8'),
1466
]);
1567

1668
// Apply the patch
1769
const patchedContent = applyPatch(originalContent, patchContent);
1870

19-
// If patch was successfully applied (not false or null)
71+
// If patch was successfully applied (not falsy)
2072
if (patchedContent) {
2173
// Write the result to the output file
22-
await fs.writeFile(filePath, patchedContent, 'utf8');
74+
await fs.writeFile(targetPath, patchedContent, 'utf8');
2375
console.log('Patch applied successfully!');
2476
} else {
25-
console.error('Failed to apply patch - patch may be invalid or incompatible');
77+
throw new Error(
78+
`ComfyUI core patching returned falsy value (${typeof patchedContent}) - .patch file probably requires update`
79+
);
2680
}
2781
} catch (error) {
28-
console.error('Error applying patch:', error.message);
82+
throw new Error(`Error applying core patch: ${error.message}`, { cause: error });
2983
}
3084
}
3185

32-
await patchFile('./assets/ComfyUI/app/frontend_management.py', './scripts/core-remove-frontend.patch');
33-
await patchFile('./assets/ComfyUI/requirements.txt', './scripts/core-requirements.patch');
86+
//#endregion Functions

0 commit comments

Comments
 (0)