mostly android
This commit is contained in:
84
iOS/scripts/create_test_token
Executable file
84
iOS/scripts/create_test_token
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate a JWT token for testing Lendair API calls.
|
||||
# Usage: ./scripts/create_test_token <user-id> [secret-env-var]
|
||||
#
|
||||
# Reads the JWT secret from the environment (default: CLERK_SECRET_KEY).
|
||||
# Falls back to .env file in the project root.
|
||||
#
|
||||
# Example:
|
||||
# CLERK_SECRET_KEY=sk_test_xxx ./scripts/create_test_token user_123
|
||||
# ./scripts/create_test_token user_123 CLERK_SECRET_KEY
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $(basename "$0") <user-id> [secret-env-var]" >&2
|
||||
echo "" >&2
|
||||
echo "Generates a JWT token with the given user-id as subject." >&2
|
||||
echo "The secret is read from the environment variable (default: CLERK_SECRET_KEY)" >&2
|
||||
echo "or from a .env file in the project root." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
USER_ID="$1"
|
||||
SECRET_VAR="${2:-CLERK_SECRET_KEY}"
|
||||
SECRET="${!SECRET_VAR:-}"
|
||||
|
||||
# Fallback: try loading from .env in project root
|
||||
if [ -z "$SECRET" ]; then
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
ENV_FILE="$PROJECT_DIR/../.env"
|
||||
if [ -f "$ENV_FILE" ]; then
|
||||
set -a
|
||||
source "$ENV_FILE" 2>/dev/null || true
|
||||
set +a
|
||||
SECRET="${!SECRET_VAR:-}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$SECRET" ]; then
|
||||
echo "Error: $SECRET_VAR is not set and no .env file found" >&2
|
||||
echo "" >&2
|
||||
echo "Set it inline:" >&2
|
||||
echo " $SECRET_VAR=sk_test_xxx $(basename "$0") $USER_ID" >&2
|
||||
echo "Or add to .env in the repo root:" >&2
|
||||
echo " $SECRET_VAR=sk_test_xxx" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
generate_jwt_via_node() {
|
||||
node --input-type=module - "$1" "$2" <<'JWTSCRIPT' 2>/dev/null
|
||||
import { createHmac } from 'node:crypto';
|
||||
|
||||
const userId = process.argv[1];
|
||||
const secret = process.argv[2];
|
||||
const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url');
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const payload = Buffer.from(JSON.stringify({
|
||||
sub: userId,
|
||||
iat: now,
|
||||
exp: now + 2592000
|
||||
})).toString('base64url');
|
||||
const sig = createHmac('sha256', secret).update(header + '.' + payload).digest('base64url');
|
||||
console.log(header + '.' + payload + '.' + sig);
|
||||
JWTSCRIPT
|
||||
}
|
||||
|
||||
generate_jwt_via_openssl() {
|
||||
local now header payload sig
|
||||
now=$(date +%s)
|
||||
header=$(echo -n '{"alg":"HS256","typ":"JWT"}' | base64 | tr '+/' '-_' | tr -d '=')
|
||||
payload=$(echo -n "{\"sub\":\"$USER_ID\",\"iat\":$now,\"exp\":$((now + 2592000))}" | base64 | tr '+/' '-_' | tr -d '=')
|
||||
sig=$(echo -n "$header.$payload" | openssl dgst -sha256 -hmac "$SECRET" -binary | base64 | tr '+/' '-_' | tr -d '=')
|
||||
echo "$header.$payload.$sig"
|
||||
}
|
||||
|
||||
if command -v node &>/dev/null; then
|
||||
generate_jwt_via_node "$USER_ID" "$SECRET"
|
||||
elif command -v openssl &>/dev/null; then
|
||||
generate_jwt_via_openssl
|
||||
else
|
||||
echo "Error: need either node or openssl to generate JWT" >&2
|
||||
exit 1
|
||||
fi
|
||||
41
iOS/scripts/get_coverage
Executable file
41
iOS/scripts/get_coverage
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# Generate code coverage report for Lendair iOS project.
|
||||
# Finds the most recent xcresult file and produces a JSON report.
|
||||
#
|
||||
# Usage: ./scripts/get_coverage
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
REPORTS_DIR="$PROJECT_DIR/reports"
|
||||
|
||||
XCRESULT=$(find ~/Library/Developer/Xcode/DerivedData -name "*Lendair*" -path "*/Test/*.xcresult" -type d 2>/dev/null | sort -r | head -1)
|
||||
|
||||
if [ -z "$XCRESULT" ]; then
|
||||
echo "Error: No xcresult file found for Lendair project" >&2
|
||||
echo "" >&2
|
||||
echo "Make sure you've run tests with coverage enabled:" >&2
|
||||
echo " ./run test -c" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Using xcresult: $XCRESULT"
|
||||
|
||||
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
|
||||
mkdir -p "$REPORTS_DIR/$TIMESTAMP"
|
||||
|
||||
xcrun xccov view --report "$XCRESULT" --json > "$REPORTS_DIR/$TIMESTAMP/code_coverage.json"
|
||||
|
||||
echo ""
|
||||
echo "Code coverage report generated:"
|
||||
echo " $REPORTS_DIR/$TIMESTAMP/code_coverage.json"
|
||||
|
||||
# Also symlink latest
|
||||
ln -sf "$TIMESTAMP" "$REPORTS_DIR/latest" 2>/dev/null || true
|
||||
cp "$REPORTS_DIR/$TIMESTAMP/code_coverage.json" "$REPORTS_DIR/code_coverage.json" 2>/dev/null || true
|
||||
|
||||
# Print a quick summary
|
||||
echo ""
|
||||
echo "=== Coverage Summary ==="
|
||||
xcrun xccov view --report "$XCRESULT" 2>/dev/null | head -30 || true
|
||||
59
iOS/scripts/typecheck
Executable file
59
iOS/scripts/typecheck
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
# typecheck - Run a fast Swift typecheck on the Lendair iOS project via remote Mac build host.
|
||||
#
|
||||
# Usage (from any machine with SSH access to the build host):
|
||||
# ./scripts/typecheck
|
||||
#
|
||||
# What it does:
|
||||
# 1. SSHes to the build host (configurable via REMOTE_HOST env var)
|
||||
# 2. Pulls latest code on the Mac
|
||||
# 3. Runs xcodebuild build with output filtered to errors/warnings only
|
||||
# 4. Exits 0 on clean typecheck, 1 on errors
|
||||
#
|
||||
# Configuration:
|
||||
# REMOTE_HOST - SSH hostname (default: hermes)
|
||||
# REMOTE_REPO - Path to repo on the Mac (default: ~/code/lendair)
|
||||
# PROJECT_PATH - Project path relative to repo root (default: iOS/Lendair/Lendair.xcodeproj)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REMOTE_HOST="${REMOTE_HOST:-hermes}"
|
||||
REMOTE_REPO="${REMOTE_REPO:-$HOME/code/lendair}"
|
||||
PROJECT_PATH="${PROJECT_PATH:-iOS/Lendair/Lendair.xcodeproj}"
|
||||
SCHEME="Lendair"
|
||||
|
||||
echo "=== Typecheck: connecting to $REMOTE_HOST ==="
|
||||
|
||||
ssh "$REMOTE_HOST" bash <<REMOTE
|
||||
set -euo pipefail
|
||||
cd "$REMOTE_REPO"
|
||||
echo "--- Pulling latest ---"
|
||||
git stash --include-untracked -q 2>/dev/null || true
|
||||
git pull --rebase origin master 2>&1 | tail -3 || echo "Already up to date or pull failed"
|
||||
git stash pop -q 2>/dev/null || true
|
||||
echo "--- Running typecheck ---"
|
||||
set +e +o pipefail
|
||||
BUILD_LOG=\$(mktemp)
|
||||
xcodebuild \
|
||||
-project "$PROJECT_PATH" \
|
||||
-scheme "$SCHEME" \
|
||||
-configuration Debug \
|
||||
-destination "generic/platform=iOS Simulator" \
|
||||
-jobs 4 \
|
||||
CODE_SIGNING_ALLOWED=NO \
|
||||
build > "\$BUILD_LOG" 2>&1
|
||||
BUILD_EXIT=\$?
|
||||
set -e -o pipefail
|
||||
|
||||
grep -E "\.swift:[0-9]+:[0-9]+: (error|warning):|^\*\* BUILD (SUCCEEDED|FAILED)" "\$BUILD_LOG" \
|
||||
| sed "s|$REMOTE_REPO/||g" \
|
||||
|| true
|
||||
|
||||
rm -f "\$BUILD_LOG"
|
||||
if [ "\$BUILD_EXIT" = "0" ]; then
|
||||
echo "=== PASSED ==="
|
||||
else
|
||||
echo "=== FAILED ==="
|
||||
fi
|
||||
exit \$BUILD_EXIT
|
||||
REMOTE
|
||||
Reference in New Issue
Block a user