Files
linkding-ios/scripts/ipa-server/build-and-deploy.sh
Krishna Kumar 22cde6d2d7
All checks were successful
CI / build-and-deploy (push) Successful in 16s
Add Gitea CI workflow with IPA distribution
On every push to swift/master: compile-checks against the simulator
(no signing required) then builds a development IPA and deploys it to
the shared OTA server at krishnas-mac-studio.tail37d544.ts.net:8443.

Modelled on 1ai's ci.yaml — runs on the local macos act runner so the
keychain is live and automatic signing works without any cert setup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 12:05:55 -05:00

105 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Build an Ad Hoc IPA and copy to the shared distribution server.
# Usage: ./build-and-deploy.sh [branch]
# branch defaults to current branch if not specified
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SERVER_BUILDS_DIR="/Volumes/Next2/hermes-home/1ai/builds"
BUILD_DIR="$SCRIPT_DIR/.build"
ARCHIVE_PATH="$BUILD_DIR/Marks.xcarchive"
EXPORT_PATH="$BUILD_DIR/export"
REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
SCHEME="${SCHEME:-Marks}"
CONFIGURATION="${CONFIGURATION:-Debug}"
EXPORT_METHOD="${EXPORT_METHOD:-development}"
mkdir -p "$SERVER_BUILDS_DIR"
mkdir -p "$BUILD_DIR"
cd "$REPO_DIR"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -n "$CI" ]; then
COMMIT=$(git rev-parse --short HEAD)
echo "📌 CI mode — building commit: $COMMIT (ref: $CURRENT_BRANCH)"
elif [ -n "$1" ] && [ "$1" != "$CURRENT_BRANCH" ]; then
echo "🔀 Switching from $CURRENT_BRANCH to $1..."
git checkout "$1"
echo "⬇️ Pulling latest $1..."
git pull origin "$1"
COMMIT=$(git rev-parse --short HEAD)
echo "📌 Building commit: $COMMIT on $1"
else
COMMIT=$(git rev-parse --short HEAD)
if git ls-remote --exit-code origin "$CURRENT_BRANCH" &>/dev/null; then
echo "⬇️ Pulling latest $CURRENT_BRANCH..."
git pull origin "$CURRENT_BRANCH"
else
echo "⚠️ No remote for $CURRENT_BRANCH — building local HEAD"
fi
echo "📌 Building commit: $COMMIT on $CURRENT_BRANCH"
fi
echo "⚙️ Generating Xcode project..."
xcodegen generate
echo "🔨 Building $SCHEME ($CONFIGURATION)..."
xcodebuild archive \
-scheme "$SCHEME" \
-configuration "$CONFIGURATION" \
-archivePath "$ARCHIVE_PATH" \
-destination 'generic/platform=iOS' \
2>&1 | tee "$BUILD_DIR/archive.log" | tail -20
cat > "$BUILD_DIR/ExportOptions.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>${EXPORT_METHOD}</string>
<key>signingStyle</key>
<string>automatic</string>
<key>teamID</key>
<string>AE5DZKJHGN</string>
<key>compileBitcode</key>
<false/>
<key>stripSwiftSymbols</key>
<true/>
</dict>
</plist>
EOF
echo "📦 Exporting IPA..."
xcodebuild -exportArchive \
-archivePath "$ARCHIVE_PATH" \
-exportPath "$EXPORT_PATH" \
-exportOptionsPlist "$BUILD_DIR/ExportOptions.plist" \
2>&1 | tee "$BUILD_DIR/export.log" | tail -20
IPA_FILE=$(find "$EXPORT_PATH" -name "*.ipa" | head -1)
if [ -n "$IPA_FILE" ]; then
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
APP_PROPS="$ARCHIVE_PATH/Info.plist"
VERSION=$(/usr/libexec/PlistBuddy -c "Print :ApplicationProperties:CFBundleShortVersionString" "$APP_PROPS")
BUILD=$(/usr/libexec/PlistBuddy -c "Print :ApplicationProperties:CFBundleVersion" "$APP_PROPS")
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-$(git rev-parse --abbrev-ref HEAD)}}"
BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9._-]/-/g')
DEST_NAME="Marks-${VERSION}-${BUILD}-${BRANCH}-${TIMESTAMP}.ipa"
cp "$IPA_FILE" "$SERVER_BUILDS_DIR/$DEST_NAME"
echo ""
echo "✅ Build complete!"
echo " IPA: $SERVER_BUILDS_DIR/$DEST_NAME"
echo " Server: https://krishnas-mac-studio.tail37d544.ts.net:8443"
else
echo "❌ No IPA file found in export"
exit 1
fi