Skip to content
Merged
4 changes: 4 additions & 0 deletions .github/workflows/ci-guards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ jobs:
if: ${{ matrix.group == 'release-ios' }}
run: python3 tests/test_ios_upload_lean_checkout.py

- name: Validate iOS upload batching
if: ${{ matrix.group == 'release-ios' }}
run: python3 tests/test_ios_upload_batching.py

- name: Validate tagged iOS device entitlement fallback
if: ${{ matrix.group == 'release-ios' }}
run: node --test ios/tests/tagged-device-entitlements.test.mjs
Expand Down
71 changes: 69 additions & 2 deletions .github/workflows/ios-appstore-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: iOS TestFlight (cmux.app)

on:
# Upload the official bundle for internal testing. App Review remains manual.
# Hourly polls batch main: they upload once IOS_APPSTORE_MIN_COMMITS
# (default 10) commits are pending or the oldest is
# IOS_APPSTORE_MAX_AGE_MINUTES (default 360) old.
schedule:
- cron: "17 * * * *"
workflow_dispatch:
Expand All @@ -28,7 +31,8 @@ jobs:
if: github.ref == 'refs/heads/main'
runs-on: ${{ vars.LINUX_RUNNER || 'blacksmith-4vcpu-ubuntu-2404' }}
outputs:
upload: ${{ steps.decide.outputs.upload }}
# The batch step, when it runs, has the last word on scheduled polls.
upload: ${{ steps.batch.outputs.upload || steps.decide.outputs.upload }}
retry_build_number: ${{ steps.decide.outputs.retry_build_number }}
steps:
- name: Skip an unchanged scheduled revision
Expand All @@ -42,7 +46,14 @@ jobs:
set -euo pipefail
if [ "$EVENT_NAME" = schedule ]; then
LAST_SHA="$(gh api "repos/$REPOSITORY/actions/workflows/ios-appstore-upload.yml/runs?branch=main&status=success&per_page=1" --jq '.workflow_runs[0].head_sha // ""')"
if [ "$LAST_SHA" = "$HEAD_SHA" ]; then
# The newest completed upload on main (the marker is written right
# after the upload, before assignment). A poll the batch step
# skipped also concludes successfully, so "unchanged" must also
# mean this head was actually uploaded; otherwise a quiet main
# would never reach the age threshold.
LAST_UPLOAD_SHA="$(gh api "repos/$REPOSITORY/actions/artifacts?name=cmux-app-testflight-upload&per_page=20" --jq '[.artifacts[] | select(.expired == false and .workflow_run.head_branch == "main")] | sort_by(.created_at) | last | .workflow_run.head_sha // ""')"
echo "last_upload_sha=$LAST_UPLOAD_SHA" >> "$GITHUB_OUTPUT"
if [ "$LAST_SHA" = "$HEAD_SHA" ] && [ "$LAST_UPLOAD_SHA" = "$HEAD_SHA" ]; then
echo 'upload=false' >> "$GITHUB_OUTPUT"
echo 'Latest main already reached official internal TestFlight.' >> "$GITHUB_STEP_SUMMARY"
exit 0
Expand Down Expand Up @@ -73,6 +84,62 @@ jobs:
fi
echo 'upload=true' >> "$GITHUB_OUTPUT"

# Batch scheduled polls: on a busy day nearly every hourly poll finds new
# main commits, and each upload is a cold Release archive on the macOS
# pool PR CI shares. Runs only when the rules above already chose to
# upload against a known prior upload; manual dispatch is never batched.
# This lane has no path filter, so every main commit counts.
- name: Check out the upload batching policy
# Batching only delays uploads; a failure here must fall back to the
# decide job's answer instead of stopping scheduled uploads.
continue-on-error: true
if: >-
steps.decide.outputs.upload == 'true' &&
github.event_name == 'schedule' &&
steps.decide.outputs.last_upload_sha != ''
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
# Commits and trees only: the batch counts first-parent commits,
# which never needs file contents.
fetch-depth: 1
filter: blob:none
sparse-checkout: |
ios/scripts/fetch-testflight-notes-history.sh
scripts/ci/ios_upload_batch_decision.py
sparse-checkout-cone-mode: false

- name: Batch official uploads by commit count and age
# See the INTERNAL lane: bound the history deepen the same way the upload
# job already bounds this script.
timeout-minutes: 5
# Batching only delays uploads; a failure here must fall back to the
# decide job's answer instead of stopping scheduled uploads.
continue-on-error: true
id: batch
if: >-
steps.decide.outputs.upload == 'true' &&
github.event_name == 'schedule' &&
steps.decide.outputs.last_upload_sha != ''
env:
EVENT_NAME: ${{ github.event_name }}
LAST_UPLOAD_SHA: ${{ steps.decide.outputs.last_upload_sha }}
MIN_COMMITS: ${{ vars.IOS_APPSTORE_MIN_COMMITS }}
MAX_AGE_MINUTES: ${{ vars.IOS_APPSTORE_MAX_AGE_MINUTES }}
run: |
set -euo pipefail
./ios/scripts/fetch-testflight-notes-history.sh "$LAST_UPLOAD_SHA"
python3 scripts/ci/ios_upload_batch_decision.py \
--event "$EVENT_NAME" \
--base "$LAST_UPLOAD_SHA" \
--min-commits "$MIN_COMMITS" \
--max-age-minutes "$MAX_AGE_MINUTES" \
--default-min-commits 10 \
--default-max-age-minutes 360 \
--output-name upload \
--github-output "$GITHUB_OUTPUT" \
--summary "$GITHUB_STEP_SUMMARY"

