170 lines
5.6 KiB
YAML
170 lines
5.6 KiB
YAML
# Reusable workflow
|
|
#
|
|
# Project metadata is read from pyproject.toml.
|
|
# No project-specific repository variables need to be configured manually.
|
|
#
|
|
# Required repository secret:
|
|
# REGISTRY_ACCESS_TOKEN Comfy Registry publishing API key
|
|
|
|
name: Publish to Comfy Registry
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
paths:
|
|
- "pyproject.toml"
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: comfy-registry-publish-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
publish-node:
|
|
name: Publish Custom Node to registry
|
|
runs-on: ubuntu-latest
|
|
if: github.ref_name == github.event.repository.default_branch
|
|
steps:
|
|
- name: Check out code
|
|
uses: actions/checkout@v7
|
|
|
|
- name: Validate publishing configuration
|
|
run: |
|
|
python - <<'PY'
|
|
from pathlib import Path
|
|
import tomllib
|
|
|
|
path = Path("pyproject.toml")
|
|
if not path.is_file():
|
|
raise SystemExit("pyproject.toml was not found")
|
|
|
|
with path.open("rb") as file:
|
|
config = tomllib.load(file)
|
|
|
|
required_fields = {
|
|
"[project].name": config.get("project", {}).get("name"),
|
|
"[project].version": config.get("project", {}).get("version"),
|
|
"[tool.comfy].PublisherId": (
|
|
config.get("tool", {}).get("comfy", {}).get("PublisherId")
|
|
),
|
|
}
|
|
missing = [
|
|
field
|
|
for field, value in required_fields.items()
|
|
if not str(value or "").strip()
|
|
]
|
|
|
|
if missing:
|
|
raise SystemExit(
|
|
"Missing required pyproject.toml fields: " + ", ".join(missing)
|
|
)
|
|
PY
|
|
|
|
- name: Check whether this version is already published
|
|
id: registry_version_check
|
|
run: |
|
|
exists="$(python - <<'PY'
|
|
import json
|
|
import tomllib
|
|
import urllib.error
|
|
import urllib.parse
|
|
import urllib.request
|
|
|
|
with open("pyproject.toml", "rb") as file:
|
|
config = tomllib.load(file)
|
|
|
|
project = config.get("project", {})
|
|
node_id = str(project.get("name", "")).strip()
|
|
version = str(project.get("version", "")).strip()
|
|
endpoint = (
|
|
"https://api.comfy.org/nodes/"
|
|
+ urllib.parse.quote(node_id, safe="")
|
|
+ "/versions"
|
|
)
|
|
request = urllib.request.Request(
|
|
endpoint,
|
|
headers={
|
|
"Accept": "application/json",
|
|
"User-Agent": "comfyui-model-resolver-publish-check",
|
|
},
|
|
)
|
|
|
|
try:
|
|
with urllib.request.urlopen(request, timeout=30) as response:
|
|
versions = json.load(response)
|
|
except urllib.error.HTTPError as error:
|
|
if error.code == 404:
|
|
versions = []
|
|
else:
|
|
raise SystemExit(
|
|
f"Registry version lookup failed with HTTP {error.code}"
|
|
) from error
|
|
except urllib.error.URLError as error:
|
|
raise SystemExit(f"Registry version lookup failed: {error.reason}") from error
|
|
|
|
if not isinstance(versions, list):
|
|
raise SystemExit("Registry version lookup returned an unexpected response")
|
|
|
|
print(
|
|
"true"
|
|
if any(
|
|
isinstance(item, dict)
|
|
and str(item.get("version", "")).strip() == version
|
|
for item in versions
|
|
)
|
|
else "false"
|
|
)
|
|
PY
|
|
)"
|
|
|
|
if [ "$exists" = "true" ]; then
|
|
echo "exists=true" >> "$GITHUB_OUTPUT"
|
|
echo "::notice title=Version already published::Version from pyproject.toml is already present in Comfy Registry. Nothing to publish."
|
|
else
|
|
echo "exists=false" >> "$GITHUB_OUTPUT"
|
|
echo "Version from pyproject.toml is not present in Comfy Registry. Publishing will continue."
|
|
fi
|
|
|
|
- name: Validate publishing credentials
|
|
if: steps.registry_version_check.outputs.exists != 'true'
|
|
env:
|
|
REGISTRY_ACCESS_TOKEN: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
|
run: |
|
|
if [ -z "$REGISTRY_ACCESS_TOKEN" ]; then
|
|
echo "::error title=Missing REGISTRY_ACCESS_TOKEN::Create a Comfy Registry publishing API key and add it as a repository secret named REGISTRY_ACCESS_TOKEN."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Set up Python
|
|
if: steps.registry_version_check.outputs.exists != 'true'
|
|
uses: actions/setup-python@v6
|
|
with:
|
|
python-version: "3.10"
|
|
|
|
- name: Install comfy-cli
|
|
if: steps.registry_version_check.outputs.exists != 'true'
|
|
run: python -m pip install --disable-pip-version-check comfy-cli
|
|
|
|
- name: Publish Custom Node
|
|
if: steps.registry_version_check.outputs.exists != 'true'
|
|
env:
|
|
REGISTRY_ACCESS_TOKEN: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
|
run: |
|
|
set +e
|
|
output="$(comfy --skip-prompt --no-enable-telemetry env comfy node publish --token "$REGISTRY_ACCESS_TOKEN" 2>&1)"
|
|
exit_code=$?
|
|
printf '%s\n' "$output"
|
|
|
|
if [ "$exit_code" -eq 0 ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if printf '%s\n' "$output" | grep -Eiq 'already exists|already published|duplicate.*version|version.*duplicate'; then
|
|
echo "::notice title=Version already published::The version from pyproject.toml already exists in Comfy Registry. Nothing to publish."
|
|
exit 0
|
|
fi
|
|
|
|
exit "$exit_code"
|