|
| 1 | +############################################################################################## |
| 2 | +# |
| 3 | +# Runway iOS RC Workflow |
| 4 | +# |
| 5 | +# Triggered from Runway to either: |
| 6 | +# - Push an OTA update (when OTA_VERSION in app/constants/ota.ts line 9 is bumped), or |
| 7 | +# - Build the mobile app (when there is no OTA version bump). |
| 8 | +# |
| 9 | +# When triggering workflow_dispatch, select the release branch (e.g. release/7.71.0). |
| 10 | +# |
| 11 | +############################################################################################## |
| 12 | +name: Runway iOS RC |
| 13 | + |
| 14 | +on: |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + ref: |
| 18 | + description: 'Optional git ref (branch) to run against. Defaults to the branch selected in the UI.' |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: write # required by build.yml (update-build-version job) |
| 24 | + pull-requests: read |
| 25 | + actions: write |
| 26 | + id-token: write # required by build.yml |
| 27 | + |
| 28 | +jobs: |
| 29 | + decide: |
| 30 | + name: Check OTA version and resolve inputs |
| 31 | + runs-on: ubuntu-latest |
| 32 | + outputs: |
| 33 | + ota_bump: ${{ steps.decide.outputs.ota_bump }} |
| 34 | + base_ref: ${{ steps.decide.outputs.base_ref }} |
| 35 | + ota_version: ${{ steps.decide.outputs.ota_version }} |
| 36 | + pr_number: ${{ steps.resolve-pr.outputs.pr_number }} |
| 37 | + steps: |
| 38 | + - name: Checkout repository |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + fetch-depth: 0 |
| 42 | + ref: ${{ inputs.ref || github.ref }} |
| 43 | + |
| 44 | + - name: Setup Node.js |
| 45 | + uses: actions/setup-node@v4 |
| 46 | + with: |
| 47 | + node-version-file: '.nvmrc' |
| 48 | + |
| 49 | + - name: Resolve PR number for current branch |
| 50 | + id: resolve-pr |
| 51 | + run: | |
| 52 | + BRANCH="${{ inputs.ref || github.ref_name }}" |
| 53 | + # Strip refs/heads/ if present |
| 54 | + BRANCH="${BRANCH#refs/heads/}" |
| 55 | + echo "Resolving PR for branch: $BRANCH (repo: $GITHUB_REPOSITORY)" |
| 56 | +
|
| 57 | + # Try same-repo head first, then owner:branch (required by API when listing pulls) |
| 58 | + PR_NUMBER=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$BRANCH" --json number --jq '.[0].number' 2>/dev/null || echo "") |
| 59 | + if [[ -z "$PR_NUMBER" ]]; then |
| 60 | + PR_NUMBER=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$GITHUB_REPOSITORY_OWNER:$BRANCH" --json number --jq '.[0].number' 2>/dev/null || echo "") |
| 61 | + fi |
| 62 | +
|
| 63 | + echo "pr_number=${PR_NUMBER}" >> "$GITHUB_OUTPUT" |
| 64 | + echo "Branch: $BRANCH, PR number: ${PR_NUMBER:-none}" |
| 65 | + env: |
| 66 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Decide OTA vs build |
| 69 | + id: decide |
| 70 | + run: | |
| 71 | + set -e |
| 72 | + # Version from package.json (e.g. 7.70.0) → base ref for OTA workflow is always v{VERSION} |
| 73 | + VERSION=$(node -p "require('./package.json').version") |
| 74 | + RELEASE_TAG="v${VERSION}" |
| 75 | + echo "base_ref=${RELEASE_TAG}" >> "$GITHUB_OUTPUT" |
| 76 | +
|
| 77 | + # Extract OTA_VERSION from line 9 (format: export const OTA_VERSION: string = 'vX.Y.Z';) |
| 78 | + extract_ota() { sed -n '9p' "$1" | sed "s/.*'\\([^']*\\)'.*/\1/"; } |
| 79 | +
|
| 80 | + # OTA_VERSION from current ref |
| 81 | + CURRENT_OTA=$(extract_ota app/constants/ota.ts) |
| 82 | + echo "ota_version=${CURRENT_OTA}" >> "$GITHUB_OUTPUT" |
| 83 | +
|
| 84 | + # Ref to compare against for detecting bump: use release tag if it exists, else main |
| 85 | + if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then |
| 86 | + COMPARE_REF="$RELEASE_TAG" |
| 87 | + BASE_OTA=$(git show "${COMPARE_REF}:app/constants/ota.ts" 2>/dev/null | sed -n '9p' | sed "s/.*'\\([^']*\\)'.*/\1/" || echo "") |
| 88 | + else |
| 89 | + COMPARE_REF="main" |
| 90 | + BASE_OTA=$(git show "origin/main:app/constants/ota.ts" 2>/dev/null | sed -n '9p' | sed "s/.*'\\([^']*\\)'.*/\1/" || echo "") |
| 91 | + echo "Release tag ${RELEASE_TAG} not found; comparing OTA_VERSION to ${COMPARE_REF} to detect bump" |
| 92 | + fi |
| 93 | +
|
| 94 | + if [[ -n "$BASE_OTA" && "$CURRENT_OTA" != "$BASE_OTA" ]]; then |
| 95 | + echo "ota_bump=true" >> "$GITHUB_OUTPUT" |
| 96 | + echo "OTA_VERSION changed: $BASE_OTA -> $CURRENT_OTA → will trigger OTA update" |
| 97 | + else |
| 98 | + echo "ota_bump=false" >> "$GITHUB_OUTPUT" |
| 99 | + echo "No OTA version bump (base: $BASE_OTA, current: $CURRENT_OTA) → will trigger build" |
| 100 | + fi |
| 101 | +
|
| 102 | + trigger-ota: |
| 103 | + name: Trigger OTA update |
| 104 | + needs: decide |
| 105 | + if: needs.decide.outputs.ota_bump == 'true' |
| 106 | + runs-on: ubuntu-latest |
| 107 | + steps: |
| 108 | + - name: Validate PR number |
| 109 | + run: | |
| 110 | + if [[ -z "${{ needs.decide.outputs.pr_number }}" ]]; then |
| 111 | + echo "::error::No PR found for this branch. OTA update requires a PR number." |
| 112 | + echo "::error::If you ran the workflow manually (workflow_dispatch), select your release branch in the 'Use workflow from' dropdown (e.g. release/test-runway-rc-ios-workflow), not main." |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | + echo "Using PR #${{ needs.decide.outputs.pr_number }}" |
| 116 | +
|
| 117 | + - name: Trigger Push OTA Update workflow |
| 118 | + uses: actions/github-script@v6 |
| 119 | + with: |
| 120 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 121 | + script: | |
| 122 | + const ref = '${{ inputs.ref || github.ref_name }}'.replace(/^refs\/heads\//, ''); |
| 123 | + await github.rest.actions.createWorkflowDispatch({ |
| 124 | + owner: context.repo.owner, |
| 125 | + repo: context.repo.repo, |
| 126 | + workflow_id: 'push-eas-update.yml', |
| 127 | + ref: ref, |
| 128 | + inputs: { |
| 129 | + pr_number: '${{ needs.decide.outputs.pr_number }}', |
| 130 | + base_branch: '${{ needs.decide.outputs.base_ref }}', |
| 131 | + message: '${{ needs.decide.outputs.ota_version }}', |
| 132 | + channel: 'rc', |
| 133 | + platform: 'ios' |
| 134 | + } |
| 135 | + }); |
| 136 | + core.notice(`Triggered Push OTA Update on ${ref} (PR #${{ needs.decide.outputs.pr_number }}, base: ${{ needs.decide.outputs.base_ref }}, message: ${{ needs.decide.outputs.ota_version }})`); |
| 137 | +
|
| 138 | + trigger-build: |
| 139 | + name: Trigger build mobile app |
| 140 | + needs: decide |
| 141 | + if: needs.decide.outputs.ota_bump != 'true' |
| 142 | + uses: ./.github/workflows/build.yml |
| 143 | + with: |
| 144 | + build_name: main-rc |
| 145 | + platform: ios |
| 146 | + skip_version_bump: false |
| 147 | + secrets: inherit |
0 commit comments