feat(ci): release notify (#94)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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}")
|
||||
Reference in New Issue
Block a user