Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ jobs:

- name: Check python types
run: uv run mypy .

- name: Install
run: pip install --user --break-system-packages .

- name: Run tests
run: bash run_tests.sh
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
default_install_hook_types:
- pre-commit
- pre-push
default_stages:
- pre-commit
fail_fast: true
Expand Down Expand Up @@ -44,3 +45,9 @@ repos:
language: system
pass_filenames: false
files: \.py$
- id: py-test
name: pytest
stages: [pre-push]
entry: bash run_tests.sh
language: system
pass_filenames: false
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ options:
uv run ruff format
uv run ruff check --fix --exit-non-zero-on-fix
uv run mypy .
uv run pytest -vvvs
```

### Performance
Expand Down
11 changes: 6 additions & 5 deletions git_evtag_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ def sign_tree_checksum(
footer = f"\n\nGit-EVTag-v0-SHA512: {in_csum}\n"
final_msg = cleaned_msg + footer

subprocess.run(
["git", "tag", "-a", "-s", tag, commit, "-m", final_msg],
check=True,
cwd=repo,
)
tag_args = ["git", "tag", "-a"]
if environ.get("EVTAG_NO_GPG_SIGN") != "true":
tag_args.append("-s")

tag_args.extend([tag, commit, "-m", final_msg])
subprocess.run(tag_args, check=True, cwd=repo)


def is_tag_signature_valid(repo: Path, tag: str) -> bool:
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dev = [
"pre-commit<4.0.0,>=3.8.0",
"mypy<2.0.0,>=1.11.2",
"ruff<1.0.0,>=0.6.7",
"pytest<9.0.0,>=8.3.3",
]

[tool.mypy]
Expand Down Expand Up @@ -92,3 +93,8 @@ ignore = [
[tool.ruff.format]
line-ending = "lf"
quote-style = "double"

[tool.pytest.ini_options]
testpaths = [
"tests.py",
]
15 changes: 15 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail

export KEY_URL="https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xd26d753395009db2b3b260940c3251a24745e484"
export EVTAG_NO_GPG_SIGN="true"

if [[ -n "${TEST_CMD:-}" ]]; then
eval "$TEST_CMD"
elif command -v uv >/dev/null 2>&1; then
uv run --frozen -q pytest --ff --exitfirst
else
pytest --ff --exitfirst
fi

unset KEY_URL EVTAG_NO_GPG_SIGN
103 changes: 103 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# ruff: noqa: S101

import shutil
import subprocess
import tempfile
from os import environ
from pathlib import Path
from urllib.request import urlopen

import pytest


def run_git(repo: Path, *args: str) -> str:
result = subprocess.run(
["git", *list(args)],
cwd=repo,
check=True,
capture_output=True,
text=True,
)
return result.stdout.strip()


def clone_repo(
url: str = "https://github.com/bbhtt/git-evtag-py.git",
) -> tuple[Path, str]:
tmpdir = tempfile.mkdtemp()
repo = Path(tmpdir) / "test_repo"
run_git(Path(tmpdir), "clone", url, str(repo))
return repo, tmpdir


def import_gpg_key() -> None:
key_url = environ.get("KEY_URL")

if key_url and key_url.startswith("https://"):
with urlopen(key_url) as response: # noqa: S310
key_data = response.read().decode("utf-8")
else:
key_data = Path("pub_key.asc").read_text()

subprocess.run(
["gpg", "--import"],
input=key_data,
text=True,
check=True,
capture_output=True,
)


def test_flow() -> None:
import_gpg_key()
repo, tmpdir = clone_repo()
try:
assert (repo / ".git").is_dir()

run_git(repo, "config", "user.name", "bbhtt")
run_git(repo, "config", "user.email", "bbhtt.zn0i8@slmail.me")

run_git(repo, "checkout", "v1.0.1")
sha = run_git(repo, "rev-parse", "HEAD")
assert sha == "295a273a2af003e57edd369f7f7e83155c36a074"

expected_evtag = (
"Git-EVTag-v0-SHA512: "
"3973d3ad28248971e6c870936012f44c512df1700cde0cf80713aced9a134fff"
"0f71eb99d87d45fd8b6c7a6fa32ec095b3bc529d09e7774ca07cefd53b1ee802"
)

assert run_git(repo, "evtag") == expected_evtag

run_git(repo, "checkout", "main")
for ref in ("v1.0.1", sha):
assert run_git(repo, "evtag", "--rev", ref) == expected_evtag

run_git(repo, "evtag", "--verify", "v1.0.8")
with pytest.raises(subprocess.CalledProcessError):
run_git(repo, "evtag", "--verify", "v1.0.1")

run_git(repo, "checkout", "v1.0.1")
run_git(repo, "evtag", "--sign", "v-test", "-m", "Testing evtag in automation")
tag_msg = run_git(repo, "show", "v-test")
lines: set[str] = {line.strip() for line in tag_msg.splitlines()}
assert "Testing evtag in automation" in lines
assert expected_evtag in lines

expected_evtag = (
"Git-EVTag-v0-SHA512: "
"b078bd1616243c65346ff47370ddf1f2e99dda350c9093b079f24647d122d38"
"5d8a5080a1645716dcec7530690f5537fc33f9c44e06ed3d265ff74fddf0cca74"
)
run_git(repo, "checkout", "v1.0.8")
msg_file = repo / "tagmsg.txt"
exp_msg = "Testing evtag tagging using tag message file"
msg_file.write_text(exp_msg)
run_git(repo, "evtag", "--sign", "v-test-2", "-F", str(msg_file))
lines_t: set[str] = {
line.strip() for line in run_git(repo, "show", "v-test-2").splitlines()
}
assert exp_msg in lines_t
assert expected_evtag in lines_t
finally:
shutil.rmtree(tmpdir)
Loading
Loading