#!/usr/bin/env bash
# scripts/release-check.sh — everything that must be green before tagging a
# release: the manifest parses, 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; IOS=1 also builds for the iOS Simulator.
set -euo pipefail
cd "$(dirname "$0")/.."
echo "== manifest"
swift package dump-package > /dev/null
echo "== build (macOS)"
swift build
echo "== tests (offline)"
swift test
if [ "${IOS:-0}" = "1" ]; then
echo "== build (iOS Simulator)"
xcodebuild -scheme ird-p2p-swift -destination 'generic/platform=iOS Simulator' -derivedDataPath .build/DerivedData 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"