ios/Scripts/generate-sdk-version-info.sh

50 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
#
# SDK Version Info Generator
#
# Extracts SDK version from project-common.yml and generates SDKVersionInfo.swift
# Works in ALL builds (local + CI), not just CI builds
#
# Prerequisites:
# - project-common.yml exists with BitwardenSdk revision comment
# - Write access to BitwardenKit/Core/Platform/Utilities/
set -euo pipefail
PROJECT_FILE="${SRCROOT:-$(pwd)}/project-common.yml"
OUTPUT_FILE="${SRCROOT:-$(pwd)}/BitwardenKit/Core/Platform/Utilities/SDKVersionInfo.swift"
# Extract SDK version from YAML comment
# Format: revision: <hash> # <version>
SDK_VERSION=$(grep -A5 "BitwardenSdk:" "$PROJECT_FILE" | \
grep "revision:" | \
sed 's/.*# //' | \
tr -d '\n' || echo "Unknown")
# If extraction failed or returned the full line (no # comment), provide fallback
if [ -z "$SDK_VERSION" ] || [ "$SDK_VERSION" = "Unknown" ] || [[ "$SDK_VERSION" == *"revision:"* ]]; then
echo "❌ ERROR: Could not extract SDK version from $PROJECT_FILE"
echo "Expected format: 'revision: <hash> # <version>'"
echo "Example: 'revision: 70f9530... # 2.0.0-3659-948b207'"
echo "Tests will fail with 'Unknown' version"
SDK_VERSION="Unknown"
fi
echo "🔧 Generating SDK Version Info..."
echo "🔧 SDK Version: $SDK_VERSION"
# Generate Swift file
cat << EOF > "$OUTPUT_FILE"
/// SDK version information extracted from project-common.yml at build time.
/// WARNING: This file is automatically generated by Scripts/generate-sdk-version-info.sh
/// and should not be modified manually.
///
public enum SDKVersionInfo {
/// The BitwardenSDK version string (e.g., "2.0.0-3659-948b207").
/// Extracted from the revision comment in project-common.yml.
public static let version: String = "$SDK_VERSION"
}
EOF
echo "✅ SDK Version Info generated successfully."