- Replace bash [[ ]] regex test with grep -Eq for better portability - Add debug output showing pwd and directory listing on file not found - Use explicit regex groups for + and - separately for better compatibility
53 lines
1.6 KiB
Bash
Executable File
53 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Extract version from version file for products
|
|
# Usage: ./extract-version.sh <app>
|
|
# app: worker-mobile-app or client-mobile-app
|
|
|
|
set -e
|
|
|
|
APP=$1
|
|
|
|
if [ -z "$APP" ]; then
|
|
echo "❌ Error: App parameter required (worker-mobile-app or client-mobile-app)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Determine pubspec path
|
|
if [ "$APP" = "worker-mobile-app" ]; then
|
|
PUBSPEC_PATH="apps/mobile/apps/staff/pubspec.yaml"
|
|
APP_NAME="Staff Product (Worker)"
|
|
else
|
|
PUBSPEC_PATH="apps/mobile/apps/client/pubspec.yaml"
|
|
APP_NAME="Client Product"
|
|
fi
|
|
|
|
# Check if pubspec exists
|
|
if [ ! -f "$PUBSPEC_PATH" ]; then
|
|
echo "❌ Error: pubspec.yaml not found at $PUBSPEC_PATH" >&2
|
|
echo "📁 Current directory: $(pwd)" >&2
|
|
echo "📂 Directory contents:" >&2
|
|
ls -la apps/mobile/apps/ 2>&1 | head -20 >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Extract version (format: X.Y.Z+buildNumber or X.Y.Z-suffix)
|
|
VERSION_LINE=$(grep "^version:" "$PUBSPEC_PATH")
|
|
if [ -z "$VERSION_LINE" ]; then
|
|
echo "❌ Error: Could not find version in $PUBSPEC_PATH" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Extract full version including suffix/build number
|
|
VERSION=$(echo "$VERSION_LINE" | sed 's/version: *//' | tr -d ' ')
|
|
|
|
# Validate version format (X.Y.Z with optional +build or -suffix)
|
|
# Use grep for better portability across different bash versions
|
|
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(\+[a-zA-Z0-9]+|-[a-zA-Z0-9]+)?$'; then
|
|
echo "❌ Error: Invalid version format in pubspec.yaml: $VERSION" >&2
|
|
echo "Expected format: X.Y.Z, X.Y.Z+build, or X.Y.Z-suffix (e.g., 0.1.0, 0.1.0+12, 0.1.0-m3)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Extracted version from $PUBSPEC_PATH: $VERSION" >&2
|
|
echo "$VERSION"
|