Public Access
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e01c39b4b8 | ||
|
|
aa93e894a6 | ||
|
|
004b890463 | ||
|
|
587906f518 | ||
|
|
d743ba93eb | ||
|
|
c7351a495a | ||
|
|
4de11bfc18 | ||
|
|
a02bf6d70e | ||
|
|
368c87aabf | ||
|
|
4f982dc3ba | ||
|
|
a7a8637244 | ||
|
|
cdf3408a35 |
@@ -90,7 +90,7 @@ jobs:
|
|||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
env:
|
env:
|
||||||
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
|
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
|
||||||
DEVX_VIKUNJA_PROJECT_ID: "8"
|
DEVX_VIKUNJA_PROJECT_ID: "2"
|
||||||
HEAD_REF: ${{ github.head_ref }}
|
HEAD_REF: ${{ github.head_ref }}
|
||||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||||
REPOSITORY: ${{ github.repository }}
|
REPOSITORY: ${{ github.repository }}
|
||||||
@@ -173,7 +173,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CI_GITEA_API_TOKEN: ${{ secrets.CI_GITEA_API_TOKEN }}
|
CI_GITEA_API_TOKEN: ${{ secrets.CI_GITEA_API_TOKEN }}
|
||||||
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
|
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
|
||||||
DEVX_VIKUNJA_PROJECT_ID: "8"
|
DEVX_VIKUNJA_PROJECT_ID: "2"
|
||||||
HEAD_REF: ${{ github.head_ref }}
|
HEAD_REF: ${{ github.head_ref }}
|
||||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||||
REPOSITORY: ${{ github.repository }}
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ jobs:
|
|||||||
if: needs.detect-and-configure.outputs.is-automated == 'false'
|
if: needs.detect-and-configure.outputs.is-automated == 'false'
|
||||||
env:
|
env:
|
||||||
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
|
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
|
||||||
DEVX_VIKUNJA_PROJECT_ID: "8"
|
DEVX_VIKUNJA_PROJECT_ID: "2"
|
||||||
run: |
|
run: |
|
||||||
. .venv/bin/activate 2>/dev/null || true
|
. .venv/bin/activate 2>/dev/null || true
|
||||||
python3 -m devx.ci.post_merge --git-sha "${{ github.sha }}"
|
python3 -m devx.ci.post_merge --git-sha "${{ github.sha }}"
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ src/devx/
|
|||||||
├── translations.json # Translation strings (en, bg, de, pl, ru, zh)
|
├── translations.json # Translation strings (en, bg, de, pl, ru, zh)
|
||||||
├── ci/ # CI/CD automation modules (run by workflows)
|
├── ci/ # CI/CD automation modules (run by workflows)
|
||||||
│ ├── release.py # Automated versioning, tagging, changelog
|
│ ├── release.py # Automated versioning, tagging, changelog
|
||||||
│ ├── publish.py # Build and publish to Gitea PyPI registry (--skip-build for non-Python repos)
|
│ ├── publish.py # Build, publish to Gitea PyPI registry, create Gitea release (with retry)
|
||||||
│ ├── auto_merge.py # Squash-merge PRs with task ID validation
|
│ ├── auto_merge.py # Squash-merge PRs with task ID validation
|
||||||
│ ├── check_auto_merge_ready.py # Pre-merge validation gate (branch, PR title, Vikunja, behind-master)
|
│ ├── check_auto_merge_ready.py # Pre-merge validation gate (branch, PR title, Vikunja, behind-master)
|
||||||
│ ├── _shared.py # Shared utilities (get_latest_tag)
|
│ ├── _shared.py # Shared utilities (get_latest_tag)
|
||||||
@@ -310,6 +310,20 @@ by `python -m devx.tools.install_tools` and configured by
|
|||||||
- `create_pr()` / `merge_pr()` / `review_pr()` — Pull request operations
|
- `create_pr()` / `merge_pr()` / `review_pr()` — Pull request operations
|
||||||
- `create_release()` / `list_releases()` — Release management
|
- `create_release()` / `list_releases()` — Release management
|
||||||
|
|
||||||
|
**`devx.gitea_cli.configure_tea_login()`** — Configures tea login in
|
||||||
|
containerized CI environments where `make setup` was not called. Used by
|
||||||
|
`publish.py` (`--auto-login`) and `notify_failure.py` (`--auto-login`).
|
||||||
|
Raises `TeaCLIError` if login configuration fails — this prevents cryptic
|
||||||
|
"no available login" errors from subsequent tea commands.
|
||||||
|
|
||||||
|
**Error handling**: `TeaCLI._run()` includes both stdout and stderr in
|
||||||
|
`TeaCLIError` messages, because `tea` writes some errors (for example,
|
||||||
|
"no available login") to stdout, not stderr.
|
||||||
|
|
||||||
|
**Release creation retry**: `publish.py` retries Gitea release creation
|
||||||
|
up to 3 times with exponential backoff (2s, 4s) on transient failures.
|
||||||
|
"Already exists" errors are treated as success (idempotent).
|
||||||
|
|
||||||
### git-cliff Commit Preprocessing
|
### git-cliff Commit Preprocessing
|
||||||
|
|
||||||
Merge commits on master have the format `DEVX-N: <conventional commit>`. The
|
Merge commits on master have the format `DEVX-N: <conventional commit>`. The
|
||||||
|
|||||||
@@ -2,6 +2,30 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.47.4] - 2026-08-03
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Add User-Agent header to _download in install_tools
|
||||||
|
|
||||||
|
## [0.47.3] - 2026-07-17
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Bake promtool into ci-full image, add download timeout, speed up tests
|
||||||
|
|
||||||
|
## [0.47.2] - 2026-07-17
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Add retry logic to TeaCLI for transient HTTP errors (502/503/504/429)
|
||||||
|
|
||||||
|
## [0.47.1] - 2026-07-16
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Tea CLI login failure handling, error messages, release retry
|
||||||
|
|
||||||
## [0.47.0] - 2026-07-14
|
## [0.47.0] - 2026-07-14
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ quality badges.
|
|||||||
|
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
||||||
[](https://www.python.org/downloads/)
|
[](https://www.python.org/downloads/)
|
||||||
|
|
||||||
## Why devx?
|
## Why devx?
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ extra index and list devx in your dependencies:
|
|||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"devx>=0.47.0",
|
"devx>=0.47.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.pip]
|
[tool.pip]
|
||||||
@@ -101,8 +101,8 @@ pip install -e .
|
|||||||
```
|
```
|
||||||
|
|
||||||
> **Note:** If your project requires a specific devx version, pin it in
|
> **Note:** If your project requires a specific devx version, pin it in
|
||||||
> `dependencies` (for example, `"devx==0.47.0"`) or use a version constraint
|
> `dependencies` (for example, `"devx==0.47.4"`) or use a version constraint
|
||||||
> (for example, `"devx>=0.47.0,<0.48"`).
|
> (for example, `"devx>=0.47.4,<0.48"`).
|
||||||
|
|
||||||
### Optional extras
|
### Optional extras
|
||||||
|
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ COPY . /tmp/devx
|
|||||||
RUN pip install --no-cache-dir /tmp/devx[release,molecule,deploy] \
|
RUN pip install --no-cache-dir /tmp/devx[release,molecule,deploy] \
|
||||||
&& rm -rf /tmp/devx
|
&& rm -rf /tmp/devx
|
||||||
|
|
||||||
# Install git-cliff (changelog generator for release job) and OpenTofu (for infra deploy jobs)
|
# Install git-cliff (changelog generator for release job), OpenTofu (for infra deploy jobs),
|
||||||
RUN python3 -m devx.tools.install_tools --tool git-cliff --tool tofu
|
# and promtool (Prometheus rule validator — used by every infra CI run for alert validation)
|
||||||
|
RUN python3 -m devx.tools.install_tools --tool git-cliff --tool tofu --tool promtool
|
||||||
|
|||||||
+8
-8
@@ -12,12 +12,12 @@ project to be reusable across all oblachno-oss repositories.
|
|||||||
|
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
||||||
[](https://www.python.org/downloads/)
|
[](https://www.python.org/downloads/)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
@@ -74,14 +74,14 @@ Add devx to your `pyproject.toml` dependencies and configure the registry:
|
|||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"devx>=0.47.0",
|
"devx>=0.47.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.pip]
|
[tool.pip]
|
||||||
extra-index-url = "https://git.oblachno.oblachno.fyi/api/packages/oblachno-oss/pypi/simple"
|
extra-index-url = "https://git.oblachno.oblachno.fyi/api/packages/oblachno-oss/pypi/simple"
|
||||||
```
|
```
|
||||||
|
|
||||||
Pin a specific version if needed: `"devx==0.47.0"` or `"devx>=0.47.0,<0.48"`.
|
Pin a specific version if needed: `"devx==0.47.4"` or `"devx>=0.47.4,<0.48"`.
|
||||||
|
|
||||||
### Optional extras
|
### Optional extras
|
||||||
|
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ Add devx to your `pyproject.toml`:
|
|||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"devx>=0.47.0",
|
"devx>=0.47.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
"devx>=0.47.0",
|
"devx>=0.47.4",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""devx — reusable development and CI/CD tools for oblachno-oss projects."""
|
"""devx — reusable development and CI/CD tools for oblachno-oss projects."""
|
||||||
|
|
||||||
__version__ = "0.47.0"
|
__version__ = "0.47.4"
|
||||||
|
|||||||
+37
-7
@@ -4,6 +4,10 @@
|
|||||||
Uses git-cliff to generate the release notes from conventional commits.
|
Uses git-cliff to generate the release notes from conventional commits.
|
||||||
Uses the ``tea`` Gitea CLI for release creation.
|
Uses the ``tea`` Gitea CLI for release creation.
|
||||||
|
|
||||||
|
Gitea release creation is retried up to 3 times with exponential backoff
|
||||||
|
(2s, 4s) to handle transient failures (network timeouts, 5xx errors).
|
||||||
|
If the release already exists, it is treated as success (idempotent).
|
||||||
|
|
||||||
Publishing destinations (checked in order):
|
Publishing destinations (checked in order):
|
||||||
1. **Gitea PyPI registry** — if ``--registry-url`` is given (or
|
1. **Gitea PyPI registry** — if ``--registry-url`` is given (or
|
||||||
``DEVX_PYPI_REGISTRY_URL`` env var is set, or ``GITEA_API_URL``
|
``DEVX_PYPI_REGISTRY_URL`` env var is set, or ``GITEA_API_URL``
|
||||||
@@ -27,6 +31,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
from dotenv import load_dotenv # pyright: ignore[reportMissingImports,reportUnknownVariableType]
|
from dotenv import load_dotenv # pyright: ignore[reportMissingImports,reportUnknownVariableType]
|
||||||
|
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential
|
||||||
|
|
||||||
from devx.config import GITEA_API_URL, REPO_OWNER
|
from devx.config import GITEA_API_URL, REPO_OWNER
|
||||||
from devx.gitea_cli import TeaCLI, TeaCLIError, configure_tea_login
|
from devx.gitea_cli import TeaCLI, TeaCLIError, configure_tea_login
|
||||||
@@ -312,13 +317,7 @@ def main(
|
|||||||
|
|
||||||
release_body = generate_release_notes(tag)
|
release_body = generate_release_notes(tag)
|
||||||
|
|
||||||
try:
|
_create_release_with_retry(tea, repo, tag, release_body)
|
||||||
tea.create_release(repo, tag=tag, title=tag, body=release_body)
|
|
||||||
except TeaCLIError as e:
|
|
||||||
if "already" in str(e).lower() and "release" in str(e).lower():
|
|
||||||
click.echo(_("Gitea release {tag} already exists — skipping creation.", tag=tag))
|
|
||||||
return
|
|
||||||
raise click.ClickException(_("Release creation failed: {error}", error=str(e))) from None
|
|
||||||
|
|
||||||
click.echo(
|
click.echo(
|
||||||
_(
|
_(
|
||||||
@@ -328,5 +327,36 @@ def main(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _create_release_with_retry(tea: TeaCLI, repo: str, tag: str, release_body: str) -> None:
|
||||||
|
"""Create a Gitea release with retry for transient failures.
|
||||||
|
|
||||||
|
Retries up to 3 times with exponential backoff (2s, 4s) on TeaCLIError
|
||||||
|
unless the error indicates the release already exists (which is treated
|
||||||
|
as success). This handles transient issues like network timeouts, Gitea
|
||||||
|
rate limiting, or temporary 5xx errors that caused CI run #2822 to fail.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@retry(
|
||||||
|
stop=stop_after_attempt(3),
|
||||||
|
wait=wait_exponential(multiplier=2, min=2, max=10),
|
||||||
|
retry=retry_if_exception_type(TeaCLIError),
|
||||||
|
reraise=True,
|
||||||
|
)
|
||||||
|
def _attempt() -> None:
|
||||||
|
try:
|
||||||
|
tea.create_release(repo, tag=tag, title=tag, body=release_body)
|
||||||
|
except TeaCLIError as e:
|
||||||
|
error_str = str(e).lower()
|
||||||
|
if "already" in error_str and "release" in error_str:
|
||||||
|
click.echo(_("Gitea release {tag} already exists — skipping creation.", tag=tag))
|
||||||
|
return
|
||||||
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
_attempt()
|
||||||
|
except TeaCLIError as e:
|
||||||
|
raise click.ClickException(_("Release creation failed: {error}", error=str(e))) from None
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": # pragma: no cover
|
if __name__ == "__main__": # pragma: no cover
|
||||||
main()
|
main()
|
||||||
|
|||||||
+78
-17
@@ -40,27 +40,46 @@ Usage::
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess # nosec B404
|
import subprocess # nosec B404
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
from tenacity import (
|
||||||
|
before_sleep_log,
|
||||||
|
retry,
|
||||||
|
retry_if_exception_type,
|
||||||
|
stop_after_attempt,
|
||||||
|
wait_exponential,
|
||||||
|
)
|
||||||
|
|
||||||
from devx.config import GITEA_API_URL
|
from devx.config import GITEA_API_URL, MAX_RETRIES, RETRY_BACKOFF_BASE, RETRY_STATUS_CODES
|
||||||
from devx.i18n import _
|
from devx.i18n import _
|
||||||
from devx.tokens import get_ci_token
|
from devx.tokens import get_ci_token
|
||||||
|
|
||||||
|
logger = logging.getLogger("gitea_cli")
|
||||||
|
|
||||||
|
|
||||||
class TeaCLIError(Exception):
|
class TeaCLIError(Exception):
|
||||||
"""Raised when a tea CLI command fails."""
|
"""Raised when a tea CLI command fails."""
|
||||||
|
|
||||||
|
|
||||||
|
class _TransientTeaError(TeaCLIError):
|
||||||
|
"""Tea CLI error caused by a transient HTTP status (502/503/504/429)."""
|
||||||
|
|
||||||
|
|
||||||
def configure_tea_login(login_name: str = "devx") -> None:
|
def configure_tea_login(login_name: str = "devx") -> None:
|
||||||
"""Configure tea CLI login from CI_GITEA_API_TOKEN and DEVX_GITEA_API_URL.
|
"""Configure tea CLI login from CI_GITEA_API_TOKEN and DEVX_GITEA_API_URL.
|
||||||
|
|
||||||
Idempotent: if a login with the same name already exists, it is not re-added.
|
Idempotent: if a login with the same name already exists, it is not re-added.
|
||||||
Skips silently if tea is not installed or no token is set.
|
Skips silently if tea is not installed or no token is set.
|
||||||
|
|
||||||
|
Raises ``TeaCLIError`` if the login add or default command fails. This is
|
||||||
|
critical because subsequent tea commands (e.g. ``releases create``) will
|
||||||
|
fail with a cryptic "no available login" error if the login was not
|
||||||
|
configured successfully.
|
||||||
|
|
||||||
Used by CI scripts (publish, notify_failure) that need tea login but
|
Used by CI scripts (publish, notify_failure) that need tea login but
|
||||||
run in containerized environments where ``make setup`` was not called.
|
run in containerized environments where ``make setup`` was not called.
|
||||||
"""
|
"""
|
||||||
@@ -88,18 +107,31 @@ def configure_tea_login(login_name: str = "devx") -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
click.echo(_("Configuring tea login '{name}' for {url}...", name=login_name, url=gitea_url))
|
click.echo(_("Configuring tea login '{name}' for {url}...", name=login_name, url=gitea_url))
|
||||||
subprocess.run( # nosec B603
|
add_result = subprocess.run( # nosec B603
|
||||||
[tea_bin, "login", "add", "--name", login_name, "--url", gitea_url, "--token", token],
|
[tea_bin, "login", "add", "--name", login_name, "--url", gitea_url, "--token", token],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
subprocess.run( # nosec B603
|
if add_result.returncode != 0:
|
||||||
|
raise TeaCLIError(
|
||||||
|
f"tea login add failed (rc={add_result.returncode})\n"
|
||||||
|
f"stdout: {add_result.stdout.strip()}\n"
|
||||||
|
f"stderr: {add_result.stderr.strip()}"
|
||||||
|
)
|
||||||
|
|
||||||
|
default_result = subprocess.run( # nosec B603
|
||||||
[tea_bin, "login", "default", login_name],
|
[tea_bin, "login", "default", login_name],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
|
if default_result.returncode != 0:
|
||||||
|
raise TeaCLIError(
|
||||||
|
f"tea login default failed (rc={default_result.returncode})\n"
|
||||||
|
f"stdout: {default_result.stdout.strip()}\n"
|
||||||
|
f"stderr: {default_result.stderr.strip()}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TeaCLI:
|
class TeaCLI:
|
||||||
@@ -122,6 +154,10 @@ class TeaCLI:
|
|||||||
def _run(self, args: list[str], json_output: bool = True) -> str:
|
def _run(self, args: list[str], json_output: bool = True) -> str:
|
||||||
"""Run a tea command and return stdout.
|
"""Run a tea command and return stdout.
|
||||||
|
|
||||||
|
Retries up to ``MAX_RETRIES`` times on transient HTTP errors
|
||||||
|
(502/503/504/429) detected in stderr/stdout, with exponential
|
||||||
|
backoff. Non-transient errors fail immediately.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
args: Command arguments (without the leading ``tea``).
|
args: Command arguments (without the leading ``tea``).
|
||||||
json_output: If True, append ``--output json`` to the command.
|
json_output: If True, append ``--output json`` to the command.
|
||||||
@@ -130,25 +166,50 @@ class TeaCLI:
|
|||||||
stdout as a string.
|
stdout as a string.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
TeaCLIError: If the command fails.
|
TeaCLIError: If the command fails after retries are exhausted.
|
||||||
"""
|
"""
|
||||||
cmd = [self._tea, *args]
|
cmd = [self._tea, *args]
|
||||||
if json_output:
|
if json_output:
|
||||||
cmd.extend(["--output", "json"])
|
cmd.extend(["--output", "json"])
|
||||||
|
|
||||||
|
def _execute() -> str:
|
||||||
|
try:
|
||||||
|
result = subprocess.run( # nosec B603
|
||||||
|
cmd,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
raise TeaCLIError(f"tea binary not found ('{self._tea}'). Install tea or add it to PATH.") from e
|
||||||
|
if result.returncode != 0:
|
||||||
|
parts = [
|
||||||
|
f"tea command failed (rc={result.returncode}): {' '.join(args)}",
|
||||||
|
f"stdout: {result.stdout.strip()}" if result.stdout.strip() else "",
|
||||||
|
f"stderr: {result.stderr.strip()}" if result.stderr.strip() else "",
|
||||||
|
]
|
||||||
|
msg = "\n".join(p for p in parts if p)
|
||||||
|
combined = f"{result.stdout} {result.stderr}".lower()
|
||||||
|
if any(str(code) in combined for code in RETRY_STATUS_CODES):
|
||||||
|
raise _TransientTeaError(msg)
|
||||||
|
raise TeaCLIError(msg)
|
||||||
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
retry_decorator = retry(
|
||||||
|
stop=stop_after_attempt(MAX_RETRIES),
|
||||||
|
wait=wait_exponential(
|
||||||
|
multiplier=RETRY_BACKOFF_BASE,
|
||||||
|
min=RETRY_BACKOFF_BASE,
|
||||||
|
max=RETRY_BACKOFF_BASE**MAX_RETRIES,
|
||||||
|
),
|
||||||
|
retry=retry_if_exception_type(_TransientTeaError),
|
||||||
|
before_sleep=before_sleep_log(logger, logging.WARNING),
|
||||||
|
reraise=True,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
result = subprocess.run( # nosec B603
|
return retry_decorator(_execute)()
|
||||||
cmd,
|
except _TransientTeaError as e:
|
||||||
capture_output=True,
|
raise TeaCLIError(str(e)) from e
|
||||||
text=True,
|
|
||||||
check=False,
|
|
||||||
)
|
|
||||||
except FileNotFoundError as e:
|
|
||||||
raise TeaCLIError(f"tea binary not found ('{self._tea}'). Install tea or add it to PATH.") from e
|
|
||||||
if result.returncode != 0:
|
|
||||||
raise TeaCLIError(
|
|
||||||
f"tea command failed (rc={result.returncode}): {' '.join(args)}\nstderr: {result.stderr.strip()}"
|
|
||||||
)
|
|
||||||
return result.stdout.strip()
|
|
||||||
|
|
||||||
def _run_raw(self, args: list[str]) -> str:
|
def _run_raw(self, args: list[str]) -> str:
|
||||||
"""Run a tea command without JSON output and return stdout."""
|
"""Run a tea command without JSON output and return stdout."""
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ devx-lint: devx-lint-ruff devx-lint-format devx-typecheck devx-lint-bandit devx-
|
|||||||
# ── Testing ───────────────────────────────────────────────────────────────────
|
# ── Testing ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
devx-test-unit:
|
devx-test-unit:
|
||||||
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -q --no-cov
|
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -q --no-cov -n 8
|
||||||
|
|
||||||
devx-pytest-cov:
|
devx-pytest-cov:
|
||||||
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -n auto --cov=$(DEVX_COV_PKG) --cov-report=term-missing --cov-fail-under=100
|
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -n auto --cov=$(DEVX_COV_PKG) --cov-report=term-missing --cov-fail-under=100
|
||||||
|
|||||||
@@ -65,8 +65,14 @@ def _ensure_target_dir() -> Path:
|
|||||||
|
|
||||||
|
|
||||||
def _download(url: str, dest: Path) -> None:
|
def _download(url: str, dest: Path) -> None:
|
||||||
"""Download a file from ``url`` to ``dest``."""
|
"""Download a file from ``url`` to ``dest`` with a 60s timeout.
|
||||||
urllib.request.urlretrieve(url, dest) # nosec B310
|
|
||||||
|
A User-Agent header is set because some CDNs (e.g. dl.gitea.com)
|
||||||
|
return 403 to requests with Python's default User-Agent.
|
||||||
|
"""
|
||||||
|
req = urllib.request.Request(url, headers={"User-Agent": "devx/install-tools"})
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as resp, open(dest, "wb") as f: # nosec B310
|
||||||
|
shutil.copyfileobj(resp, f)
|
||||||
|
|
||||||
|
|
||||||
def _download_and_extract_tarball(url: str, binary_name: str) -> Path:
|
def _download_and_extract_tarball(url: str, binary_name: str) -> Path:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Unit tests for scripts/gitea_cli.py."""
|
"""Unit tests for devx/gitea_cli.py."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@@ -7,7 +7,13 @@ from unittest.mock import MagicMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from devx.gitea_cli import TeaCLI, TeaCLIError, _extract_issue_number, _extract_pr_number, configure_tea_login
|
from devx.gitea_cli import (
|
||||||
|
TeaCLI,
|
||||||
|
TeaCLIError,
|
||||||
|
_extract_issue_number,
|
||||||
|
_extract_pr_number,
|
||||||
|
configure_tea_login,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestExtractIssueNumber:
|
class TestExtractIssueNumber:
|
||||||
@@ -77,6 +83,25 @@ class TestTeaCLIRun:
|
|||||||
with pytest.raises(TeaCLIError, match="auth error"):
|
with pytest.raises(TeaCLIError, match="auth error"):
|
||||||
cli._run(["labels", "list"])
|
cli._run(["labels", "list"])
|
||||||
|
|
||||||
|
def test_run_failure_includes_stdout(self) -> None:
|
||||||
|
"""tea writes some errors to stdout (e.g. 'no available login')."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
mock_result = MagicMock(returncode=1, stdout="no available login", stderr="")
|
||||||
|
with patch("subprocess.run", return_value=mock_result):
|
||||||
|
with pytest.raises(TeaCLIError, match="no available login"):
|
||||||
|
cli._run(["releases", "create"])
|
||||||
|
|
||||||
|
def test_run_failure_includes_both_stdout_and_stderr(self) -> None:
|
||||||
|
"""When both stdout and stderr have content, both are included."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
mock_result = MagicMock(returncode=1, stdout="partial error", stderr="auth error")
|
||||||
|
with patch("subprocess.run", return_value=mock_result):
|
||||||
|
with pytest.raises(TeaCLIError, match="partial error"):
|
||||||
|
cli._run(["labels", "list"])
|
||||||
|
with patch("subprocess.run", return_value=mock_result):
|
||||||
|
with pytest.raises(TeaCLIError, match="auth error"):
|
||||||
|
cli._run(["labels", "list"])
|
||||||
|
|
||||||
def test_run_tea_not_found_raises_tea_error(self) -> None:
|
def test_run_tea_not_found_raises_tea_error(self) -> None:
|
||||||
cli = TeaCLI(tea_bin="tea")
|
cli = TeaCLI(tea_bin="tea")
|
||||||
with patch("subprocess.run", side_effect=FileNotFoundError("tea not found")):
|
with patch("subprocess.run", side_effect=FileNotFoundError("tea not found")):
|
||||||
@@ -100,6 +125,46 @@ class TestTeaCLIRun:
|
|||||||
cmd = mock_run.call_args[0][0]
|
cmd = mock_run.call_args[0][0]
|
||||||
assert "--output" not in cmd
|
assert "--output" not in cmd
|
||||||
|
|
||||||
|
def test_run_retries_on_502(self) -> None:
|
||||||
|
"""Transient 502 errors should be retried, then succeed."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="", stderr="502 Bad Gateway")
|
||||||
|
success_result = MagicMock(returncode=0, stdout='[{"id": 1}]', stderr="")
|
||||||
|
with patch("subprocess.run", side_effect=[fail_result, success_result]) as mock_run:
|
||||||
|
with patch("tenacity.nap.time.sleep"):
|
||||||
|
output = cli._run(["labels", "list"])
|
||||||
|
assert output == '[{"id": 1}]'
|
||||||
|
assert mock_run.call_count == 2
|
||||||
|
|
||||||
|
def test_run_retries_on_503_then_fails(self) -> None:
|
||||||
|
"""If all retries are exhausted on 503, raise TeaCLIError."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="", stderr="503 Service Unavailable")
|
||||||
|
with patch("subprocess.run", return_value=fail_result):
|
||||||
|
with patch("tenacity.nap.time.sleep"):
|
||||||
|
with pytest.raises(TeaCLIError, match="503"):
|
||||||
|
cli._run(["issues", "create"])
|
||||||
|
# MAX_RETRIES=3, so 3 attempts total
|
||||||
|
|
||||||
|
def test_run_no_retry_on_non_transient_error(self) -> None:
|
||||||
|
"""Non-transient errors (e.g. auth) should fail immediately without retry."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="", stderr="auth error")
|
||||||
|
with patch("subprocess.run", return_value=fail_result) as mock_run:
|
||||||
|
with pytest.raises(TeaCLIError, match="auth error"):
|
||||||
|
cli._run(["labels", "list"])
|
||||||
|
assert mock_run.call_count == 1
|
||||||
|
|
||||||
|
def test_run_retries_on_429_in_stdout(self) -> None:
|
||||||
|
"""429 rate limit in stdout should trigger retry."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="429 Too Many Requests", stderr="")
|
||||||
|
success_result = MagicMock(returncode=0, stdout="ok", stderr="")
|
||||||
|
with patch("subprocess.run", side_effect=[fail_result, success_result]):
|
||||||
|
with patch("tenacity.nap.time.sleep"):
|
||||||
|
output = cli._run(["releases", "create"])
|
||||||
|
assert output == "ok"
|
||||||
|
|
||||||
|
|
||||||
class TestRepoArg:
|
class TestRepoArg:
|
||||||
def test_with_repo_arg(self) -> None:
|
def test_with_repo_arg(self) -> None:
|
||||||
@@ -380,9 +445,11 @@ class TestConfigureTeaLogin:
|
|||||||
def test_configures_login_when_not_present(self, mock_subprocess: MagicMock, mock_which: MagicMock) -> None:
|
def test_configures_login_when_not_present(self, mock_subprocess: MagicMock, mock_which: MagicMock) -> None:
|
||||||
"""configure_tea_login adds login when not already configured."""
|
"""configure_tea_login adds login when not already configured."""
|
||||||
mock_list = MagicMock(returncode=0, stdout="")
|
mock_list = MagicMock(returncode=0, stdout="")
|
||||||
mock_subprocess.return_value = mock_list
|
mock_add = MagicMock(returncode=0, stdout="Login successful", stderr="")
|
||||||
|
mock_default = MagicMock(returncode=0, stdout="", stderr="")
|
||||||
|
mock_subprocess.side_effect = [mock_list, mock_add, mock_default]
|
||||||
configure_tea_login()
|
configure_tea_login()
|
||||||
assert mock_subprocess.call_count >= 2 # login list + login add + login default
|
assert mock_subprocess.call_count == 3 # login list + login add + login default
|
||||||
|
|
||||||
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
|
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
|
||||||
@patch("devx.gitea_cli.shutil.which", return_value="/usr/bin/tea")
|
@patch("devx.gitea_cli.shutil.which", return_value="/usr/bin/tea")
|
||||||
@@ -393,3 +460,37 @@ class TestConfigureTeaLogin:
|
|||||||
mock_subprocess.return_value = mock_list
|
mock_subprocess.return_value = mock_list
|
||||||
configure_tea_login()
|
configure_tea_login()
|
||||||
assert mock_subprocess.call_count == 1 # only login list, no add
|
assert mock_subprocess.call_count == 1 # only login list, no add
|
||||||
|
|
||||||
|
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
|
||||||
|
@patch("devx.gitea_cli.shutil.which", return_value="/usr/bin/tea")
|
||||||
|
@patch("devx.gitea_cli.subprocess.run")
|
||||||
|
def test_raises_on_login_add_failure(self, mock_subprocess: MagicMock, mock_which: MagicMock) -> None:
|
||||||
|
"""configure_tea_login raises TeaCLIError if tea login add fails."""
|
||||||
|
mock_list = MagicMock(returncode=0, stdout="")
|
||||||
|
mock_add = MagicMock(returncode=1, stdout="", stderr="invalid token")
|
||||||
|
mock_subprocess.side_effect = [mock_list, mock_add]
|
||||||
|
with pytest.raises(TeaCLIError, match="login add failed"):
|
||||||
|
configure_tea_login()
|
||||||
|
|
||||||
|
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
|
||||||
|
@patch("devx.gitea_cli.shutil.which", return_value="/usr/bin/tea")
|
||||||
|
@patch("devx.gitea_cli.subprocess.run")
|
||||||
|
def test_raises_on_login_default_failure(self, mock_subprocess: MagicMock, mock_which: MagicMock) -> None:
|
||||||
|
"""configure_tea_login raises TeaCLIError if tea login default fails."""
|
||||||
|
mock_list = MagicMock(returncode=0, stdout="")
|
||||||
|
mock_add = MagicMock(returncode=0, stdout="Login successful", stderr="")
|
||||||
|
mock_default = MagicMock(returncode=1, stdout="", stderr="login not found")
|
||||||
|
mock_subprocess.side_effect = [mock_list, mock_add, mock_default]
|
||||||
|
with pytest.raises(TeaCLIError, match="login default failed"):
|
||||||
|
configure_tea_login()
|
||||||
|
|
||||||
|
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
|
||||||
|
@patch("devx.gitea_cli.shutil.which", return_value="/usr/bin/tea")
|
||||||
|
@patch("devx.gitea_cli.subprocess.run")
|
||||||
|
def test_login_add_failure_includes_stdout(self, mock_subprocess: MagicMock, mock_which: MagicMock) -> None:
|
||||||
|
"""Error message includes stdout when tea writes errors there."""
|
||||||
|
mock_list = MagicMock(returncode=0, stdout="")
|
||||||
|
mock_add = MagicMock(returncode=1, stdout="Error: invalid username", stderr="")
|
||||||
|
mock_subprocess.side_effect = [mock_list, mock_add]
|
||||||
|
with pytest.raises(TeaCLIError, match="invalid username"):
|
||||||
|
configure_tea_login()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@@ -47,13 +48,29 @@ class TestDownload:
|
|||||||
def test_download(self, tmp_path: Path) -> None:
|
def test_download(self, tmp_path: Path) -> None:
|
||||||
dest = tmp_path / "file.bin"
|
dest = tmp_path / "file.bin"
|
||||||
|
|
||||||
def _write_file(url: str, path: Path) -> tuple[str, None]:
|
class _FakeResponse:
|
||||||
Path(path).write_bytes(b"data")
|
def __init__(self) -> None:
|
||||||
return str(path), None
|
self._sent = False
|
||||||
|
|
||||||
with patch("urllib.request.urlretrieve", side_effect=_write_file) as mock_retrieve:
|
def __enter__(self) -> _FakeResponse:
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *args: object) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def read(self, n: int = -1) -> bytes:
|
||||||
|
if self._sent:
|
||||||
|
return b""
|
||||||
|
self._sent = True
|
||||||
|
return b"data"
|
||||||
|
|
||||||
|
with patch("urllib.request.urlopen", return_value=_FakeResponse()) as mock_urlopen:
|
||||||
install_tools._download("https://example.com/file", dest)
|
install_tools._download("https://example.com/file", dest)
|
||||||
mock_retrieve.assert_called_once()
|
mock_urlopen.assert_called_once()
|
||||||
|
call_args = mock_urlopen.call_args
|
||||||
|
req = call_args.args[0]
|
||||||
|
assert isinstance(req, urllib.request.Request)
|
||||||
|
assert req.get_header("User-agent") == "devx/install-tools"
|
||||||
assert dest.read_bytes() == b"data"
|
assert dest.read_bytes() == b"data"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -387,8 +387,10 @@ class TestMain:
|
|||||||
@patch("devx.ci.publish.TeaCLI")
|
@patch("devx.ci.publish.TeaCLI")
|
||||||
@patch("devx.ci.publish.publish_to_pypi")
|
@patch("devx.ci.publish.publish_to_pypi")
|
||||||
@patch("devx.ci.publish.build_package")
|
@patch("devx.ci.publish.build_package")
|
||||||
|
@patch("time.sleep")
|
||||||
def test_release_failure_raises_click(
|
def test_release_failure_raises_click(
|
||||||
self,
|
self,
|
||||||
|
mock_sleep: MagicMock,
|
||||||
mock_build: MagicMock,
|
mock_build: MagicMock,
|
||||||
mock_publish: MagicMock,
|
mock_publish: MagicMock,
|
||||||
mock_tea_cls: MagicMock,
|
mock_tea_cls: MagicMock,
|
||||||
@@ -397,6 +399,7 @@ class TestMain:
|
|||||||
mock_tag: MagicMock,
|
mock_tag: MagicMock,
|
||||||
mock_login: MagicMock,
|
mock_login: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""Release creation failure after retries raises ClickException."""
|
||||||
mock_tea = MagicMock()
|
mock_tea = MagicMock()
|
||||||
mock_tea.list_releases.return_value = []
|
mock_tea.list_releases.return_value = []
|
||||||
mock_tea.create_release.side_effect = TeaCLIError("server error")
|
mock_tea.create_release.side_effect = TeaCLIError("server error")
|
||||||
@@ -405,6 +408,8 @@ class TestMain:
|
|||||||
result = runner.invoke(main, ["v1.0.0", "owner/repo"])
|
result = runner.invoke(main, ["v1.0.0", "owner/repo"])
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
assert "Release creation failed" in result.output
|
assert "Release creation failed" in result.output
|
||||||
|
# Retried 3 times (stop_after_attempt(3))
|
||||||
|
assert mock_tea.create_release.call_count == 3
|
||||||
|
|
||||||
@patch("devx.ci.publish.subprocess.run")
|
@patch("devx.ci.publish.subprocess.run")
|
||||||
@patch("devx.ci.publish.get_latest_tag", return_value="v0.1.0")
|
@patch("devx.ci.publish.get_latest_tag", return_value="v0.1.0")
|
||||||
@@ -496,8 +501,10 @@ class TestMain:
|
|||||||
@patch("devx.ci.publish.publish_to_gitea_registry")
|
@patch("devx.ci.publish.publish_to_gitea_registry")
|
||||||
@patch("devx.ci.publish.publish_to_pypi")
|
@patch("devx.ci.publish.publish_to_pypi")
|
||||||
@patch("devx.ci.publish.build_package")
|
@patch("devx.ci.publish.build_package")
|
||||||
|
@patch("time.sleep")
|
||||||
def test_create_release_already_exists_is_idempotent(
|
def test_create_release_already_exists_is_idempotent(
|
||||||
self,
|
self,
|
||||||
|
mock_sleep: MagicMock,
|
||||||
mock_build: MagicMock,
|
mock_build: MagicMock,
|
||||||
mock_publish: MagicMock,
|
mock_publish: MagicMock,
|
||||||
mock_gitea_pub: MagicMock,
|
mock_gitea_pub: MagicMock,
|
||||||
@@ -507,7 +514,7 @@ class TestMain:
|
|||||||
mock_tag: MagicMock,
|
mock_tag: MagicMock,
|
||||||
mock_login: MagicMock,
|
mock_login: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""If create_release fails with 'already exists', treat as success."""
|
"""If create_release fails with 'already exists', treat as success (no retry)."""
|
||||||
mock_tea = MagicMock()
|
mock_tea = MagicMock()
|
||||||
mock_tea.list_releases.side_effect = TeaCLIError("api error")
|
mock_tea.list_releases.side_effect = TeaCLIError("api error")
|
||||||
mock_tea.create_release.side_effect = TeaCLIError("there is already a release for this tag")
|
mock_tea.create_release.side_effect = TeaCLIError("there is already a release for this tag")
|
||||||
@@ -516,6 +523,8 @@ class TestMain:
|
|||||||
result = runner.invoke(main, ["v1.0.0", "owner/repo"])
|
result = runner.invoke(main, ["v1.0.0", "owner/repo"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "already exists" in result.output
|
assert "already exists" in result.output
|
||||||
|
# "already exists" is caught immediately — no retry
|
||||||
|
assert mock_tea.create_release.call_count == 1
|
||||||
|
|
||||||
@patch("devx.ci.publish.subprocess.run")
|
@patch("devx.ci.publish.subprocess.run")
|
||||||
@patch("devx.ci.publish.get_latest_tag", return_value="v0.1.0")
|
@patch("devx.ci.publish.get_latest_tag", return_value="v0.1.0")
|
||||||
@@ -526,8 +535,10 @@ class TestMain:
|
|||||||
@patch("devx.ci.publish.publish_to_gitea_registry")
|
@patch("devx.ci.publish.publish_to_gitea_registry")
|
||||||
@patch("devx.ci.publish.publish_to_pypi")
|
@patch("devx.ci.publish.publish_to_pypi")
|
||||||
@patch("devx.ci.publish.build_package")
|
@patch("devx.ci.publish.build_package")
|
||||||
|
@patch("time.sleep")
|
||||||
def test_create_release_other_error_raises(
|
def test_create_release_other_error_raises(
|
||||||
self,
|
self,
|
||||||
|
mock_sleep: MagicMock,
|
||||||
mock_build: MagicMock,
|
mock_build: MagicMock,
|
||||||
mock_publish: MagicMock,
|
mock_publish: MagicMock,
|
||||||
mock_gitea_pub: MagicMock,
|
mock_gitea_pub: MagicMock,
|
||||||
@@ -537,7 +548,7 @@ class TestMain:
|
|||||||
mock_tag: MagicMock,
|
mock_tag: MagicMock,
|
||||||
mock_login: MagicMock,
|
mock_login: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""If create_release fails with a non-'already exists' error, raise."""
|
"""If create_release fails with a non-'already exists' error, raise after retries."""
|
||||||
mock_tea = MagicMock()
|
mock_tea = MagicMock()
|
||||||
mock_tea.list_releases.side_effect = TeaCLIError("api error")
|
mock_tea.list_releases.side_effect = TeaCLIError("api error")
|
||||||
mock_tea.create_release.side_effect = TeaCLIError("network error")
|
mock_tea.create_release.side_effect = TeaCLIError("network error")
|
||||||
@@ -546,6 +557,75 @@ class TestMain:
|
|||||||
result = runner.invoke(main, ["v1.0.0", "owner/repo"])
|
result = runner.invoke(main, ["v1.0.0", "owner/repo"])
|
||||||
assert result.exit_code != 0
|
assert result.exit_code != 0
|
||||||
assert "Release creation failed" in result.output
|
assert "Release creation failed" in result.output
|
||||||
|
# Retried 3 times before giving up
|
||||||
|
assert mock_tea.create_release.call_count == 3
|
||||||
|
|
||||||
|
|
||||||
|
class TestReleaseRetry:
|
||||||
|
"""Tests for retry logic on transient release creation failures."""
|
||||||
|
|
||||||
|
@patch("devx.ci.publish.subprocess.run")
|
||||||
|
@patch("devx.ci.publish.get_latest_tag", return_value="v0.1.0")
|
||||||
|
@patch("devx.gitea_cli.configure_tea_login")
|
||||||
|
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "gitea-tok"})
|
||||||
|
@patch("devx.ci.publish.generate_release_notes", return_value="Release notes")
|
||||||
|
@patch("devx.ci.publish.TeaCLI")
|
||||||
|
@patch("devx.ci.publish.build_package")
|
||||||
|
@patch("time.sleep")
|
||||||
|
def test_transient_failure_retried_and_succeeds(
|
||||||
|
self,
|
||||||
|
mock_sleep: MagicMock,
|
||||||
|
mock_build: MagicMock,
|
||||||
|
mock_tea_cls: MagicMock,
|
||||||
|
mock_notes: MagicMock,
|
||||||
|
mock_run: MagicMock,
|
||||||
|
mock_tag: MagicMock,
|
||||||
|
mock_login: MagicMock,
|
||||||
|
) -> None:
|
||||||
|
"""Transient failure on first attempt succeeds on retry."""
|
||||||
|
mock_tea = MagicMock()
|
||||||
|
mock_tea.list_releases.return_value = []
|
||||||
|
mock_tea.create_release.side_effect = [
|
||||||
|
TeaCLIError("connection timeout"),
|
||||||
|
None, # second attempt succeeds
|
||||||
|
]
|
||||||
|
mock_tea_cls.return_value = mock_tea
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["v1.0.0", "owner/repo", "--skip-build"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Gitea release v1.0.0 created" in result.output
|
||||||
|
assert mock_tea.create_release.call_count == 2
|
||||||
|
mock_sleep.assert_called() # slept between attempts
|
||||||
|
|
||||||
|
@patch("devx.ci.publish.subprocess.run")
|
||||||
|
@patch("devx.ci.publish.get_latest_tag", return_value="v0.1.0")
|
||||||
|
@patch("devx.gitea_cli.configure_tea_login")
|
||||||
|
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "gitea-tok"})
|
||||||
|
@patch("devx.ci.publish.generate_release_notes", return_value="Release notes")
|
||||||
|
@patch("devx.ci.publish.TeaCLI")
|
||||||
|
@patch("devx.ci.publish.build_package")
|
||||||
|
@patch("time.sleep")
|
||||||
|
def test_all_retries_exhausted_raises(
|
||||||
|
self,
|
||||||
|
mock_sleep: MagicMock,
|
||||||
|
mock_build: MagicMock,
|
||||||
|
mock_tea_cls: MagicMock,
|
||||||
|
mock_notes: MagicMock,
|
||||||
|
mock_run: MagicMock,
|
||||||
|
mock_tag: MagicMock,
|
||||||
|
mock_login: MagicMock,
|
||||||
|
) -> None:
|
||||||
|
"""All 3 retry attempts fail — raises ClickException."""
|
||||||
|
mock_tea = MagicMock()
|
||||||
|
mock_tea.list_releases.return_value = []
|
||||||
|
mock_tea.create_release.side_effect = TeaCLIError("503 service unavailable")
|
||||||
|
mock_tea_cls.return_value = mock_tea
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["v1.0.0", "owner/repo", "--skip-build"])
|
||||||
|
assert result.exit_code == 1
|
||||||
|
assert "Release creation failed" in result.output
|
||||||
|
assert mock_tea.create_release.call_count == 3
|
||||||
|
assert mock_sleep.call_count == 2 # slept between 3 attempts (2 sleeps)
|
||||||
|
|
||||||
|
|
||||||
class TestFromTag:
|
class TestFromTag:
|
||||||
|
|||||||
Reference in New Issue
Block a user