adff
Prompt
#!/usr/bin/env bash # Download StreamApp and Management Console snapshot releases, then build # target/ant-media-server-community.zip. # # ./make_release2.sh full release zip # ./make_release2.sh --fetch-only install the WAR and stage the console for Maven # # Uses snapshot-<branch>, or snapshot-master when that release does not exist. # Set DEPENDENCY_CHECKOUT_TOKEN (CI environment "CI Env"), or sign in with gh. set -euo pipefail STREAMAPP_REPO="${STREAMAPP_REPOSITORY:-VaslSH/StreamApp}" CONSOLE_REPO="${CONSOLE_REPOSITORY:-VaslSH/Management-Console}" FALLBACK_BRANCH="${DEPENDENCY_FALLBACK_BRANCH:-master}" die() { printf '%s\n' "$*" >&2 exit 1 } need() { command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1" } current_branch() { if [ -n "${BRANCH_NAME:-}" ]; then printf '%s' "$BRANCH_NAME" elif [ -n "${GITHUB_HEAD_REF:-}" ]; then printf '%s' "$GITHUB_HEAD_REF" elif [ "${GITHUB_REF_TYPE:-}" = "branch" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then printf '%s' "$GITHUB_REF_NAME" else local branch branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)" if [ -n "$branch" ] && [ "$branch" != "HEAD" ]; then printf '%s' "$branch" else printf '%s' "$FALLBACK_BRANCH" fi fi } release_code() { local repo="$1" tag="$2" dest="$3" encoded encoded="$(python3 -c 'import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=""))' "$tag")" curl -sS -o "$dest" -w '%{http_code}' \ -H "Authorization: Bearer ${DEPENDENCY_CHECKOUT_TOKEN}" \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${repo}/releases/tags/${encoded}" || true } # Return 0 when the release exists, 1 when it is missing, exit on auth or network errors. release_ok() { local code="$1" repo="$2" tag="$3" case "$code" in 200) return 0 ;; 404) return 1 ;; 000|"") die "Could not reach the GitHub API for ${repo}." ;; 401) die "GitHub rejected DEPENDENCY_CHECKOUT_TOKEN (HTTP 401) for ${repo}." ;; 403) die "DEPENDENCY_CHECKOUT_TOKEN cannot access ${repo} (HTTP 403). If the organization uses SAML SSO, authorize the token for that organization." ;; *) die "Unexpected GitHub API status ${code} for ${repo} release ${tag}." ;; esac } # Print the tag that exists: the branch snapshot, or the master snapshot. choose_release() { local repo="$1" preferred="$2" fallback="$3" json="$4" code code="$(release_code "$repo" "$preferred" "$json")" if release_ok "$code" "$repo" "$preferred"; then echo "Using ${repo} release ${preferred}" >&2 printf '%s' "$preferred" return fi [ "$preferred" = "$fallback" ] && die "Release ${preferred} was not found on ${repo}." echo "Release ${preferred} was not found on ${repo}; trying ${fallback}" >&2 code="$(release_code "$repo" "$fallback" "$json")" release_ok "$code" "$repo" "$fallback" \ || die "Fallback release ${fallback} was not found on ${repo} (HTTP ${code})." echo "Using ${repo} release ${fallback}" >&2 printf '%s' "$fallback" } asset_url() { python3 - "$1" "$2" <<'PY' import json, sys name, path = sys.argv[1], sys.argv[2] with open(path) as handle: release = json.load(handle) for asset in release.get("assets") or []: if asset.get("name") == name: print(asset["url"]) raise SystemExit(0) raise SystemExit(1) PY } download_asset() { local repo="$1" json="$2" name="$3" dest="$4" url url="$(asset_url "$name" "$json")" || die "Release on ${repo} has no asset named ${name}." curl -fL \ -H "Authorization: Bearer ${DEPENDENCY_CHECKOUT_TOKEN}" \ -H "Accept: application/octet-stream" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -o "$dest" \ "$url" unzip -tq "$dest" >/dev/null || die "Downloaded ${name} from ${repo} is not a zip archive." } unpack_console() { local zip_file="$1" dest="$2" unpacked="$work/console-unpacked" rm -rf "$unpacked" mkdir -p "$unpacked" "$dest" unzip -q "$zip_file" -d "$unpacked" if [ -d "$unpacked/dist" ]; then cp -a "$unpacked/dist/." "$dest/" else cp -a "$unpacked/." "$dest/" fi if [ ! -f "$dest/index.html" ]; then find "$unpacked" -maxdepth 3 -type f >&2 die "Management console archive has no index.html." fi } install_streamapp() { local war="$1" version version="$(sed -n '/<parent>/,/<\/parent>/{s/.*<version>\([^<]*\)<\/version>.*/\1/p;}' pom.xml)" version="${version%%$'\n'*}" [ -n "$version" ] || die "Could not read the parent version from pom.xml." echo "Installing StreamApp ${version} into the local Maven repository" mvn -B install:install-file \ -Dfile="$war" \ -DgroupId=io.antmedia.webrtc \ -DartifactId=StreamApp \ -Dversion="$version" \ -Dpackaging=war } add_native_library() { local native_dir="target/ant-media-server/lib/native" if [ ! -f core/Makefile ] || ! command -v go >/dev/null 2>&1 || [ -z "${JAVA_HOME:-}" ]; then echo "WARNING: skipping native library build; it needs ./core, Go, and JAVA_HOME" >&2 return 0 fi echo "Building native library..." export CGO_CFLAGS="-I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux" (cd core && make) mkdir -p "$native_dir/lib" cp core/build/go_shared_library.so "$native_dir/libjniNativeInterface.so" chmod 0755 "$native_dir/libjniNativeInterface.so" (cd target && zip -r ant-media-server-community.zip ant-media-server/lib/native) } fetch_only=0 case "${1:-}" in "") ;; --fetch-only) fetch_only=1 ;; *) die "Usage: $0 [--fetch-only]" ;; esac [ "$#" -le 1 ] || die "Usage: $0 [--fetch-only]" cd "$(dirname "$0")" need curl need python3 need unzip need mvn if [ -z "${DEPENDENCY_CHECKOUT_TOKEN:-}" ] && command -v gh >/dev/null 2>&1; then DEPENDENCY_CHECKOUT_TOKEN="$(gh auth token 2>/dev/null || true)" fi [ -n "${DEPENDENCY_CHECKOUT_TOKEN:-}" ] || die "DEPENDENCY_CHECKOUT_TOKEN is not set. In CI use environment \"CI Env\". Locally export the token or run gh auth login." work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT branch="$(current_branch)" echo "Selecting StreamApp and Management Console releases for branch ${branch}" choose_release "$STREAMAPP_REPO" \ "snapshot-${branch}" \ "snapshot-${FALLBACK_BRANCH}" \ "$work/streamapp.json" >/dev/null download_asset "$STREAMAPP_REPO" "$work/streamapp.json" StreamApp.war "$work/StreamApp.war" console_tag="$(choose_release "$CONSOLE_REPO" \ "snapshot-${branch}" \ "snapshot-${FALLBACK_BRANCH}" \ "$work/console.json")" console_asset="management-console-${console_tag#snapshot-}.zip" download_asset "$CONSOLE_REPO" "$work/console.json" "$console_asset" "$work/$console_asset" install_streamapp "$work/StreamApp.war" if [ "$fetch_only" -eq 1 ]; then unpack_console "$work/$console_asset" src/main/server/webapps/root echo "Fetched StreamApp and the management console for Maven assemble." exit 0 fi need zip ./repackage_community.sh add_native_library mkdir -p target/ant-media-server/webapps/root unpack_console "$work/$console_asset" target/ant-media-server/webapps/root (cd target && zip -r ant-media-server-community.zip ant-media-server/webapps/root) rm -rf target/ant-media-server echo "Release created: target/ant-media-server-community.zip" the script is too spegetty make it better
Response not available