ci: skip duplicate registry versions

This commit is contained in:
Dariusz L
2026-08-02 16:02:17 +02:00
parent 4ea3f7d50f
commit 69bf8a2a93
2 changed files with 127 additions and 12 deletions
+105 -12
View File
@@ -1,6 +1,6 @@
# Reusable workflow
#
# Project metadata is read by the publishing action from pyproject.toml.
# Project metadata is read from pyproject.toml.
# No project-specific repository variables need to be configured manually.
#
# Required repository secret:
@@ -31,14 +31,7 @@ jobs:
uses: actions/checkout@v7
- name: Validate publishing configuration
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
python - <<'PY'
from pathlib import Path
import tomllib
@@ -69,8 +62,108 @@ jobs:
)
PY
- name: Publish Custom Node
uses: Comfy-Org/publish-node-action@main
- 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:
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
skip_checkout: true
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"
+22
View File
@@ -0,0 +1,22 @@
from pathlib import Path
WORKFLOW_PATH = Path(__file__).parents[1] / ".github" / "workflows" / "publish.yml"
def test_publish_workflow_skips_versions_already_in_the_registry():
workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
assert "id: registry_version_check" in workflow
assert "https://api.comfy.org/nodes/" in workflow
assert 'echo "exists=true" >> "$GITHUB_OUTPUT"' in workflow
assert "if: steps.registry_version_check.outputs.exists != 'true'" in workflow
assert "already published" in workflow.lower()
def test_publish_workflow_uses_current_python_runtime_without_the_external_wrapper():
workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
assert "actions/setup-python@v6" in workflow
assert "Comfy-Org/publish-node-action@main" not in workflow
assert "comfy node publish --token" in workflow