CI / check (pull_request) Successful in 19s
The services read ~/netork/.env through env_file, so whatever it says when `up -d` creates a container ends up in that container's environment. The settings were recorded only after the swap, so every container carried the previous deploy's NETORK_VERSION: the image was right, `docker exec <api> env` was not. Record them once the pull has brought the images onto the host and before the first `up -d`. A failed pull still leaves .env alone. If the swap fails afterwards, .env names the tag whose compose files and images are already on the host, which is what a hand-typed `docker compose up -d` there should start. Also say which branches a feature-<branch> tag comes from: feature/<name> and feat/<name> become feature-<name>, and fix/<name> now becomes feature-fix-<name> (NetOrk/netork#208), because the registry keeps only feature-* branch tags. The accepted forms do not change; the comment, the refusal message and the README now say so, and a test holds that feature-fix-<name> passes and a bare fix-<name> does not. Closes #6
92 lines
2.7 KiB
Python
92 lines
2.7 KiB
Python
"""`--version` takes only the tag formats netOrk's CI publishes (NetOrk/netork#55, #208).
|
|
|
|
Every branch build is a `feature-` tag, with `/` turned into `-`: `feature/x` and
|
|
`feat/x` become `feature-x`, `fix/x` becomes `feature-fix-x`. The registry keeps
|
|
`feature-*` tags for 14 days and deletes a tag of any other form within a day, so
|
|
a bare `fix-x` is refused like any other unknown form. Anything else is refused
|
|
before a host is touched, so a typo cannot pull some ancient leftover tag.
|
|
|
|
The fake `ssh` only notes that it was reached and fails, which ends the deploy
|
|
right after the validation.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
DEPLOY = Path(__file__).resolve().parent.parent / "deploy.sh"
|
|
|
|
|
|
def _deploy(tmp_path: Path, version: str) -> tuple[subprocess.CompletedProcess[str], bool]:
|
|
bin_dir = tmp_path / "bin"
|
|
bin_dir.mkdir()
|
|
marker = tmp_path / "ssh-was-called"
|
|
fake = bin_dir / "ssh"
|
|
fake.write_text(f"#!/bin/sh\ntouch {marker}\nexit 255\n")
|
|
fake.chmod(0o755)
|
|
result = subprocess.run(
|
|
["bash", str(DEPLOY), f"--version={version}", "testhost"],
|
|
env={
|
|
"PATH": f"{bin_dir}:{os.environ['PATH']}",
|
|
"HOME": str(tmp_path),
|
|
"DEPLOY_ENV_FILE": "/dev/null",
|
|
"REGISTRY_HOST": "registry.example",
|
|
},
|
|
stdin=subprocess.DEVNULL,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=30,
|
|
check=False,
|
|
)
|
|
return result, marker.exists()
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"version",
|
|
[
|
|
"latest",
|
|
"latest-dev",
|
|
"main-1a2b3c4",
|
|
"feature-container-engine-api",
|
|
"feature-fix-a-hook-below-the-early-returns",
|
|
"feature-fix-ui-warning-icons",
|
|
"0.37.0",
|
|
],
|
|
)
|
|
def test_a_published_tag_is_accepted(tmp_path: Path, version: str) -> None:
|
|
result, reached_ssh = _deploy(tmp_path, version)
|
|
|
|
assert "Refusing to deploy version" not in result.stderr
|
|
assert reached_ssh
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"version",
|
|
[
|
|
"bogus",
|
|
"fix-a-hook",
|
|
"fix/a-hook",
|
|
"feature-",
|
|
"feature-fix/ui/warning-icons",
|
|
"feature-fix-a;id",
|
|
"feature-$(id)",
|
|
"main-xyz1234",
|
|
],
|
|
)
|
|
def test_anything_else_is_refused_before_a_host_is_touched(tmp_path: Path, version: str) -> None:
|
|
result, reached_ssh = _deploy(tmp_path, version)
|
|
|
|
assert result.returncode != 0
|
|
assert f"Refusing to deploy version '{version}'" in result.stderr
|
|
assert not reached_ssh
|
|
|
|
|
|
def test_the_refusal_names_branch_builds(tmp_path: Path) -> None:
|
|
result, _ = _deploy(tmp_path, "bogus")
|
|
|
|
assert "feature-<branch> (also for fix/* branches)" in result.stderr
|