diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6441c9..f9bc323 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,15 +20,15 @@ jobs: include: - task: format do_sync: true - command: uv run --no-sync ruff format --check --diff + command: uv run --no-sync ruff format --check --diff src tests sync_args: --no-install-project - task: ruff do_sync: true - command: uv run --no-sync ruff check . --output-format=github + command: uv run --no-sync ruff check src tests --output-format=github sync_args: --no-install-project - task: ty do_sync: true - command: uv run --no-sync ty check . + command: uv run --no-sync ty check src tests sync_args: --no-install-project - task: pytest do_sync: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1698451..82ffb8a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -95,6 +95,15 @@ jobs: permissions: contents: write steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + python-version: "3.14" + enable-cache: true + - name: Download dist artifacts uses: actions/download-artifact@v4 with: @@ -107,3 +116,11 @@ jobs: generate_release_notes: true files: | dist/* + + - name: Notify release + run: uv run scripts/release_notify.py + env: + REPO: ${{ github.repository }} + TAG_NAME: ${{ github.ref_name }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} diff --git a/Justfile b/Justfile index 31d84cd..5061beb 100644 --- a/Justfile +++ b/Justfile @@ -1,7 +1,7 @@ check: - uv run ruff format --check - uv run ruff check . - uv run ty check . + uv run ruff format --check src tests + uv run ruff check src tests + uv run ty check src tests uv run pytest bundle: diff --git a/scripts/release_notify.py b/scripts/release_notify.py new file mode 100644 index 0000000..6725d01 --- /dev/null +++ b/scripts/release_notify.py @@ -0,0 +1,49 @@ +# /// script +# requires-python = ">=3.14" +# dependencies = [ +# "mistune>=3.2.0", +# "requests>=2.32.5", +# "sulguk>=0.11.1", +# ] +# /// +import mistune +import sulguk +import requests +import os +import re + +repo = os.environ["REPO"] +tag = os.environ["TAG_NAME"] +bot_token = os.environ["TELEGRAM_BOT_TOKEN"] +chat_id = os.environ["TELEGRAM_CHAT_ID"] + +PULL_RE = re.compile(rf"(https://github.com/{repo}/pull/(\d+))") +COMPARE_RE = re.compile(rf"(https://github.com/{repo}/compare/(.*))") + +resp = requests.get(f"https://api.github.com/repos/{repo}/releases/tags/{tag}") +body = resp.json()["body"] +lines = body.splitlines() + +header = f"release **{repo} {tag}**" +pulls = "\n".join( + [PULL_RE.sub(r"[#\2](\1)", line) for line in lines if PULL_RE.search(line)] +) +compare = COMPARE_RE.sub(r"compare [\2](\1)", COMPARE_RE.search(body).group(0)) + +message = "\n\n".join([header, pulls, compare]) +print(message) + +html = mistune.html(message) +rendered = sulguk.transform_html(html) + +payload = { + "chat_id": chat_id, + "text": rendered.text, + "entities": rendered.entities, + "link_preview_options": {"is_disabled": True}, +} +resp = requests.post( + f"https://api.telegram.org/bot{bot_token}/sendMessage", json=payload +) +resp.raise_for_status() +print(f"\nsent to {chat_id}")