|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +detect_repo_root() { |
| 6 | + local git_root |
| 7 | + if command -v git >/dev/null 2>&1; then |
| 8 | + if git_root=$(git rev-parse --show-toplevel 2>/dev/null); then |
| 9 | + echo "${git_root}" |
| 10 | + return 0 |
| 11 | + fi |
| 12 | + fi |
| 13 | + |
| 14 | + # Fallback to script directory's parent (repo layout assumption) |
| 15 | + local script_dir |
| 16 | + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 17 | + echo "$(cd "${script_dir}/.." && pwd)" |
| 18 | +} |
| 19 | + |
| 20 | +REPO_ROOT="$(detect_repo_root)" |
| 21 | + |
| 22 | +DOC="${REPO_ROOT}/docs/sdk-versions.md" |
| 23 | + |
| 24 | +print_usage() { |
| 25 | + cat <<'USAGE' |
| 26 | +Usage: scripts/update-sdk-versions-table.sh <flutter_version> |
| 27 | +
|
| 28 | +Arguments: |
| 29 | + <flutter_version> Required. The Sentry Flutter SDK version (e.g., 9.9.9 or 9.5.0-beta.1). |
| 30 | +USAGE |
| 31 | +} |
| 32 | + |
| 33 | +# Parse flags (support -h/--help only for now) |
| 34 | +for arg in "$@"; do |
| 35 | + case "$arg" in |
| 36 | + -h|--help) |
| 37 | + print_usage |
| 38 | + exit 0 |
| 39 | + ;; |
| 40 | + esac |
| 41 | +done |
| 42 | + |
| 43 | +# Positional argument: Flutter version (required) |
| 44 | +FLUTTER_VERSION=${1:-} |
| 45 | +if [[ -z "${FLUTTER_VERSION}" ]]; then |
| 46 | + echo "Error: Missing required <flutter_version> argument." >&2 |
| 47 | + echo >&2 |
| 48 | + print_usage >&2 |
| 49 | + exit 2 |
| 50 | +fi |
| 51 | + |
| 52 | +ANDROID_VERSION="$(${REPO_ROOT}/packages/flutter/scripts/update-android.sh get-version)" |
| 53 | +COCOA_VERSION="$(${REPO_ROOT}/packages/flutter/scripts/update-cocoa.sh get-version)" |
| 54 | +JS_VERSION="$(${REPO_ROOT}/packages/flutter/scripts/update-js.sh get-version)" |
| 55 | +NATIVE_VERSION="$(${REPO_ROOT}/packages/flutter/scripts/update-native.sh get-version)" |
| 56 | + |
| 57 | +ROW="| ${FLUTTER_VERSION} | ${ANDROID_VERSION} | ${COCOA_VERSION} | ${JS_VERSION} | ${NATIVE_VERSION} |" |
| 58 | + |
| 59 | +# Bootstrap docs file if missing |
| 60 | +if [[ ! -f "${DOC}" ]]; then |
| 61 | + { |
| 62 | + echo '# SDK Versions' |
| 63 | + echo |
| 64 | + echo 'This document shows which version of the various Sentry SDKs are used in which Sentry Flutter SDK version.' |
| 65 | + echo |
| 66 | + echo '## Version Table' |
| 67 | + echo |
| 68 | + echo '| Sentry Flutter SDK | Sentry Android SDK | Sentry Cocoa SDK | Sentry JavaScript SDK | Sentry Native SDK |' |
| 69 | + echo '| ------------------ | ------------------ | ---------------- | --------------------- | ----------------- |' |
| 70 | + echo "${ROW}" |
| 71 | + } > "${DOC}" |
| 72 | + exit 0 |
| 73 | +fi |
| 74 | + |
| 75 | +# Always insert the new row directly below the table separator of the first table |
| 76 | +awk -v row="$ROW" ' |
| 77 | + BEGIN { in_table=0; inserted=0 } |
| 78 | + { |
| 79 | + print $0 |
| 80 | + if (!in_table && $0 ~ /^\| Sentry Flutter SDK \|/) { |
| 81 | + in_table=1 |
| 82 | + next |
| 83 | + } |
| 84 | + if (in_table && !inserted && $0 ~ /^\| *-+ *\|/) { |
| 85 | + print row |
| 86 | + inserted=1 |
| 87 | + in_table=0 |
| 88 | + } |
| 89 | + } |
| 90 | + END { |
| 91 | + if (!inserted) { |
| 92 | + # If no header/separator found, append at end for robustness |
| 93 | + print row |
| 94 | + } |
| 95 | + } |
| 96 | +' "$DOC" >"$DOC.tmp" |
| 97 | + |
| 98 | +mv "$DOC.tmp" "$DOC" |
| 99 | + |
| 100 | +exit 0 |
| 101 | + |
| 102 | + |
0 commit comments