---
format_version: '8'
default_step_lib_source: 'https://github.com/bitrise-io/bitrise-steplib.git'
project_type: react-native
workflows:
    # Code Setups
    setup:
        steps:
            - activate-ssh-key@4:
                  run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
            - git-clone@4: {}
            - nvm@1.3.0:
                  inputs:
                      - node_version: '14'
    code_setup_cache:
        before_run:
            - setup
        steps:
            - cache-pull@2: {}
            - yarn@0:
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: setup
                  title: Yarn Setup
            - yarn@0:
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: audit:ci
                  title: Audit Dependencies
            - yarn@0:
                  title: Lint
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: lint
                  is_always_run: true
            - cache-push@2: {}
    code_setup:
        before_run:
            - setup
        steps:
            - yarn@0:
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: setup
                  title: Yarn Setup
            - yarn@0:
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: audit:ci
                  title: Audit Dependencies
            - yarn@0:
                  title: Lint
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: lint
                  is_always_run: true
    # CI Steps
    ci_test:
        before_run:
            - code_setup_cache
        steps:
            - yarn@0:
                  inputs:
                      - args: ''
                      - command: test:unit --silent
                  title: Unit Test
                  is_always_run: false
            - script@1:
                  inputs:
                      - content: |-
                            #!/usr/bin/env bash
                            echo 'weew - everything passed!'
                  title: All Tests Passed
                  is_always_run: false
    # E2E Steps
    e2e_setup:
        steps:
            - yarn@:
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: global add detox-cli
                  title: Detox - Install CLI
    android_e2e_test:
        before_run:
            - code_setup
            - e2e_setup
        steps:
            - install-missing-android-tools@2:
                  inputs:
                      - ndk_revision: $NDK_VERSION
                      - gradlew_path: $PROJECT_LOCATION/gradlew
            - avd-manager@1:
                  inputs:
                      - api_level: '29'
                      - create_command_flags: '--sdcard 4096M'
                      - profile: pixel
            - wait-for-android-emulator@1: {}
            - file-downloader@1:
                  inputs:
                      - source: $BITRISEIO_ANDROID_KEYSTORE_URL
                      - destination: android/keystores/release.keystore
            - yarn@0:
                  inputs:
                      - cache_local_deps: 'yes'
                      - command: test:e2e:android
                  title: E2E Tests on Android
                  is_always_run: false
    ios_e2e_test:
        before_run:
            - code_setup
            - e2e_setup
        steps:
            - certificate-and-profile-installer@1: {}
            - set-xcode-build-number@1:
                  inputs:
                      - build_short_version_string: $VERSION_NAME
                      - plist_path: $PROJECT_LOCATION_IOS/MetaMask/Info.plist
            - script:
                  inputs:
                      - content: |-
                            # Add cache directory to environment variable
                            envman add --key BREW_APPLESIMUTILS --value "$(brew --cellar)/applesimutils"
                            envman add --key BREW_OPT_APPLESIMUTILS --value "/usr/local/opt/applesimutils"
                            brew tap wix/brew
                  title: Set Env Path for caching deps
            - cocoapods-install@2:
                  is_always_run: false
            - script@1:
                  inputs:
                      - content: |-
                            #!/usr/bin/env bash
                            node -v
                            METAMASK_ENVIRONMENT='production' yarn test:e2e:ios
                  title: Detox Build & Test
                  is_always_run: false
    start_e2e_tests:
        steps:
            - build-router-start@0:
                  inputs:
                      - workflows: |-
                            ios_e2e_test
                      - wait_for_builds: 'true'
                      - access_token: $BITRISE_START_BUILD_ACCESS_TOKEN
            - build-router-wait@0:
                  inputs:
                      - abort_on_fail: 'yes'
                      - access_token: $BITRISE_START_BUILD_ACCESS_TOKEN
            - script@1:
                  inputs:
                      - content: |-
                            #!/usr/bin/env bash echo 'weew - everything passed!'
                  title: All Tests Passed
                  is_always_run: false
    # Parallel Build & Deploy Steps
    start_bitrise_release_builds:
        before_run:
            - code_setup_cache
        steps:
            - build-router-start@0:
                  inputs:
                      - workflows: |-
                            android_test_release_step
                            ios_test_release_step
                      - wait_for_builds: 'true'
                      - abort_on_fail: 'yes'
                      - access_token: $BITRISE_START_BUILD_ACCESS_TOKEN
            - build-router-wait@0:
                  inputs:
                      - abort_on_fail: 'yes'
                      - build_artifacts_save_path: $BITRISE_DEPLOY_DIR
                      - access_token: $BITRISE_START_BUILD_ACCESS_TOKEN
    start_store_release_builds:
        before_run:
            - code_setup_cache
        steps:
            - build-router-start@0:
                  inputs:
                      - workflows: |-
                            android_store_release_step
                            ios_store_release_step
                      - wait_for_builds: 'true'
                      - abort_on_fail: 'yes'
                      - access_token: $BITRISE_START_BUILD_ACCESS_TOKEN
            - build-router-wait@0:
                  inputs:
                      - abort_on_fail: 'yes'
                      - build_artifacts_save_path: $BITRISE_DEPLOY_DIR
                      - access_token: $BITRISE_START_BUILD_ACCESS_TOKEN
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: $BITRISE_DEPLOY_DIR/app-release.apk
                  title: Bitrise Deploy APK
            - yarn@0:
                  inputs:
                      - command: build:announce
                  title: Accouncing pre-release
                  is_always_run: false
    android_test_release_step:
        before_run:
            - code_setup
        steps:
            - change-android-versioncode-and-versionname@1:
                  inputs:
                      - new_version_name: $VERSION_NAME
                      - new_version_code: $VERSION_NUMBER
                      - build_gradle_path: $PROJECT_LOCATION_ANDROID/app/build.gradle
            - file-downloader@1:
                  inputs:
                      - source: $BITRISEIO_ANDROID_KEYSTORE_URL
                      - destination: android/keystores/release.keystore
            - install-missing-android-tools@2:
                  inputs:
                      - ndk_revision: $NDK_VERSION
                      - gradlew_path: $PROJECT_LOCATION/gradlew
            - script@1:
                  inputs:
                      - content: |-
                            #!/usr/bin/env bash
                            node -v
                            METAMASK_ENVIRONMENT='production' yarn build:android:pre-release:bundle
                  title: Build Android Pre-Release Bundle
                  is_always_run: false
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: $PROJECT_LOCATION/app/build/outputs/apk/release/app-release.apk
                  title: Bitrise Deploy APK
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: $PROJECT_LOCATION/app/build/outputs/apk/release/sha512sums.txt
                  title: Bitrise Deploy Checksum
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: $PROJECT_LOCATION/app/build/outputs/mapping/release/mapping.txt
                  title: Bitrise ProGuard Map Files
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: $PROJECT_LOCATION/app/build/outputs/bundle/release/app-release.aab
                  title: Bitrise Deploy AAB
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: sourcemaps/android/index.js.map
                  title: Bitrise Deploy Sourcemaps
    android_store_release_step:
        before_run:
            - android_test_release_step
        steps:
            - google-play-deploy:
                  inputs:
                      - app_path: $PROJECT_LOCATION/app/build/outputs/bundle/release/app-release.aab
                      - track: internal
                      - service_account_json_key_path: $BITRISEIO_BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL_URL
                      - package_name: $MM_ANDROID_PACKAGE_NAME
        envs:
            - opts:
                  is_expand: false
              MM_ANDROID_PACKAGE_NAME: io.metamask
    ios_test_release_step:
        before_run:
            - code_setup_cache
        steps:
            - certificate-and-profile-installer@1: {}
            - set-xcode-build-number@1:
                  inputs:
                      - build_short_version_string: $VERSION_NAME
                      - build_version: $VERSION_NUMBER
                      - plist_path: $PROJECT_LOCATION_IOS/MetaMask/Info.plist
            - cocoapods-install@2: {}
            - script@1:
                  inputs:
                      - content: |-
                            #!/usr/bin/env bash
                            node -v
                            METAMASK_ENVIRONMENT='production' yarn build:ios:pre-release
                  title: iOS Sourcemaps & Build
                  is_always_run: false
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: ios/build/output/MetaMask.ipa
                  title: Deploy iOS IPA
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: ios/build/MetaMask.xcarchive
                  title: Deploy Symbols File
            - deploy-to-bitrise-io@1:
                  inputs:
                      - deploy_path: sourcemaps/ios/index.js.map
                  title: Deploy Source Map
    ios_store_release_step:
        before_run:
            - ios_test_release_step
        steps:
            - deploy-to-itunesconnect-application-loader@1:
                  inputs:
                      - ipa_path: ios/build/output/MetaMask.ipa
app:
    envs:
        - opts:
              is_expand: false
          PROJECT_LOCATION: android
        - opts:
              is_expand: false
          NDK_VERSION: 21e
        - opts:
              is_expand: false
          MODULE: app
        - opts:
              is_expand: false
          VARIANT: ''
        - opts:
              is_expand: false
          BITRISE_PROJECT_PATH: ios/MetaMask.xcworkspace
        - opts:
              is_expand: false
          BITRISE_SCHEME: MetaMask
        - opts:
              is_expand: false
          BITRISE_EXPORT_METHOD: enterprise
        - opts:
              is_expand: false
          PROJECT_LOCATION_ANDROID: android
        - opts:
              is_expand: false
          PROJECT_LOCATION_IOS: ios
        - opts:
              is_expand: false
          VERSION_NAME: 5.4.0
        - opts:
              is_expand: false
          VERSION_NUMBER: 931
        - opts:
              is_expand: false
          ANDROID_APK_LINK: ''
        - opts:
              is_expand: false
          ANDROID_AAP_LINK: ''
        - opts:
              is_expand: false
          IOS_APP_LINK: ''
meta:
    bitrise.io:
        stack: osx-xcode-13.3.x
