#!/usr/bin/env bash
# scripts/release-check.sh — everything that must be green before tagging a
# release: the manifest parses, the generated code matches the spec snapshot,
# the package builds and the offline test suite passes on macOS, and the working
# tree is clean. RELEASE=1 additionally requires HEAD to carry a version tag;
# MACAPP=1 also builds the example app; IOS=1 builds the package for the iOS Simulator.
set -euo pipefail
cd "$(dirname "$0")/.."
echo "== manifest"
swift package dump-package > /dev/null
echo "== generated sources"
python3 scripts/gen-api.py --check
echo "== build (macOS)"
swift build
echo "== tests (offline)"
swift test
if [ "${IOS:-0}" = "1" ]; then
echo "== build (iOS Simulator)"
xcodebuild -scheme ird-api-swift -destination 'generic/platform=iOS Simulator' -derivedDataPath .build/DerivedData build | grep -E "BUILD|error:" || true
fi
if [ "${MACAPP:-0}" = "1" ]; then
echo "== build (example app, macOS)"
xcodebuild -project Examples/IrdManager/IrdManager.xcodeproj -scheme IrdManager -destination 'generic/platform=macOS' \
-derivedDataPath .build/DerivedData CODE_SIGNING_ALLOWED=NO build | grep -E "BUILD|error:" || true
fi
echo "== working tree"
if [ -n "$(git status --porcelain)" ]; then
echo "ABORT: uncommitted changes" >&2
git status --short >&2
exit 1
fi
if [ "${RELEASE:-0}" = "1" ]; then
echo "== tag"
git describe --exact-match --tags HEAD
fi
echo "release-check: OK"