fix github release
This commit is contained in:
@@ -8,6 +8,7 @@ executes after the gate passes.
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.error
|
||||
from pathlib import Path
|
||||
@@ -214,6 +215,137 @@ def test_manifest_scope_covers_examples_and_sensor_json_only():
|
||||
), "binary sensor assets belong in the wheel, not the public repo"
|
||||
|
||||
|
||||
def test_github_steps_resume_skips_tag_creation(tmp_path):
|
||||
"""A tag pushed by an earlier failed run must not block the release upload."""
|
||||
assets = [_wheel(tmp_path, "orisys-1.2.3-cp310-cp310-win_amd64.whl")]
|
||||
steps = github.build_github_steps(
|
||||
version="1.2.3",
|
||||
branch="main",
|
||||
tag="v1.2.3",
|
||||
assets=assets,
|
||||
notes_file=None,
|
||||
create_tag=False,
|
||||
)
|
||||
descriptions = [step.description for step in steps]
|
||||
assert "create tag" not in descriptions
|
||||
assert descriptions[-1] == "create GitHub Release with assets"
|
||||
# The pushes stay: pushing an up-to-date ref is a safe no-op.
|
||||
assert "push branch" in descriptions and "push tag" in descriptions
|
||||
|
||||
|
||||
def test_non_github_remote_is_reported(tmp_path):
|
||||
repo = tmp_path / "release"
|
||||
repo.mkdir()
|
||||
subprocess.run(["git", "init", "-q"], cwd=repo, check=True, capture_output=True)
|
||||
subprocess.run(
|
||||
["git", "remote", "add", "origin", "ssh://git@internal.example:24928/orisys-tech/orisys-sdk.git"],
|
||||
cwd=repo,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
problem = github.non_github_remote_problem(repo)
|
||||
assert problem is not None and "not a GitHub host" in problem
|
||||
|
||||
subprocess.run(
|
||||
["git", "remote", "set-url", "origin", "git@github.com:orisys-tech/orisys-sdk.git"],
|
||||
cwd=repo,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
assert github.non_github_remote_problem(repo) is None
|
||||
|
||||
|
||||
def _synthetic_publish_layout(tmp_path: Path, version: str, *, tag_exists: bool):
|
||||
"""Build a fake SDK checkout + release repo and point the module at them."""
|
||||
sdk = tmp_path / "sdk"
|
||||
wheel_dir = sdk / "SDK" / version
|
||||
wheel_dir.mkdir(parents=True)
|
||||
wheels = [wheel_dir / f"orisys-{version}-cp310-cp310-win_amd64.whl"]
|
||||
wheels[0].write_bytes(b"wheel")
|
||||
|
||||
report_dir = sdk / "build" / "release" / "reports" / version
|
||||
report_dir.mkdir(parents=True)
|
||||
(report_dir / "preflight.json").write_text(
|
||||
json.dumps(_report_payload(version, wheels)), encoding="utf-8"
|
||||
)
|
||||
|
||||
release = tmp_path / "orisys-sdk-release"
|
||||
release.mkdir()
|
||||
for command in (
|
||||
["git", "init", "-q"],
|
||||
["git", "config", "user.email", "test@example.invalid"],
|
||||
["git", "config", "user.name", "test"],
|
||||
["git", "remote", "add", "origin", "git@github.com:orisys-tech/orisys-sdk.git"],
|
||||
):
|
||||
subprocess.run(command, cwd=release, check=True, capture_output=True)
|
||||
(release / "README.md").write_text("x", encoding="utf-8")
|
||||
subprocess.run(["git", "add", "-A"], cwd=release, check=True, capture_output=True)
|
||||
subprocess.run(["git", "commit", "-qm", "init"], cwd=release, check=True, capture_output=True)
|
||||
if tag_exists:
|
||||
subprocess.run(["git", "tag", f"v{version}"], cwd=release, check=True, capture_output=True)
|
||||
|
||||
manifest = sdk / "tools" / "downstream_sync_manifest.json"
|
||||
manifest.parent.mkdir(parents=True)
|
||||
manifest.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"version": 1,
|
||||
"downstreams": [
|
||||
{"name": "orisys-sdk-release", "path": "../orisys-sdk-release", "sync": []}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return sdk, release, wheels[0]
|
||||
|
||||
|
||||
def test_publish_dry_run_resumes_when_tag_already_exists(tmp_path, monkeypatch, capsys):
|
||||
sdk, release, wheel = _synthetic_publish_layout(tmp_path, "1.2.3", tag_exists=True)
|
||||
monkeypatch.setattr(github, "REPO_ROOT", sdk)
|
||||
monkeypatch.setattr(github, "MANIFEST_PATH", sdk / "tools" / "downstream_sync_manifest.json")
|
||||
monkeypatch.setattr(github, "_check_gh", lambda repo: [])
|
||||
monkeypatch.setattr(github, "_release_exists", lambda repo, tag: False)
|
||||
|
||||
exit_code = github.publish(
|
||||
github.Options(version="1.2.3", apply=False, skip_fetch=True)
|
||||
)
|
||||
output = capsys.readouterr().out
|
||||
assert exit_code == 0
|
||||
assert "already exist" in output and "skipping tag creation" in output
|
||||
assert "git tag v1.2.3" not in output
|
||||
assert "gh release create v1.2.3" in output
|
||||
|
||||
|
||||
def test_publish_dry_run_creates_tag_when_absent(tmp_path, monkeypatch, capsys):
|
||||
sdk, release, wheel = _synthetic_publish_layout(tmp_path, "1.2.4", tag_exists=False)
|
||||
monkeypatch.setattr(github, "REPO_ROOT", sdk)
|
||||
monkeypatch.setattr(github, "MANIFEST_PATH", sdk / "tools" / "downstream_sync_manifest.json")
|
||||
monkeypatch.setattr(github, "_check_gh", lambda repo: [])
|
||||
monkeypatch.setattr(github, "_release_exists", lambda repo, tag: False)
|
||||
|
||||
exit_code = github.publish(
|
||||
github.Options(version="1.2.4", apply=False, skip_fetch=True)
|
||||
)
|
||||
output = capsys.readouterr().out
|
||||
assert exit_code == 0
|
||||
assert "git tag v1.2.4" in output
|
||||
|
||||
|
||||
def test_publish_refuses_when_release_already_exists(tmp_path, monkeypatch, capsys):
|
||||
sdk, release, wheel = _synthetic_publish_layout(tmp_path, "1.2.5", tag_exists=True)
|
||||
monkeypatch.setattr(github, "REPO_ROOT", sdk)
|
||||
monkeypatch.setattr(github, "MANIFEST_PATH", sdk / "tools" / "downstream_sync_manifest.json")
|
||||
monkeypatch.setattr(github, "_check_gh", lambda repo: [])
|
||||
monkeypatch.setattr(github, "_release_exists", lambda repo, tag: True)
|
||||
|
||||
exit_code = github.publish(
|
||||
github.Options(version="1.2.5", apply=False, skip_fetch=True)
|
||||
)
|
||||
assert exit_code == 1
|
||||
assert "already exists; nothing to publish" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_manifest_checks_use_the_python_placeholder():
|
||||
entry = github.manifest_entry()
|
||||
for command in entry["checks"]:
|
||||
|
||||
Reference in New Issue
Block a user