|
1 | 1 | #!/bin/bash |
2 | 2 | # Script to build NetBird mobile bindings using gomobile |
3 | 3 | # Usage: ./script.sh [version] |
4 | | -# - If a version is provided, it will be used. |
| 4 | +# - If a version is provided, it will be used (with leading 'v' stripped if present). |
5 | 5 | # - If no version is provided: |
6 | | -# * Uses the latest Git tag if available. |
| 6 | +# * Uses the latest Git tag if available (with leading 'v' stripped if present). |
7 | 7 | # * Otherwise, defaults to "dev-<short-hash>". |
8 | 8 | # - When running in GitHub Actions, uses "ci-<short-hash>" instead of "dev-<short-hash>". |
9 | 9 |
|
10 | | -set -e |
| 10 | +set -euo pipefail |
11 | 11 |
|
12 | 12 | app_path=$(pwd) |
13 | 13 |
|
| 14 | +# Normalize semantic versions to drop a leading 'v' (e.g., v1.2.3 -> 1.2.3). |
| 15 | +# Only strips if the string starts with 'v' followed by a digit, so it won't affect |
| 16 | +# dev/ci strings or other non-semver values. |
| 17 | +normalize_version() { |
| 18 | + local ver="$1" |
| 19 | + if [[ "$ver" =~ ^v[0-9] ]]; then |
| 20 | + ver="${ver#v}" |
| 21 | + fi |
| 22 | + echo "$ver" |
| 23 | +} |
14 | 24 |
|
15 | 25 | get_version() { |
16 | | - if [ -n "$1" ]; then |
17 | | - echo "$1" |
| 26 | + if [ -n "${1:-}" ]; then |
| 27 | + normalize_version "$1" |
18 | 28 | return |
19 | 29 | fi |
20 | 30 |
|
21 | 31 | # Try to get an exact tag |
22 | | - local tag=$(git describe --tags --exact-match 2>/dev/null || true) |
| 32 | + local tag |
| 33 | + tag=$(git describe --tags --exact-match 2>/dev/null || true) |
23 | 34 |
|
24 | 35 | if [ -n "$tag" ]; then |
25 | | - echo "$tag" |
| 36 | + normalize_version "$tag" |
26 | 37 | return |
27 | 38 | fi |
28 | 39 |
|
29 | 40 | # Fallback to "<prefix>-<short-hash>" |
30 | | - local short_hash=$(git rev-parse --short HEAD) |
| 41 | + local short_hash |
| 42 | + short_hash=$(git rev-parse --short HEAD) |
31 | 43 |
|
32 | | - if [ "$GITHUB_ACTIONS" == "true" ]; then |
33 | | - local new_version="ci-$short_hash" |
| 44 | + local new_version |
| 45 | + if [ "${GITHUB_ACTIONS:-}" = "true" ]; then |
| 46 | + new_version="ci-$short_hash" |
34 | 47 | else |
35 | | - local new_version="dev-$short_hash" |
| 48 | + new_version="dev-$short_hash" |
36 | 49 | fi |
37 | 50 |
|
38 | 51 | echo "$new_version" |
39 | 52 | } |
40 | 53 |
|
41 | | - |
42 | 54 | cd netbird |
43 | 55 |
|
44 | 56 | # Get version using the function |
45 | | -version=$(get_version "$1") |
| 57 | +version=$(get_version "${1:-}") |
46 | 58 | echo "Using version: $version" |
47 | 59 |
|
48 | 60 | gomobile init |
49 | 61 |
|
50 | 62 | CGO_ENABLED=0 gomobile bind \ |
51 | | - -o $app_path/gomobile/netbird.aar \ |
| 63 | + -o "$app_path/gomobile/netbird.aar" \ |
52 | 64 | -javapkg=io.netbird.gomobile \ |
53 | 65 | -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" \ |
54 | | - $(pwd)/client/android |
| 66 | + "$(pwd)/client/android" |
55 | 67 |
|
56 | 68 | cd - > /dev/null |
0 commit comments