From dd905ea248b3eac35945dd594da4350c51ed4076 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 24 Apr 2026 14:02:24 +0300 Subject: [PATCH] Add Gitea TDLib build workflow --- .gitea/workflows/build-tdlib.yaml | 164 ++++++++++++++++++++++++++++++ CMakeLists.txt | 24 +---- README.md | 9 +- 3 files changed, 172 insertions(+), 25 deletions(-) create mode 100644 .gitea/workflows/build-tdlib.yaml diff --git a/.gitea/workflows/build-tdlib.yaml b/.gitea/workflows/build-tdlib.yaml new file mode 100644 index 0000000..cccff6c --- /dev/null +++ b/.gitea/workflows/build-tdlib.yaml @@ -0,0 +1,164 @@ +name: Build TDLib + +on: + workflow_dispatch: + inputs: + tdlib_ref: + description: Optional TDLib tag or commit to build + required: false + type: string + schedule: + - cron: "0 3 * * 1" + +permissions: + contents: read + packages: write + +jobs: + build-tdlib: + runs-on: ubuntu-latest + env: + PACKAGE_NAME: tdlib + TDLIB_REPO: https://github.com/tdlib/td.git + steps: + - name: Check out repository + uses: https://github.com/actions/checkout@v4 + + - name: Install build dependencies + run: | + if command -v sudo >/dev/null 2>&1; then + SUDO=sudo + else + SUDO= + fi + + $SUDO apt-get update + $SUDO apt-get install -y \ + build-essential \ + ca-certificates \ + cmake \ + curl \ + git \ + gperf \ + libssl-dev \ + pkg-config \ + zlib1g-dev + + - name: Resolve TDLib ref + id: tdlib + run: | + set -euo pipefail + ref="${{ inputs.tdlib_ref }}" + if [ -z "$ref" ]; then + ref="$(git ls-remote --tags --refs --sort='version:refname' "$TDLIB_REPO" 'v*' | tail -n1 | awk -F/ '{print $3}')" + fi + if [ -z "$ref" ]; then + echo "Failed to resolve TDLib ref" >&2 + exit 1 + fi + + version="$ref" + version="${version#v}" + archive="tdlib-${version}-linux-x86_64.tar.gz" + + { + echo "ref=$ref" + echo "version=$version" + echo "archive=$archive" + } >> "$GITHUB_OUTPUT" + + - name: Build TDLib bundle + run: | + set -euo pipefail + ref="${{ steps.tdlib.outputs.ref }}" + version="${{ steps.tdlib.outputs.version }}" + archive="${{ steps.tdlib.outputs.archive }}" + + rm -rf tdlib-src tdlib-build dist + git clone --depth 1 --branch "$ref" "$TDLIB_REPO" tdlib-src + + cmake -S tdlib-src -B tdlib-build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$PWD/dist/tdlib" \ + -DTD_ENABLE_INSTALL=ON \ + -DTD_ENABLE_JNI=OFF \ + -DTD_ENABLE_DOTNET=OFF \ + -DTD_ENABLE_TESTS=OFF \ + -DTD_ENABLE_BENCHMARKS=OFF + cmake --build tdlib-build -j"$(nproc)" + cmake --install tdlib-build + + tar -C dist -czf "$archive" tdlib + sha256sum "$archive" > "${archive}.sha256" + + - name: Publish TDLib package + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: | + set -euo pipefail + version="${{ steps.tdlib.outputs.version }}" + archive="${{ steps.tdlib.outputs.archive }}" + base="${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/generic/${PACKAGE_NAME}" + + status="$(curl --silent --show-error \ + --output /dev/null \ + --write-out "%{http_code}" \ + --user "${{ gitea.actor }}:${GITEA_TOKEN}" \ + -X DELETE \ + "$base/$version")" + case "$status" in + 204|404) ;; + *) + echo "Unexpected response deleting existing package version: $status" >&2 + exit 1 + ;; + esac + + curl --fail-with-body \ + --user "${{ gitea.actor }}:${GITEA_TOKEN}" \ + --upload-file "$archive" \ + "$base/$version/$archive" + + curl --fail-with-body \ + --user "${{ gitea.actor }}:${GITEA_TOKEN}" \ + --upload-file "${archive}.sha256" \ + "$base/$version/${archive}.sha256" + + - name: Publish latest metadata + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: | + set -euo pipefail + version="${{ steps.tdlib.outputs.version }}" + archive="${{ steps.tdlib.outputs.archive }}" + base="${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/generic/${PACKAGE_NAME}" + latest_manifest="tdlib-latest.json" + + cat > "$latest_manifest" <&2 + exit 1 + ;; + esac + + curl --fail-with-body \ + --user "${{ gitea.actor }}:${GITEA_TOKEN}" \ + --upload-file "$latest_manifest" \ + "$base/latest/$latest_manifest" diff --git a/CMakeLists.txt b/CMakeLists.txt index f9dfa83..5d27cba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,6 @@ find_program(CLANG_FORMAT_BIN clang-format) include(FetchContent) option(TELEGRAM_TUI_USE_SYSTEM_TDLIB "Use an installed TDLib package instead of fetching it." OFF) -set(TELEGRAM_TUI_TDLIB_ROOT "" - CACHE PATH "Path to a prebuilt TDLib root containing include/ and lib/ directories.") set(CURSES_NEED_WIDE TRUE) find_package(Curses REQUIRED) @@ -48,27 +46,7 @@ configure_file( @ONLY ) -if(TELEGRAM_TUI_TDLIB_ROOT) - find_path(TELEGRAM_TUI_TDLIB_INCLUDE_DIR - NAMES td/telegram/td_json_client.h - PATHS "${TELEGRAM_TUI_TDLIB_ROOT}/include" - NO_DEFAULT_PATH - REQUIRED - ) - find_library(TELEGRAM_TUI_TDLIB_LIBRARY - NAMES tdjson libtdjson.so libtdjson.so.1.8.61 - PATHS "${TELEGRAM_TUI_TDLIB_ROOT}/lib" - NO_DEFAULT_PATH - REQUIRED - ) - - add_library(TdJsonPrebuilt SHARED IMPORTED GLOBAL) - set_target_properties(TdJsonPrebuilt PROPERTIES - IMPORTED_LOCATION "${TELEGRAM_TUI_TDLIB_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${TELEGRAM_TUI_TDLIB_INCLUDE_DIR}" - ) - add_library(Td::TdJson ALIAS TdJsonPrebuilt) -elseif(TELEGRAM_TUI_USE_SYSTEM_TDLIB) +if(TELEGRAM_TUI_USE_SYSTEM_TDLIB) find_package(Td REQUIRED) else() set(TD_ENABLE_JNI OFF CACHE BOOL "" FORCE) diff --git a/README.md b/README.md index 6a6f74d..26184e7 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ A minimal Telegram terminal client built with `ncurses` and TDLib. - TDLib build dependencies (`gperf`, `openssl`, `zlib`, `git`) The project vendors TDLib automatically by default. If you already have TDLib installed with CMake package metadata, configure with `-DTELEGRAM_TUI_USE_SYSTEM_TDLIB=ON`. -If you have a prebuilt TDLib bundle with `include/` and `lib/`, configure with -`-DTELEGRAM_TUI_TDLIB_ROOT=/path/to/tdlib`. ## Build @@ -56,6 +54,13 @@ export TELEGRAM_USE_TEST_DC=1 The client stores TDLib state in `~/.local/share/telegram-tui/tdlib` for production and `~/.local/share/telegram-tui/test/tdlib` for test mode. +## Gitea Actions + +The repository includes [`.gitea/workflows/build-tdlib.yaml`](.gitea/workflows/build-tdlib.yaml), +which builds the latest upstream TDLib tag on Gitea Actions and publishes a bundled TDLib +archive plus checksum to the Gitea Generic Package Registry under the `tdlib` package. +It also refreshes a `latest/tdlib-latest.json` manifest with the newest published version. + ## Keys - `Up` / `Down`: move selection