From 92729911318d94d6bb5b4c044ac76b105c226de9 Mon Sep 17 00:00:00 2001 From: Hakan Sariman Date: Mon, 6 Oct 2025 20:18:20 +0700 Subject: [PATCH] fix: improve version normalization in build script --- build-android-lib.sh | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/build-android-lib.sh b/build-android-lib.sh index 0b6cbde..5cdb524 100755 --- a/build-android-lib.sh +++ b/build-android-lib.sh @@ -1,56 +1,68 @@ #!/bin/bash # Script to build NetBird mobile bindings using gomobile # Usage: ./script.sh [version] -# - If a version is provided, it will be used. +# - If a version is provided, it will be used (with leading 'v' stripped if present). # - If no version is provided: -# * Uses the latest Git tag if available. +# * Uses the latest Git tag if available (with leading 'v' stripped if present). # * Otherwise, defaults to "dev-". # - When running in GitHub Actions, uses "ci-" instead of "dev-". -set -e +set -euo pipefail app_path=$(pwd) +# Normalize semantic versions to drop a leading 'v' (e.g., v1.2.3 -> 1.2.3). +# Only strips if the string starts with 'v' followed by a digit, so it won't affect +# dev/ci strings or other non-semver values. +normalize_version() { + local ver="$1" + if [[ "$ver" =~ ^v[0-9] ]]; then + ver="${ver#v}" + fi + echo "$ver" +} get_version() { - if [ -n "$1" ]; then - echo "$1" + if [ -n "${1:-}" ]; then + normalize_version "$1" return fi # Try to get an exact tag - local tag=$(git describe --tags --exact-match 2>/dev/null || true) + local tag + tag=$(git describe --tags --exact-match 2>/dev/null || true) if [ -n "$tag" ]; then - echo "$tag" + normalize_version "$tag" return fi # Fallback to "-" - local short_hash=$(git rev-parse --short HEAD) + local short_hash + short_hash=$(git rev-parse --short HEAD) - if [ "$GITHUB_ACTIONS" == "true" ]; then - local new_version="ci-$short_hash" + local new_version + if [ "${GITHUB_ACTIONS:-}" = "true" ]; then + new_version="ci-$short_hash" else - local new_version="dev-$short_hash" + new_version="dev-$short_hash" fi echo "$new_version" } - cd netbird # Get version using the function -version=$(get_version "$1") +version=$(get_version "${1:-}") echo "Using version: $version" gomobile init CGO_ENABLED=0 gomobile bind \ - -o $app_path/gomobile/netbird.aar \ + -o "$app_path/gomobile/netbird.aar" \ -javapkg=io.netbird.gomobile \ -ldflags="-checklinkname=0 -X golang.zx2c4.com/wireguard/ipc.socketDirectory=/data/data/io.netbird.client/cache/wireguard -X github.com/netbirdio/netbird/version.version=$version" \ - $(pwd)/client/android + "$(pwd)/client/android" cd - > /dev/null