From 0717d5cf42c900b142c913ba3a10aea85839c607 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 24 Apr 2026 14:41:09 +0300 Subject: [PATCH] Add TDLib packaging and release scripts --- README.md | 50 +++++++++++++ scripts/package-tdlib.sh | 42 +++++++++++ scripts/publish-release.sh | 139 +++++++++++++++++++++++++++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 README.md create mode 100755 scripts/package-tdlib.sh create mode 100755 scripts/publish-release.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ea4266 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# shinoa-tdlib + +Prebuilt TDLib bundles used by `shinoa`. + +## Bundle Format + +Release assets are expected to contain a top-level `tdlib/` directory with: + +- `tdlib/include/` +- `tdlib/lib/` + +At minimum, the app build expects: + +- `tdlib/include/td/telegram/td_json_client.h` +- `tdlib/include/td/telegram/tdjson_export.h` +- `tdlib/lib/libtdjson.so` +- `tdlib/lib/libtdjson.so.` + +## Build Locally + +Build and install TDLib somewhere on your local machine: + +```bash +cmake -S /path/to/tdlib -B td-build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$PWD/td-install" +cmake --build td-build -j"$(nproc)" +cmake --install td-build +``` + +Package it into the expected archive format: + +```bash +./scripts/package-tdlib.sh td-install tdlib-linux-x86_64.tar.gz +``` + +## Publish Release + +Publish the archive and checksum to a versioned release tag derived from the TDLib soname, +for example `v1.8.63`: + +```bash +./scripts/publish-release.sh tdlib-linux-x86_64.tar.gz +``` + +By default the script derives the tag from the archive contents. You can override it: + +```bash +RELEASE_TAG=v1.8.63 ./scripts/publish-release.sh tdlib-linux-x86_64.tar.gz +``` diff --git a/scripts/package-tdlib.sh b/scripts/package-tdlib.sh new file mode 100755 index 0000000..104b63c --- /dev/null +++ b/scripts/package-tdlib.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then + echo "usage: $0 [output-tar.gz]" >&2 + exit 1 +fi + +tdlib_root="$(realpath "$1")" +output_path="${2:-tdlib-linux-x86_64.tar.gz}" +output_path="$(realpath -m "$output_path")" + +include_dir="$tdlib_root/include" +lib_dir="$tdlib_root/lib" + +if [ ! -f "$include_dir/td/telegram/td_json_client.h" ]; then + echo "missing TDLib header: $include_dir/td/telegram/td_json_client.h" >&2 + exit 1 +fi + +if [ ! -f "$include_dir/td/telegram/tdjson_export.h" ]; then + echo "missing TDLib export header: $include_dir/td/telegram/tdjson_export.h" >&2 + exit 1 +fi + +if ! compgen -G "$lib_dir/libtdjson.so*" >/dev/null; then + echo "missing TDLib shared library under: $lib_dir" >&2 + exit 1 +fi + +workdir="$(mktemp -d)" +trap 'rm -rf "$workdir"' EXIT + +mkdir -p "$workdir/tdlib" +cp -a "$include_dir" "$workdir/tdlib/include" +cp -a "$lib_dir" "$workdir/tdlib/lib" + +tar -C "$workdir" -czf "$output_path" tdlib +sha256sum "$output_path" > "${output_path}.sha256" + +echo "wrote $output_path" +echo "wrote ${output_path}.sha256" diff --git a/scripts/publish-release.sh b/scripts/publish-release.sh new file mode 100755 index 0000000..677fc2e --- /dev/null +++ b/scripts/publish-release.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ "$#" -ne 1 ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +archive="$(realpath "$1")" +checksum="${archive}.sha256" + +if [ ! -f "$archive" ]; then + echo "archive not found: $archive" >&2 + exit 1 +fi + +if [ ! -f "$checksum" ]; then + echo "checksum not found: $checksum" >&2 + exit 1 +fi + +REPO_SLUG="${REPO_SLUG:-AxiFisk/shinoa-tdlib}" +SERVER_URL="${SERVER_URL:-https://git.mshq.dev}" +tdlib_version="$( + tar -xOf "$archive" tdlib/lib/libtdjson.so 2>/dev/null | + strings | rg -o 'Td::TdJson [0-9]+\.[0-9]+\.[0-9]+' -m1 | + awk '{print $2}' || true +)" +if [ -z "$tdlib_version" ]; then + tdlib_version="$(basename "$(tar -tzf "$archive" | rg 'tdlib/lib/libtdjson\.so\.[0-9]+\.[0-9]+\.[0-9]+$' -m1)" | sed 's/^libtdjson\.so\.//')" +fi +if [ -z "$tdlib_version" ]; then + echo "failed to determine TDLib version from $archive" >&2 + exit 1 +fi + +RELEASE_TAG="${RELEASE_TAG:-v${tdlib_version}}" +RELEASE_NAME="${RELEASE_NAME:-TDLib ${tdlib_version}}" + +if [ -n "${GITEA_TOKEN:-}" ]; then + auth_header=(-H "Authorization: token ${GITEA_TOKEN}") +else + cred_data="$( + printf 'protocol=https\nhost=%s\npath=%s.git\n\n' \ + "${SERVER_URL#https://}" \ + "$REPO_SLUG" | git credential fill + )" + username="$(printf '%s\n' "$cred_data" | awk -F= '$1=="username"{print $2}')" + password="$(printf '%s\n' "$cred_data" | awk -F= '$1=="password"{print $2}')" + if [ -z "$username" ] || [ -z "$password" ]; then + echo "failed to resolve credentials for $SERVER_URL/$REPO_SLUG" >&2 + exit 1 + fi + auth_header=(-u "${username}:${password}") +fi + +api="${SERVER_URL}/api/v1/repos/${REPO_SLUG}" +release_json="$(mktemp)" +body_file="$(mktemp)" +trap 'rm -f "$release_json" "$body_file"' EXIT + +cat > "$body_file" <&2 + cat "$release_json" >&2 + exit 1 +fi + +status="$( + curl --silent --show-error \ + --output /dev/null \ + --write-out "%{http_code}" \ + "${auth_header[@]}" \ + -X DELETE \ + "$api/tags/$RELEASE_TAG" +)" +case "$status" in + 204|404) ;; + *) + echo "failed to delete tag $RELEASE_TAG, HTTP $status" >&2 + exit 1 + ;; +esac + +default_branch="$(git remote show origin | awk '/HEAD branch/ {print $NF}')" +default_branch="${default_branch:-main}" +commit_sha="$(git rev-parse "origin/${default_branch}")" + +curl --fail-with-body \ + "${auth_header[@]}" \ + -H "Content-Type: application/json" \ + -X POST \ + -d @- \ + "$api/releases" > "$release_json" <