-
Notifications
You must be signed in to change notification settings - Fork 5
/
action.yml
499 lines (457 loc) · 23.1 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
name: "Run ComfyUI on Various OSs"
description: "Run a comfyui workflow on various OSs"
inputs:
os:
description: "Operating System. macos, linux, windows."
required: true
default: ""
python_version:
description: "Python Version. Will be used in the conda install command for pytorch. 3.9 or 3.10. Only valid when os is linux or windows."
required: false
default: "3.9"
cuda_version:
description: "CUDA Version. Will be used in the conda install command for pytorch."
required: false
default: "12.1"
torch_version:
description: "Pytorch Version type, 'stable', 'nightly', 'specific'"
required: false
default: 'stable'
specific_torch_install:
description: "Command for installing specific torch version. E.g. `conda install bla bla`"
required: false
default: ''
models-json:
description: 'JSON string containing models and their download URLs. The models will be downloaded into the exact directory relative to /ComfyUI/models/. eg { "model_name": { url: "https://example.com/model.pth", "directory": "checkpoints" } }'
required: false
workflow_filenames:
description: "The list of workflow filenames is listed in the workflows/ directory. Separate by comma, e.g., 'workflow1.json,workflow2.json'."
required: false
default: 'auto'
comfyui_flags:
description: "Flags to pass to the comfyui application. eg. --force-fp16"
required: false
default: ''
use_prior_commit:
description: "Specify 'true' to use the prior commit, or 'false' to use the current commit."
required: false
default: 'false'
# Not yet supported
workflow_raw_json:
description: "Workflow's raw json file"
required: false
default: ''
timeout:
description: "Timeout for the workflow (in seconds)"
required: false
default: "600"
google_credentials:
description: "Service Account JSON for uploading to GCS. Required if you want results uploaded to CI dashboard. https://ci.comfy.org"
required: false
gcs_bucket_name:
description: "Name of the GCS bucket to upload the output files to. Required if you want results uploaded to CI dashboard. https://ci.comfy.org"
required: false
default: "comfy-ci-results"
output_prefix:
description: "Prefix for the output files. Required if you want results uploaded to CI dashboard. https://ci.comfy.org"
required: false
default: "ComfyUI"
api_endpoint:
description: "Comfy Org API endpoint"
required: false
default: "https://api.comfy.org/upload-artifact"
skip_quickci:
description: "Skip quickci."
required: false
default: "true"
runs:
using: "composite"
steps:
- name: '[Universal] Checkout'
uses: actions/checkout@v4
with:
fetch-depth: 2
############################################################
## Mac/Linux Steps ##
## ______________ ##
## / /| _nnnn_ ##
## / / | dGGGGMMb ##
## /____________ / | @p~qp~~qMb ##
## | ___________ | | M|@||@) M| ##
## || || | @,----.JM| ##
## || || | JS^\__/ qKL ##
## || || | dZP qKRb ##
## ||___________|| | dZP qKKb ##
## | _______ | / fZP SMMb ##
## /| (_______) | / HZM MMMM ##
## ( |_____________|/ FqM MMMM ##
## \ __| ". |\dS"qML ##
## .=======================. | `. | `' \Zq ##
## | :::::::::::::::: ::: | _) \.___.,| .' ##
## | ::::::::::::::[] ::: | \____ )MMMMMP| .' ##
## | ----------- ::: | `-' `--' ##
## `-----------------------' ##
############################################################
- name: '[Unix] Auth to GCS'
uses: "google-github-actions/auth@v2"
if: ${{ inputs.os != 'windows' }}
with:
credentials_json: "${{ inputs.google_credentials }}"
# - name: '[Unix] Setup Conda'
# uses: conda-incubator/[email protected]
# if: ${{ inputs.os != 'windows' && hashFiles('${{ env.HOME }}/miniconda3/envs/gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}/bin/pip') == '' }}
# with:
# activate-environment: gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
# miniconda-version: "latest"
# auto-activate-base: false
# python-version: ${{ inputs.python_version }}
# continue-on-error: true
- name: '[Unix-Mac-Only] Install Pytorch nightly'
if: ${{ inputs.os == 'macos' && inputs.torch_version == 'nightly' }}
shell: bash -el {0}
run: |
conda env list
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
conda install pytorch-nightly::pytorch torchvision torchaudio -c pytorch-nightly
- name: '[Unix-Mac-Only] Install Pytorch stable'
if: ${{ inputs.os == 'macos' && inputs.torch_version == 'stable' }}
shell: bash -el {0}
run: |
conda env list
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
conda install pytorch::pytorch torchvision torchaudio -c pytorch
- name: '[Unix-Linux-Only] Install Pytorch nightly'
if: ${{ inputs.os == 'linux' && inputs.torch_version == 'nightly' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
#conda install pytorch torchvision torchaudio pytorch-cuda=${{ inputs.cuda_version }} -c pytorch-nightly -c nvidia
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121
- name: '[Unix-Linux-Only] Install Pytorch stable'
if: ${{ inputs.os == 'linux' && inputs.torch_version == 'stable' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
conda install pytorch torchvision torchaudio pytorch-cuda=${{ inputs.cuda_version}} -c pytorch -c nvidia
- name: '[Unix] Install Pytorch specific version'
if: ${{ inputs.os == 'macos' && inputs.torch_version == 'specific' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
echo "Run specific torch install command"
${{ inputs.specific_torch_install }}
- name: '[Unix] Install dependencies'
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
which pip
pip install -r requirements.txt
pip install -U comfy-cli
- name: '[Unix] Check conda environment'
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
which python
echo "#### Python Version ####"
python --version
echo "#### Pip Version ####"
pip --version
echo "#### Conda Info Version ####"
conda info
conda list
- name: '[Unix] Download models'
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
cd ${{ github.action_path }}
which pip
pip install -r requirements.txt
echo "will run default-models prep"
python default-models-prep.py --cache-directory ~/.cache/comfy-actions-runner/modelcache --live-directory "$GITHUB_WORKSPACE/models"
echo "default-models-prep done, will copy workflow images"
cp -r "${{ github.action_path }}"/workflow-images/* "$GITHUB_WORKSPACE/input"
echo "workflow images copied"
- name: '[Unix] Run ComfyUI quick test'
if: ${{ inputs.os != 'windows' && inputs.skip_quick_ci != 'true' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
python3 main.py --quick-test-for-ci
- name: '[Unix] Run ComfyUI'
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
python3 main.py ${{inputs.comfyui_flags}} > application.log 2>&1 &
- name: '[Unix] Check if the server is running'
if: ${{ inputs.os != 'windows' }}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
cd ${{ github.action_path }}
python3 poll_server_start.py > application.log 2>&1
shell: bash -el {0}
- name: '[Unix] Get Details and Run Python Action'
id: unix_action
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
if [ "${{ inputs.use_prior_commit }}" == "true" ]; then
COMMIT_HASH=$(git rev-parse HEAD^)
else
COMMIT_HASH=$(git rev-parse HEAD)
fi
echo "Commit time: $TIMESTAMP"
echo "Commit title: $MESSAGE"
echo "Commit hash: $COMMIT_HASH"
BRANCH_NAME="${{ github.ref_name }}"
PRNUMBER="${{ github.event.pull_request.number }}"
if [ -n "$PRNUMBER" ]; then
BRANCH_NAME="$PRNUMBER/merge"
git fetch origin pull/$PRNUMBER/head
git checkout FETCH_HEAD
COMMIT_HASH=$(git rev-parse HEAD)
fi
TIMESTAMP=$(git show -s --format=%cI $COMMIT_HASH)
MESSAGE=$(git show -s --format=%s $COMMIT_HASH)
cd ${{ github.action_path }}
echo "Running workflows: ${{ inputs.workflow_filenames }}"
python3 action.py \
--comfy-workflow-names ${{ inputs.workflow_filenames }} \
--github-action-workflow-name "${{ github.workflow }}" \
--os "${{ inputs.os }}" \
--run-id "${{ github.run_id }}" \
--job-id "${{ github.job }}" \
--job-trigger-user "${{ github.actor }}" \
--gsc-bucket-name "${{ inputs.gcs_bucket_name }}" \
--workspace-path "${{ github.workspace }}" \
--output-file-prefix ${{ inputs.output_prefix }} \
--repo "${{ github.repository }}" \
--comfy-run-flags "'${{ inputs.comfyui_flags }}'" \
--python-version "${{ inputs.python_version }}" \
--torch-version "${{ inputs.torch_version }}" \
--cuda-version "${{ inputs.cuda_version }}" \
--commit-hash "$COMMIT_HASH" \
--commit-time "$TIMESTAMP" \
--commit-message "$MESSAGE" \
--branch-name "$BRANCH_NAME" \
--api-endpoint "${{ inputs.api_endpoint }}"
- name: '[Unix] Upload Output Files'
uses: actions/upload-artifact@v4
if: ${{ inputs.os != 'windows' && ( success() || failure() ) }}
with:
name: output-files-${{ github.job }}-${{ inputs.os }}-${{ inputs.python_version }}-${{ inputs.cuda_version }}-${{ inputs.torch_version }}-${{ inputs.workflow_name }}-run${{ github.run_id }}
path: ${{ github.workspace }}/output/**
- name: '[Unix] Upload log file to GCS'
if: ${{ inputs.os != 'windows' && ( success() || failure() ) }}
id: unix_upload-log-files
uses: google-github-actions/upload-cloud-storage@v2
with:
process_gcloudignore: false
path: ${{ github.workspace }}/application.log
destination: ${{ inputs.gcs_bucket_name }}/logs/${{ github.job }}-${{ inputs.os }}-${{ inputs.python_version }}-${{ inputs.cuda_version }}-${{ inputs.torch_version }}-${{ inputs.workflow_name }}-run${{ github.run_id }}
- name: '[Unix] Upload log file'
if: ${{ inputs.os != 'windows' && ( success() || failure() ) }}
uses: actions/upload-artifact@v4
with:
name: app-logs-${{ github.job }}-${{ inputs.os }}-${{ inputs.python_version }}-${{ inputs.cuda_version }}-${{ inputs.torch_version }}-${{ inputs.workflow_name }}-run${{ github.run_id }}
path: ${{ github.workspace }}/application.log
- name: '[Unix] Cleanup output files only'
if: ${{ inputs.os != 'windows' && ( success() || failure() ) }}
shell: bash -el {0}
run: rm -rf ${{ github.workspace }}/*
#####################################################################################
## Windows Steps (F**k powershell) ##
## ##
## _.-;;-._ _ ##
## '-..-'| || | | | ##
## '-..-'|_.-;;-._| | |===( ) ////// ##
## '-..-'| || | |_| ||| | o o| ##
## '-..-'|_.-''-._| ||| ( c ) ____ ##
## ||| \= / || \_ ##
## |||||| || | ##
## |||||| ...||__/|-" ##
## |||||| __|________|__ ##
## ||| |______________| ##
## ||| || || || || ##
## ||| || || || || ##
## -------------------------------------|||-------------||-||------||-||------- ##
## |__> || || || || ##
## ##
## ##
#####################################################################################
- name: '[Win] Auth to GCS'
uses: "google-github-actions/auth@v2"
if: ${{ inputs.os == 'windows' }}
with:
credentials_json: "${{ inputs.google_credentials }}"
- name: '[Win] Setup Conda'
uses: conda-incubator/[email protected]
if: ${{ inputs.os == 'windows' }}
with:
activate-environment: gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
miniconda-version: "latest"
python-version: ${{ inputs.python_version }}
continue-on-error: true
# This step is created because the Conda setup step fails everytime.
- name: '[Win-Only] Create Conda environment if not exists'
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
if (-not (conda env list | Select-String -Pattern "gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}")) {
conda create -n gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }} python=${{ inputs.python_version }} -y
}
- name: '[Win-Only] Install Pytorch nightly'
if: ${{ inputs.os == 'windows' && inputs.torch_version == 'nightly'}}
shell: powershell
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
Get-Command pip3
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121
- name: '[Win-Only] Install Pytorch stable'
if: ${{ inputs.os == 'windows' && inputs.torch_version =='stable' }}
shell: powershell
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
Get-Command pip3
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
- name: '[Win] Install Pytorch specific version'
if: ${{ inputs.os == 'windows' && inputs.torch_version == 'specific' }}
shell: powershell
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
Write-Output "Run specific torch install command"
${{ inputs.specific_torch_install }}
- name: '[Win] Install dependencies'
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
pip install -r requirements.txt
pip install -U comfy-cli
conda install google-cloud-storage -y # This is because some fcking how, installing google-cloud-storage using pip has permission error on Windows using python 3.12
- name: "[Win] Check conda environment"
if: ${{ inputs.os == 'windows' }}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
Get-Command python
Write-Output "#### Python Version ####"
python --version
Write-Output "#### Pip Version ####"
pip --version
Write-Output "#### Conda Info ####"
conda info
conda list
shell: powershell
- name: '[Win] Download models'
if: ${{ inputs.os == 'windows' }}
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
cd $Env:GITHUB_ACTION_PATH
pip install -r requirements.txt
python default-models-prep.py --cache-directory C:\actions-runner\modelcache --live-directory "$Env:GITHUB_WORKSPACE/models"
Copy-Item -Path "$Env:GITHUB_ACTION_PATH\workflow-images\*" -Destination "$Env:GITHUB_WORKSPACE\input" -Recurse
shell: powershell
- name: '[Win] Run ComfyUI quick test'
if: ${{ inputs.os == 'windows' && inputs.skip_quick_ci != 'true' }}
shell: powershell
run: |
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
python $Env:GITHUB_WORKSPACE/main.py --quick-test-for-ci
Write-Output "(Temporary) fixing torch nightly bug"
python $Env:GITHUB_WORKSPACE/fix_torch.py
- name: '[Win] Run ComfyUI'
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
$envGithubWorkspace = $Env:GITHUB_WORKSPACE
Write-Output "##############################"
Write-Output $envGithubWorkspace
Write-Output "##############################"
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
Start-Process powershell -ArgumentList "-File", "${{ github.action_path }}\start-server.ps1", "-GITHUB_WORKSPACE", "`"$envGithubWorkspace`"", "-CondaEnv", "`"gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}`"", "-RunFlags", "`"${{ inputs.comfyui_flags}}`""
- name: '[Win] Check if the server is running'
if: ${{ inputs.os == 'windows' }}
run: |
cd $Env:GITHUB_ACTION_PATH
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
python poll_server_start.py
shell: powershell
- name: '[Win] Get Details and Run Python Action'
id: windows_action
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
if ( "${{ inputs.use_prior_commit }}" -eq "true" ) {
$commit_hash = git rev-parse HEAD^
} else {
$commit_hash = git rev-parse HEAD
}
$branch_name = "${{ github.ref_name }}"
$pr_number = "${{ github.event.pull_request.number }}"
if ( $pr_number -ne "" ) {
$branch_name = "$pr_number/merge"
git fetch origin pull/$pr_number/head
git checkout FETCH_HEAD
$commit_hash = git rev-parse HEAD
}
$timestamp = git show -s --format=%cI $commit_hash
$message = git show -s --format=%s $commit_hash
# Special cleanup/escape for variable names
$branch_name = $branch_name -replace '"', '\"'
$message = $message -replace '"', '\"'
$actor = "${{ github.actor }}"
$actor = $actor -replace '"', '\"'
cd $Env:GITHUB_ACTION_PATH
conda activate gha-comfyui-${{ inputs.python_version }}-${{ inputs.torch_version }}
Write-Host "Running workflows: ${{ inputs.workflow_filenames }}"
python action.py `
--comfy-workflow-names "${{ inputs.workflow_filenames }}" `
--github-action-workflow-name "${{ github.workflow }}" `
--os "${{ inputs.os }}" `
--run-id "${{ github.run_id }}" `
--job-id "${{ github.job }}" `
--job-trigger-user $actor `
--gsc-bucket-name "${{ inputs.gcs_bucket_name }}" `
--workspace-path "${{ github.workspace }}" `
--output-file-prefix "${{ inputs.output_prefix }}" `
--repo "${{ github.repository }}" `
--comfy-run-flags "'${{ inputs.comfyui_flags }}'" `
--python-version "${{ inputs.python_version }}" `
--torch-version "${{ inputs.torch_version }}" `
--cuda-version "${{ inputs.cuda_version }}" `
--commit-hash "$commit_hash" `
--commit-time "$timestamp" `
--commit-message $message `
--branch-name $branch_name `
--api-endpoint "${{ inputs.api_endpoint }}"
(Get-ChildItem -Force -Path "${{ github.workspace }}/output").FullName
cat "${{ github.workspace }}/application.log"
# Note the Get-ChildItem mess is powershell for "ls -la" for debug
- name: '[Win] Upload Output Files'
uses: actions/upload-artifact@v4
if: ${{ inputs.os == 'windows' && ( success() || failure() ) }}
with:
name: output-files-${{ github.job }}-${{ inputs.os }}-${{ inputs.python_version }}-${{ inputs.cuda_version }}-${{ inputs.torch_version }}-${{ inputs.workflow_name }}-run${{ github.run_id }}
path: ${{ github.workspace }}/output/**
- name: '[Win] Upload log file to GCS'
if: ${{ ( success() || failure() ) && inputs.os == 'windows'}}
id: win_upload-log-files
uses: google-github-actions/upload-cloud-storage@v2
with:
process_gcloudignore: false
path: ${{ github.workspace }}/application.log
destination: ${{ inputs.gcs_bucket_name }}/logs/${{ github.job }}-${{ inputs.os }}-${{ inputs.python_version }}-${{ inputs.cuda_version }}-${{ inputs.torch_version }}-${{ inputs.workflow_name }}-run${{ github.run_id }}
- name: '[Win] Upload log file'
uses: actions/upload-artifact@v4
if: ${{ inputs.os == 'windows' && ( success() || failure() ) }}
with:
name: app-logs-${{ github.job }}-${{ inputs.os }}-${{ inputs.python_version }}-${{ inputs.cuda_version }}-${{ inputs.torch_version }}-${{ inputs.workflow_name }}-run${{ github.run_id }}
path: ${{ github.workspace }}/application.log
- name: '[Win] Cleanup output files only'
if: ${{ inputs.os == 'windows' && ( success() || failure() ) }}
shell: powershell
run: Remove-Item -Path "${{ github.workspace }}/output/*" -Recurse -Force