Add TDLib packaging and release scripts
This commit is contained in:
50
README.md
Normal file
50
README.md
Normal file
@@ -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.<soname>`
|
||||
|
||||
## 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
|
||||
```
|
||||
42
scripts/package-tdlib.sh
Executable file
42
scripts/package-tdlib.sh
Executable 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
139
scripts/publish-release.sh
Executable 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"
|
||||
Reference in New Issue
Block a user