Add TDLib packaging and release scripts

This commit is contained in:
2026-04-24 14:41:09 +03:00
commit 0717d5cf42
3 changed files with 231 additions and 0 deletions

42
scripts/package-tdlib.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "usage: $0 <tdlib-root> [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"

139
scripts/publish-release.sh Executable file
View File

@@ -0,0 +1,139 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -ne 1 ]; then
echo "usage: $0 <tdlib-tar.gz>" >&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" <<EOF
Manual TDLib bundle upload.
EOF
status="$(
curl --silent --show-error \
--output "$release_json" \
--write-out "%{http_code}" \
"${auth_header[@]}" \
"$api/releases/tags/$RELEASE_TAG"
)"
if [ "$status" = "200" ]; then
release_id="$(jq -r '.id' "$release_json")"
jq -r '.assets[]?.id' "$release_json" | while read -r asset_id; do
[ -n "$asset_id" ] || continue
curl --fail-with-body \
"${auth_header[@]}" \
-X DELETE \
"$api/releases/$release_id/assets/$asset_id"
done
curl --fail-with-body \
"${auth_header[@]}" \
-X DELETE \
"$api/releases/tags/$RELEASE_TAG"
elif [ "$status" != "404" ]; then
echo "failed to query release, HTTP $status" >&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" <<EOF
{
"body": $(jq -Rs . < "$body_file"),
"draft": false,
"name": ${RELEASE_NAME@Q},
"prerelease": false,
"tag_name": ${RELEASE_TAG@Q},
"target_commitish": ${commit_sha@Q}
}
EOF
release_id="$(jq -r '.id' "$release_json")"
[ -n "$release_id" ] && [ "$release_id" != "null" ]
for file in "$archive" "$checksum"; do
curl --fail-with-body \
"${auth_header[@]}" \
-F "attachment=@${file}" \
"$api/releases/$release_id/assets?name=$(basename "$file")"
done
echo "published $(basename "$archive") to $SERVER_URL/$REPO_SLUG releases/tag/$RELEASE_TAG"