146 lines
4.7 KiB
YAML
146 lines
4.7 KiB
YAML
# =============================================================================
|
|
# TabataGo — PR → Build → Archive → Firebase OTA → Wait LGTM → Merge
|
|
# =============================================================================
|
|
|
|
name: PR → Build → Firebase OTA → LGTM
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
types: [opened, synchronize, reopened]
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
|
|
build-deploy:
|
|
name: Build & Deploy to Firebase OTA
|
|
runs-on: macos
|
|
timeout-minutes: 20
|
|
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git clone --depth 1 https://x-access-token:${PR_TOKEN}@gitea.1000co.fr/${REPO}.git .
|
|
env:
|
|
PR_TOKEN: ${{ secrets.PR_API_TOKEN }}
|
|
REPO: ${{ github.repository }}
|
|
|
|
- name: Setup Xcode
|
|
run: |
|
|
sudo xcode-select -s /Applications/Xcode.app
|
|
xcodebuild -version
|
|
|
|
- name: Install tools (xcodegen, node, firebase)
|
|
run: |
|
|
arch -arm64 /opt/homebrew/bin/brew install xcodegen node || true
|
|
npm install -g firebase-tools
|
|
|
|
- name: Generate Xcode project
|
|
run: |
|
|
cd tabatago-swift
|
|
xcodegen generate
|
|
|
|
- name: Archive app
|
|
run: |
|
|
cd tabatago-swift
|
|
xcodebuild archive \
|
|
-scheme TabataGo \
|
|
-sdk iphoneos \
|
|
-destination "generic/platform=iOS" \
|
|
-configuration Debug \
|
|
-archivePath ../build/TabataGo.xcarchive \
|
|
-allowProvisioningUpdates \
|
|
CODE_SIGN_STYLE=Automatic
|
|
|
|
- name: Export IPA
|
|
run: |
|
|
cd tabatago-swift
|
|
xcodebuild -exportArchive \
|
|
-archivePath ../build/TabataGo.xcarchive \
|
|
-exportPath ../build/ \
|
|
-exportOptionsPlist ExportOptions.plist \
|
|
-allowProvisioningUpdates
|
|
|
|
- name: Deploy to Firebase
|
|
env:
|
|
FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID }}
|
|
run: |
|
|
echo "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" | base64 -d > /tmp/firebase-key.json
|
|
export GOOGLE_APPLICATION_CREDENTIALS=/tmp/f...on
|
|
firebase appdistribution:distribute build/TabataGo.ipa \
|
|
--app "${FIREBASE_APP_ID}" \
|
|
--groups "millian-test" \
|
|
--release-notes "PR: ${{ github.event.pull_request.title }}"
|
|
rm /tmp/firebase-key.json
|
|
|
|
- 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 via Firebase.\\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
|