|
| 1 | +name: Sync E/App and Mobile-Expensify versions |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + TARGET_VERSION: |
| 7 | + description: 'Version to sync to (leave empty to auto-detect from Mobile-Expensify)' |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + |
| 11 | +jobs: |
| 12 | + syncVersions: |
| 13 | + runs-on: macos-latest |
| 14 | + steps: |
| 15 | + - name: Check out |
| 16 | + # v4 |
| 17 | + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 |
| 18 | + with: |
| 19 | + ref: main |
| 20 | + submodules: true |
| 21 | + # The OS_BOTIFY_COMMIT_TOKEN is a personal access token tied to osbotify |
| 22 | + # This is a workaround to allow pushes to a protected branch |
| 23 | + token: ${{ secrets.OS_BOTIFY_COMMIT_TOKEN }} |
| 24 | + |
| 25 | + - name: Validate actor is a mobile deployer |
| 26 | + uses: ./.github/actions/composite/validateActor |
| 27 | + with: |
| 28 | + REQUIRE_APP_DEPLOYER: true |
| 29 | + OS_BOTIFY_TOKEN: ${{ secrets.OS_BOTIFY_COMMIT_TOKEN }} |
| 30 | + |
| 31 | + - name: Setup git for OSBotify |
| 32 | + uses: Expensify/GitHub-Actions/setupGitForOSBotify@main |
| 33 | + id: setupGitForOSBotify |
| 34 | + with: |
| 35 | + OP_VAULT: ${{ vars.OP_VAULT }} |
| 36 | + OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} |
| 37 | + SETUP_AS_APP: false |
| 38 | + |
| 39 | + - name: Check current versions |
| 40 | + id: checkVersions |
| 41 | + run: | |
| 42 | + APP_VERSION=$(jq -r .version package.json) |
| 43 | + ME_VERSION=$(jq -r .meta.version Mobile-Expensify/app/config/config.json) |
| 44 | + echo "E/App version: $APP_VERSION" |
| 45 | + echo "Mobile-Expensify version: $ME_VERSION" |
| 46 | + echo "APP_VERSION=$APP_VERSION" >> "$GITHUB_OUTPUT" |
| 47 | + echo "ME_VERSION=$ME_VERSION" >> "$GITHUB_OUTPUT" |
| 48 | + |
| 49 | + if [ "$APP_VERSION" == "$ME_VERSION" ]; then |
| 50 | + echo "::notice::✅ Versions are already in sync: $APP_VERSION" |
| 51 | + echo "IN_SYNC=true" >> "$GITHUB_OUTPUT" |
| 52 | + else |
| 53 | + echo "::warning::⚠️ Versions are out of sync - E/App: $APP_VERSION, Mobile-Expensify: $ME_VERSION" |
| 54 | + echo "IN_SYNC=false" >> "$GITHUB_OUTPUT" |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Determine target version |
| 58 | + if: steps.checkVersions.outputs.IN_SYNC != 'true' |
| 59 | + id: targetVersion |
| 60 | + run: | |
| 61 | + if [ -n "${{ inputs.TARGET_VERSION }}" ]; then |
| 62 | + echo "Using provided target version: ${{ inputs.TARGET_VERSION }}" |
| 63 | + echo "VERSION=${{ inputs.TARGET_VERSION }}" >> "$GITHUB_OUTPUT" |
| 64 | + else |
| 65 | + # Use Mobile-Expensify version as source of truth since it was pushed first |
| 66 | + echo "Using Mobile-Expensify version as target: ${{ steps.checkVersions.outputs.ME_VERSION }}" |
| 67 | + echo "VERSION=${{ steps.checkVersions.outputs.ME_VERSION }}" >> "$GITHUB_OUTPUT" |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Setup Node |
| 71 | + if: steps.checkVersions.outputs.IN_SYNC != 'true' |
| 72 | + uses: ./.github/actions/composite/setupNode |
| 73 | + |
| 74 | + - name: Sync E/App to target version |
| 75 | + if: steps.checkVersions.outputs.IN_SYNC != 'true' |
| 76 | + run: | |
| 77 | + TARGET="${{ steps.targetVersion.outputs.VERSION }}" |
| 78 | + echo "::notice::Syncing E/App to version $TARGET" |
| 79 | + |
| 80 | + # Update version using npm (this updates package.json and package-lock.json) |
| 81 | + npm --no-git-tag-version version "$TARGET" |
| 82 | + |
| 83 | + # Extract version components for native file updates |
| 84 | + SHORT_VERSION="${TARGET%-*}" # e.g., "9.3.11" from "9.3.11-48" |
| 85 | + BUILD_NUMBER="${TARGET#*-}" # e.g., "48" from "9.3.11-48" |
| 86 | + CF_VERSION="${SHORT_VERSION}.${BUILD_NUMBER}" # e.g., "9.3.11.48" |
| 87 | + |
| 88 | + # Pad build number components for Android version code (prefix 10 for E/App) |
| 89 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$SHORT_VERSION" |
| 90 | + ANDROID_VERSION_CODE="10$(printf '%02d' $MAJOR)$(printf '%02d' $MINOR)$(printf '%02d' $PATCH)$(printf '%02d' $BUILD_NUMBER)" |
| 91 | + |
| 92 | + echo "Updating Android build.gradle with versionName=$TARGET, versionCode=$ANDROID_VERSION_CODE" |
| 93 | + sed -i '' "s/versionName \"[0-9.-]*\"/versionName \"$TARGET\"/" android/app/build.gradle |
| 94 | + sed -i '' "s/versionCode [0-9]*/versionCode $ANDROID_VERSION_CODE/" android/app/build.gradle |
| 95 | + |
| 96 | + echo "Updating iOS plists with CFBundleShortVersionString=$SHORT_VERSION, CFBundleVersion=$CF_VERSION" |
| 97 | + /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $SHORT_VERSION" ios/NewExpensify/Info.plist |
| 98 | + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CF_VERSION" ios/NewExpensify/Info.plist |
| 99 | + /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $SHORT_VERSION" ios/NotificationServiceExtension/Info.plist |
| 100 | + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CF_VERSION" ios/NotificationServiceExtension/Info.plist |
| 101 | + /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $SHORT_VERSION" ios/ShareViewController/Info.plist |
| 102 | + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CF_VERSION" ios/ShareViewController/Info.plist |
| 103 | + |
| 104 | + # Commit version changes |
| 105 | + git add package.json package-lock.json android/app/build.gradle ios/*/Info.plist |
| 106 | + git commit -m "Update version to $TARGET (sync recovery)" |
| 107 | + |
| 108 | + # Update submodule reference |
| 109 | + git add Mobile-Expensify |
| 110 | + git commit -m "Update Mobile-Expensify submodule version to $TARGET (sync recovery)" |
| 111 | + |
| 112 | + # Push changes |
| 113 | + if ! git push origin main; then |
| 114 | + echo "::warning::Push failed, attempting rebase..." |
| 115 | + git fetch origin main |
| 116 | + git rebase origin/main |
| 117 | + git push origin main |
| 118 | + fi |
| 119 | + |
| 120 | + echo "::notice::✅ Successfully synced E/App to version $TARGET" |
| 121 | +
|
| 122 | + - name: Verify sync completed |
| 123 | + if: steps.checkVersions.outputs.IN_SYNC != 'true' |
| 124 | + run: | |
| 125 | + APP_VERSION=$(jq -r .version package.json) |
| 126 | + ME_VERSION=$(jq -r .meta.version Mobile-Expensify/app/config/config.json) |
| 127 | + |
| 128 | + if [ "$APP_VERSION" != "$ME_VERSION" ]; then |
| 129 | + echo "::error::Sync failed! Versions still don't match" |
| 130 | + echo "::error::E/App: $APP_VERSION, Mobile-Expensify: $ME_VERSION" |
| 131 | + exit 1 |
| 132 | + fi |
| 133 | + echo "::notice::✅ Versions verified: $APP_VERSION" |
| 134 | +
|
| 135 | + - name: Announce sync in Slack |
| 136 | + if: steps.checkVersions.outputs.IN_SYNC != 'true' |
| 137 | + # v3 |
| 138 | + uses: 8398a7/action-slack@1750b5085f3ec60384090fb7c52965ef822e869e |
| 139 | + with: |
| 140 | + status: custom |
| 141 | + custom_payload: | |
| 142 | + { |
| 143 | + channel: '#deployer', |
| 144 | + attachments: [{ |
| 145 | + color: "good", |
| 146 | + text: `✅ Version sync completed. E/App and Mobile-Expensify are now both at version ${{ steps.targetVersion.outputs.VERSION }}` |
| 147 | + }] |
| 148 | + } |
| 149 | + env: |
| 150 | + GITHUB_TOKEN: ${{ github.token }} |
| 151 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 152 | + |
| 153 | + - name: Announce failed workflow in Slack |
| 154 | + if: ${{ failure() }} |
| 155 | + uses: ./.github/actions/composite/announceFailedWorkflowInSlack |
| 156 | + with: |
| 157 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
0 commit comments