upload:
name: Upload to App Store Connect (com.cmux.app)
# Only ever publish from main: the ASC secrets ship reviewed main, and a
Expand Down
70 changes: 68 additions & 2 deletions .github/workflows/ios-testflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: iOS TestFlight (CMUX INTERNAL)

on:
# Poll main every 20 minutes and batch merges into one upload. The decide job
# skips scheduled runs when main is unchanged or the changes do not affect iOS.
# skips scheduled runs when main is unchanged or the changes do not affect iOS,
# and INTERNAL polls wait until IOS_TESTFLIGHT_INTERNAL_MIN_COMMITS (default 5)
# iOS-relevant commits are pending or the oldest is
# IOS_TESTFLIGHT_INTERNAL_MAX_AGE_MINUTES (default 180) old.
# Manual dispatch remains available for intentional rebuilds.
schedule:
# Check current main for a cmux INTERNAL upload every 20 minutes.
Expand Down Expand Up @@ -49,7 +52,9 @@ jobs:
runs-on: ${{ vars.LINUX_RUNNER || 'blacksmith-4vcpu-ubuntu-2404' }}
timeout-minutes: 360
outputs:
should_build: ${{ steps.decide.outputs.should_build }}
# The batch step, when it runs, has the last word on scheduled INTERNAL
# polls; every other run keeps the decide script's answer.
should_build: ${{ steps.batch.outputs.should_build || steps.decide.outputs.should_build }}
last_uploaded_sha: ${{ steps.decide.outputs.last_uploaded_sha }}
variant: ${{ steps.decide.outputs.variant }}
steps:
Expand Down Expand Up @@ -418,6 +423,67 @@ jobs:
])
.write();

# Batch scheduled INTERNAL polls: on a busy day nearly every 20-minute
# poll finds an iOS-relevant merge, and each upload is a cold Release
# archive on the macOS pool PR CI shares. Runs only when the rules above
# already chose to upload against a known prior upload; manual dispatch
# and the twice-daily DEMO lane are never batched.
- name: Check out the upload batching policy
# Batching only delays uploads; a failure here must fall back to the
# decide job's answer instead of stopping scheduled uploads.
continue-on-error: true
if: >-
steps.decide.outputs.should_build == 'true' &&
github.event_name == 'schedule' &&
steps.decide.outputs.variant == 'internal' &&
steps.decide.outputs.last_uploaded_sha != ''
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
# Commits and trees only: the batch counts first-parent commits and
# their changed paths, which never needs file contents.
fetch-depth: 1
filter: blob:none
sparse-checkout: |
.github/workflows/ios-testflight.yml
ios/scripts/fetch-testflight-notes-history.sh
scripts/ci/ios_upload_batch_decision.py
sparse-checkout-cone-mode: false

- name: Batch INTERNAL uploads by iOS commit count and age
# fetch-testflight-notes-history.sh deepens history in a loop; the upload
# job bounds the same script at 5 minutes. Without a bound here a
# pathological deepen would hold a runner for the job's 360-minute budget.
timeout-minutes: 5
# Batching only delays uploads; a failure here must fall back to the
# decide job's answer instead of stopping scheduled uploads.
continue-on-error: true
id: batch
if: >-
steps.decide.outputs.should_build == 'true' &&
github.event_name == 'schedule' &&
steps.decide.outputs.variant == 'internal' &&
steps.decide.outputs.last_uploaded_sha != ''
env:
EVENT_NAME: ${{ github.event_name }}
LAST_UPLOADED_SHA: ${{ steps.decide.outputs.last_uploaded_sha }}
MIN_COMMITS: ${{ vars.IOS_TESTFLIGHT_INTERNAL_MIN_COMMITS }}
MAX_AGE_MINUTES: ${{ vars.IOS_TESTFLIGHT_INTERNAL_MAX_AGE_MINUTES }}
run: |
set -euo pipefail
./ios/scripts/fetch-testflight-notes-history.sh "$LAST_UPLOADED_SHA"
python3 scripts/ci/ios_upload_batch_decision.py \
--event "$EVENT_NAME" \
--base "$LAST_UPLOADED_SHA" \
--paths-from-workflow .github/workflows/ios-testflight.yml \
--min-commits "$MIN_COMMITS" \
--max-age-minutes "$MAX_AGE_MINUTES" \
--default-min-commits 5 \
--default-max-age-minutes 180 \
--output-name should_build \
--github-output "$GITHUB_OUTPUT" \
--summary "$GITHUB_STEP_SUMMARY"

upload:
name: Upload to TestFlight
needs: decide
Expand Down
Loading
Loading