Skip to content

Commit

Permalink
Add action to purely test action itself
Browse files Browse the repository at this point in the history
  • Loading branch information
yoland68 committed Jul 10, 2024
1 parent 0759b81 commit 69b2757
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 314 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

repos:
- repo: local
hooks:
Expand All @@ -8,3 +7,4 @@ repos:
language: python
pass_filenames: false
additional_dependencies: [pyyaml, tabulate] # Add this line to specify the dependency
exclude: ^(?!(main)$).*
326 changes: 13 additions & 313 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,315 +1,15 @@
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. 11.8 or 12.1. Only valid when os is linux or windows."
required: false
default: "12.1"
torch_version:
description: "Pytorch Version. Will be used in the conda install command for pytorch. 1.10.0 or 1.11.0. Only valid when os is linux or windows."
required: false
default: 'stable'
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: true
comfyui_flags:
description: "Flags to pass to the comfyui application. eg. --force-fp16"
required: false
default: ''
# 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. http://www.comfyci.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. http://www.comfyci.org"
required: false
output_prefix:
description: "Prefix for the output files. Required if you want results uploaded to CI dashboard. http://www.comfyci.org"
required: false
default: "ComfyUI"
api_endpoint:
description: "Comfy Org API endpoint"
required: false
default: "https://api.comfy.org/upload-artifact"
name: 'action_yaml_checker'
description: 'Check action.yml for errors'
runs:
using: "composite"
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/setup-miniconda@v3
if: ${{ inputs.os != 'windows' }}
with:
activate-environment: gha-comfyui
auto-activate-base: false

- name: '[Unix] Install dependencies'
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
which pip3
pip3 install -r requirements.txt
- name: '[Unix] Check conda environment'
if: ${{ inputs.os != 'windows' }}
run: |
conda info
conda list
shell: bash -el {0}

- name: '[Unix] Download models'
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
cd ${{ github.action_path }}
python default-models-prep.py --cache-directory ~/.cache/comfy-actions-runner/modelcache --live-directory "$GITHUB_WORKSPACE/models"
- name: '[Unix] Run ComfyUI'
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
python3 main.py > application.log 2>&1 &
- name: '[Unix] Check if the server is running'
if: ${{ inputs.os != 'windows' }}
run: |
cd ${{ github.action_path }}
python3 poll_server_start.py > application.log 2>&1
shell: bash -el {0}

- name: '[Unix] Get Commit Details'
id: unix_get_commit_details
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
TIMESTAMP=$(git show -s --format=%cI HEAD^)
MESSAGE=$(git show -s --format=%s HEAD^)
COMMIT_HASH=$(git rev-parse HEAD^)
echo "Commit time: $TIMESTAMP"
echo "Commit title: $MESSAGE"
echo "Commit hash: $COMMIT_HASH"
echo "commit_time=$TIMESTAMP" >> $GITHUB_OUTPUT
echo "commit_title=$MESSAGE" >> $GITHUB_OUTPUT
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
- name: '[Unix] Run Python Action'
id: unix_action
if: ${{ inputs.os != 'windows' }}
shell: bash -el {0}
run: |
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 }}" --gsc-bucket-name "${{ inputs.gcs_bucket_name }}" --workspace-path "${{ github.workspace }}" --output-file-prefix ${{ inputs.output_prefix }} --repo "${{ github.repository }}" --commit-hash "${{ steps.unix_get_commit_details.outputs.commit_hash }}" --commit-time "${{ steps.unix_get_commit_details.outputs.commit_time }}" --commit-message "${{ steps.unix_get_commit_details.outputs.commit_title }}" --branch-name "${{ github.ref_name }}" --api-endpoint "${{ inputs.api_endpoint }}" ${{ inputs.comfyui_flags }}
- 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.workflow_name}}-${{ github.run_id }}
path: ${{ github.workspace }}/output/**

- 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.workflow_name}}-${{ 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 }}/*

# - name: '[Unix] Cleanup Conda'
# if: ${{ inputs.os != 'windows' && ( success() || failure() ) }}
# shell: bash -el {0}
# run: conda deactivate && conda env remove --name comfyui && conda clean -all


#####################################################################################
## 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:
auto-update-conda: true
miniconda-version: latest
activate-environment: gha-comfyui
python-version: ${{ inputs.python_version }}
continue-on-error: true

- name: '[Win-Only] Install Pytorch'
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
conda install pytorch torchvision torchaudio pytorch-cuda=${{ inputs.cuda_version }} -c pytorch -c nvidia --yes
- name: '[Win] Install dependencies'
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
Get-Command pip
pip install -r requirements.txt
- name: "[Win] Check conda environment"
if: ${{ inputs.os == 'windows' }}
run: |
conda activate gha-comfyui
conda info
conda list
shell: powershell

- name: '[Win] Download models'
if: ${{ inputs.os == 'windows' }}
run: |
cd $Env:GITHUB_ACTION_PATH
python default-models-prep.py --cache-directory C:\actions-runner\modelcache --live-directory "$Env:GITHUB_WORKSPACE/models"
shell: powershell

- name: '[Win] Run ComfyUI'
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
$envGithubWorkspace = $Env:GITHUB_WORKSPACE
Write-Output "##############################"
Write-Output $envGithubWorkspace
Write-Output "##############################"
Start-Process powershell -ArgumentList "-File", "${{ github.action_path }}\start-server.ps1", "-GITHUB_WORKSPACE", "`"$envGithubWorkspace`""
- name: '[Win] Check if the server is running'
if: ${{ inputs.os == 'windows' }}
run: |
cd $Env:GITHUB_ACTION_PATH
conda activate gha-comfyui
python poll_server_start.py
shell: powershell

- name: '[Win] Get Commit Details'
id: win_get_commit_details
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
$timestamp = git show -s --format=%cI HEAD^
$message = git show -s --format=%s HEAD^
$commit_hash = git rev-parse HEAD^
"commit_time=$timestamp" | Out-File -FilePath $Env:GITHUB_OUTPUT -Append
"commit_title=$message" | Out-File -FilePath $Env:GITHUB_OUTPUT -Append
"commit_hash=$commit_hash" | Out-File -FilePath $Env:GITHUB_OUTPUT -Append
- name: '[Win] Run Python Action'
id: windows_action
if: ${{ inputs.os == 'windows' }}
shell: powershell
run: |
cd $Env:GITHUB_ACTION_PATH
conda activate gha-comfyui
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 }}" `
--gsc-bucket-name "${{ inputs.gcs_bucket_name }}" `
--workspace-path "${{ github.workspace }}" `
--output-file-prefix "${{ inputs.output_prefix }}" `
--repo "${{ github.repository }}" `
--commit-hash "${{ steps.win_get_commit_details.outputs.commit_hash }}" `
--commit-time "${{ steps.win_get_commit_details.outputs.commit_time }}" `
--commit-message "${{ steps.win_get_commit_details.outputs.commit_title }}" `
--branch-name "${{ github.ref_name }}" `
--api-endpoint "${{ inputs.api_endpoint }}" `
${{ inputs.comfyui_flags }}
- 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.workflow_name}}-${{ github.run_id }}
path: ${{ github.workspace }}/output/**

- 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.workflow_name}}-${{ 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
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: python -m pip install -r requirements-dev.txt
shell: bash
- name: Run action_yaml_checker
run: python action_yaml_checker.py action.yml
shell: bash

0 comments on commit 69b2757

Please sign in to comment.