Files
tabatago/.github/workflows/pr-iphone-deploy.yml
Millian Lamiaux a309b2b593 chore: purge obsolete .archive docs and relocate CI workflows
- Remove 5 outdated TabataFit/Expo concept docs (.archive/)
- Rename .gitea/workflows -> .github/workflows
- Ignore build/ directory
- Add Xcode UserInterfaceState
2026-07-04 16:41:34 +02:00

193 lines
6.6 KiB
YAML

# =============================================================================
# TabataGo — PR → Build → WiFi/USB Direct Deploy → Wait LGTM → Merge
# =============================================================================
name: PR → Build → WiFi/USB Deploy → LGTM
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
permissions:
contents: write
pull-requests: write
jobs:
build-deploy:
name: Build & Deploy to iPhone (WiFi/USB)
runs-on: macos
timeout-minutes: 20
steps:
- name: Checkout
run: |
git clone --depth 1 -b ${{ github.head_ref }} https://x-access-token:${PR_TOKEN}@gitea.1000co.fr/${{ github.repository }}.git .
env:
PR_TOKEN: ${{ secrets.PR_API_TOKEN }}
REPO: ${{ github.repository }}
- name: Setup Xcode
run: |
xcodebuild -version
- name: Setup PATH
run: echo "/opt/homebrew/bin" >> $GITHUB_PATH
- name: Clean build artifacts
run: |
echo "🧹 Cleaning build artifacts..."
# Act runner caches
rm -rf ~/.cache/act/*/hostexecutor/tabatago-swift/build 2>/dev/null || true
# SPM caches are KEPT between runs — RevenueCat is 1.10 GiB and takes
# 5+ minutes to clone; re-cloning on every CI run would waste time
# and cause random failures on the act_runner sandbox.
# Xcode DerivedData — suppression COMPLÈTE (le bundle ID a changé,
# l'ancien dossier TabataGo-* peut être ignoré par le nouveau build)
rm -rf ~/Library/Developer/Xcode/DerivedData/*
# Module cache Xcode — des .pcm stale peuvent segfault le linker
rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache.noindex 2>/dev/null || true
rm -rf ~/Library/Caches/com.apple.dt.Xcode
# Build artifacts locaux (utilisés par le step "Build app")
rm -rf build/
rm -rf .build
rm -rf tabatago-swift/.build
rm -rf tabatago-swift/TabataGo.xcodeproj
rm -rf tabatago-swift/*.xcworkspace 2>/dev/null || true
# Package.resolved — peut être stale après un changement de bundle ID
find . -name "Package.resolved" -delete 2>/dev/null || true
find . -name ".package.resolved" -delete 2>/dev/null || true
echo "✅ Caches nettoyés"
- name: Install tools (xcodegen, node, ios-deploy)
run: |
brew install xcodegen node ios-deploy || true
- name: Generate Xcode project
run: |
cd tabatago-swift
xcodegen generate
- name: Resolve SPM packages
run: |
cd tabatago-swift
xcodebuild -resolvePackageDependencies \
-project TabataGo.xcodeproj \
-scmProvider system
- name: Build app
run: |
cd tabatago-swift
xcodebuild build \
-project TabataGo.xcodeproj \
-scheme TabataGo \
-configuration Debug \
-allowProvisioningUpdates \
-skipPackagePluginValidation \
-derivedDataPath ../build/derived \
-clonedSourcePackagesDirPath ../build/spm-cache \
SWIFT_ENABLE_EXPLICIT_MODULES=NO \
ONLY_ACTIVE_ARCH=NO \
CODE_SIGN_STYLE=Automatic \
DEVELOPMENT_TEAM=2MJF39L8VY
- name: Install to iPhone (WiFi → USB fallback)
run: |
UDID="00008120-000925CE3672201E"
APP=$(find build/derived -name 'TabataGo.app' -type d | head -1)
# 1. Try WiFi first (Xcode 15+ devicectl network discovery)
echo "📱 Trying WiFi install via devicectl..."
xcrun devicectl device install app --device "$UDID" "$APP" 2>&1 | tail -3
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo "✅ Installed via WiFi"
exit 0
fi
# 2. Fallback to USB via ios-deploy
echo "🔌 WiFi failed, trying USB..."
ios-deploy --bundle "$APP" --id "$UDID" --justlaunch
if [ $? -eq 0 ]; then
echo "✅ Installed via USB"
exit 0
fi
echo "❌ Install failed (both WiFi and USB)"
exit 1
- name: Post "Ready to test" comment
env:
GT_TOKEN: ${{ secrets.PR_API_TOKEN }}
GITEA_URL: https://gitea.1000co.fr
run: |
PR="${{ github.event.pull_request.number }}"
REPO="${{ github.repository }}"
curl -s -X POST \
-H "Authorization: token ${GT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"body\":\"## 📱 Prêt à tester !\\n\\nL'app est déployée sur l'iPhone (USB/WiFi).\\n\\n- Teste les changements\\n- Reply **LGTM** pour merger\\n- Reply **KO** pour bloquer\"}" \
"${GITEA_URL}/api/v1/repos/${REPO}/issues/${PR}/comments"
wait-approval:
name: Wait for LGTM comment
needs: build-deploy
runs-on: macos
timeout-minutes: 120
steps:
- name: Poll for LGTM
env:
GT_TOKEN: ${{ secrets.PR_API_TOKEN }}
GITEA_URL: https://gitea.1000co.fr
run: |
PR="${{ github.event.pull_request.number }}"
REPO="${{ github.repository }}"
PR_TITLE="${{ github.event.pull_request.title }}"
API="${GITEA_URL}/api/v1/repos/${REPO}"
MAX=240
TRIES=0
echo "⏳ Attente LGTM sur PR #${PR}..."
LAST_ID=$(curl -s -H "Authorization: token ${GT_TOKEN}" \
"${API}/issues/${PR}/comments" | \
python3 -c "import json,sys; cs=json.load(sys.stdin); print(cs[-1]['id'] if cs else 0)" 2>/dev/null || echo 0)
while [ $TRIES -lt $MAX ]; do
sleep 30
TRIES=$((TRIES + 1))
COMMENTS=$(curl -s -H "Authorization: token ${GT_TOKEN}" \
"${API}/issues/${PR}/comments?since_id=${LAST_ID}")
if echo "$COMMENTS" | grep -qi '"body": *"LGTM"'; then
echo "✅ LGTM reçu ! Merge..."
curl -s -X POST \
-H "Authorization: token ${GT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"Do\":\"merge\"}" \
"${API}/pulls/${PR}/merge"
echo "✅ Mergée."
exit 0
fi
if echo "$COMMENTS" | grep -qi '"body": *"KO"'; then
echo "❌ KO reçu. Bloquée."
exit 1
fi
if [ $((TRIES % 4)) -eq 0 ]; then
echo " ⏳ ... (${TRIES}/240, $(date +%H:%M))"
fi
done
echo "❌ Timeout 2h."
exit 1