format_version: "8"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: ionic
app:
  envs:
  - APP_NAME: riskwise
  - APPCENTER_NOTIFY_TESTERS: "true"
    opts:
      is_expand: false
  - APPCENTER_OWNER_NAME: S2-Riskwise
    opts:
      is_expand: false
  - BITBUCKET_USERNAME: s2software
    opts:
      is_expand: false
  - BITRISE_PROJECT_PATH: $BITRISE_SOURCE_DIR/ios/App/App.xcworkspace
  - BITRISE_SCHEME_DEV: DEV
  - BITRISE_SCHEME_JLLPROD: JLLPROD
  - BITRISE_SCHEME_PROD: PROD
  - BITRISE_SCHEME_RELEASE: STORE
  - BITRISE_SCHEME_DELIVERY: STAGING
  - FASTLANE_TEAM_ID_CLIENT: null
  - FASTLANE_TEAM_ID_WARACLE: EG4GA65Y37
  - BITBUCKET_URL: api.bitbucket.org
  - JIRA_COMMENT: |-
      *[$BITRISE_APP_TITLE|$BITRISE_APP_URL]* build *[$BITRISE_BUILD_NUMBER|$BITRISE_BUILD_URL]* is now available:

      {panel:title=Bitrise|titleBGColor=#3bc3a3}
      |Build number|[$BITRISE_BUILD_NUMBER|$BITRISE_BUILD_URL]|
      |Author|$GIT_CLONE_COMMIT_AUTHOR_NAME|
      |Branch|$BITRISE_GIT_BRANCH|
      |Commit hash|$GIT_CLONE_COMMIT_HASH|
      |Commit message|$GIT_CLONE_COMMIT_MESSAGE_SUBJECT|
      |PR|$PR|
      {panel}

      {panel:title=App Center|titleBGColor=#009EE1}
      Build number: $BITRISE_BUILD_NUMBER Available in App Center.
      https://appcenter.ms/orgs/$APPCENTER_OWNER_NAME/applications
      {panel}
    opts:
      is_expand: false
  - IONIC_WORK_DIR: .
    opts:
      is_expand: false
  - IONIC_PLATFORM: ios,android
    opts:
      is_expand: false
  - JIRA_URL: waracle.atlassian.net
    opts:
      is_expand: false
  - JIRA_USERNAME: webmaster@waracle.com
    opts:
      is_expand: false
  - MATCH_APP_IDENTIFIER_CLIENT: com.s2partnership.development.JLLRiskWise, com.s2partnership.JLLRiskWise
    opts:
      is_expand: false
  - MATCH_APP_IDENTIFIER_WARACLE: com.waracle.s2.riskwise.dev,com.waracle.s2.riskwise.staging,com.waracle.s2.riskwise.prod
    opts:
      is_expand: false
  - MATCH_GIT_BRANCH_CLIENT: null
  - MATCH_GIT_BRANCH_WARACLE: waracle_enterprise
  - PILOT_TEAM_ID_CLIENT: null
    opts:
      is_expand: false
  - PILOT_TEAM_ID_WARACLE: ""
    opts:
      is_expand: false
  - RISKWISE_ENCRYPTION_KEY: p2r5u8x/A?D(G+KbPeShVmYq3t6v9y$B
  - SCAN_DEVICES: iPhone 7
    opts:
      is_expand: false
  - SCAN_SCHEME: ${BITRISE_SCHEME_DEV}
    opts:
      is_expand: true
  - SLACK_CHANNEL: '#s2.riskwise-feed'
    opts:
      is_expand: false
  - XCPRETTY_ARGS: --color --output "${BITRISE_DEPLOY_DIR}/xcode-test-results-${BITRISE_SCHEME}.html"
  - RISKWISE_BASE_URL: staging-api-layer.s2qa.com
    opts:
      is_expand: false
trigger_map:
- push_branch: main
  workflow: S2DeliveryWorkflow
- push_branch: develop
  workflow: S2devWorkflow
- pull_request_source_branch: '*'
  workflow: S2devWorkflow
- tag: '*.*.*'
  workflow: S2ProductionWorkflow
workflows:
  _dev:
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: true
    - RISKWISE_API_URL: https://${RISKWISE_BASE_URL}/xml_api_2_9_1
    - APPEND_NAME: _QA
    - APP_ID: com.s2partnership.development.JLLRiskWise
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    steps:
    - npm@1:
        title: Set AppId
        inputs:
        - command: run appId -- --appId=${APP_ID}
    - script@1:
        title: Set AppId in Android project
        inputs:
        - is_debug: "yes"
        - working_dir: $BITRISE_SOURCE_DIR/android
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # Fix for 'sed: RE error: illegal byte sequence' error
            export LC_ALL=C

            grep -rli 'com.waracle.s2.riskwise' * | xargs -I@ sed -i '' -E "s/com.waracle.s2.riskwise.(dev|staging|prod)/${APP_ID}/g" @
    - npm@1:
        title: Build Web Project
        inputs:
        - command: run build
    - script@1:
        title: Sync Android Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx jetify
            npx cap sync android
    - android-build@0:
        title: Build Android DEV
        inputs:
        - variant: ${BITRISE_SCHEME_DEV}Debug
        - module: app
        - project_location: $BITRISE_SOURCE_DIR/android
    - script@1:
        title: Sync iOS Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx cap sync ios
    - xcode-archive@2:
        title: Build iOS DEV
        inputs:
        - export_method: enterprise
        - team_id: $FASTLANE_TEAM_ID_WARACLE
        - force_provisioning_profile: ${sigh_com.waracle.s2.riskwise.dev_dev}
        - scheme: $BITRISE_SCHEME_DEV
        - configuration: $BITRISE_SCHEME_DEV Debug
  _post-workflow:
    envs:
    - HOMEBREW_NO_AUTO_UPDATE: "1"
      opts:
        is_expand: false
    steps:
    - deploy-to-bitrise-io:
        inputs:
        - is_enable_public_page: "false"
        - notify_user_groups: none
    - cache-push@2:
        is_always_run: true
    - script@1:
        title: Trigger Jenkins Build
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            curl -X GET "https://ci.s2qa.com/job/RiskWise%20Hybrid/build?token=f762795gb1J5p3T_Hybr|d"
    - script@1:
        title: Populate JIRA Comment
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            usage(){ echo "Usage: $0 -v [-?] -- program to update the an environment variable containing placeholders
            where:
                -?  show this help text
                -v  variable to update
                -d  enable debug" 1>&2;
            exit 1;
            }
            if [[ "${is_debug}" == "yes" ]]; then
              set -x
            fi
            # is envsubst available
            if [[ ! -x "$(command -v envsubst)" ]]; then
              echo "envsubst is required, but is unavailable.  Attempting to install now"
              if [[ "$OSTYPE" == "linux-gnu" ]]; then
                # *nix
                apt-get update -qq && apt-get install -qqy --no-install-recommends gettext-base
              elif [[ "$OSTYPE" == "darwin"* ]]; then
                # mac
                brew update && brew upgrade gettext && brew link --force gettext
              else
                echo "Unsupported OS, exiting"
                exit 1
              fi
            fi
            while getopts ':v:d?' option; do
              case "$option" in
                v) VARIABLE_NAME="${OPTARG:-JIRA_COMMENT}"
                   ;;
                d) set -x
                    is_debug='yes'
                   ;;
                ?) usage
                exit 1
                   ;;
              esac
            done
            shift $((OPTIND - 1))
            VARIABLE_NAME='JIRA_COMMENT'
            if [[ "${is_debug}" == "yes" ]]; then
              echo "Variable to update: ${VARIABLE_NAME}"
            fi
            # use shell substitution to expand the $VARIABLE_NAME and export the updated variable
            export $VARIABLE_NAME="$(cat << EOF | sh
            echo "${!VARIABLE_NAME}"
            EOF
            )"
            echo "envman add --key \"${VARIABLE_NAME}\" --value \"${!VARIABLE_NAME}\""
            if  [ -x "$(command -v envman)" ]; then
              echo "Adding variable to envman in bitrise"
              envman add --key "${VARIABLE_NAME}" --value "${!VARIABLE_NAME}"
            fi
    - bitbucket-snippet-runner:
        title: Populate JIRA Comment
        run_if: "false"
        inputs:
        - script_args: -v JIRA_COMMENT
        - is_debug: "yes"
        - script_url: https://bitbucket.org/snippets/waracle/aeej7G
    - git::https://github.com/Waracle/update-jira-bitrise-step.git@1.1.5:
        is_skippable: true
        inputs:
        - jira_comment: $JIRA_COMMENT
  _pre-work:
    after_run:
    - download_profiles
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: "true"
      opts:
        is_expand: false
    - RISKWISE_API_URL: https://delivery-api-layer.s2qa.com/xml_api_2_9_1
      opts:
        is_expand: false
    - APPEND_NAME: _DEL
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    steps:
    - activate-ssh-key@4:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4: {}
    - cache-pull@2: {}
    - build-number-adjust@1.0.0:
        title: Set build number locally
        run_if: not .IsCI
        inputs:
        - change: "1"
    - certificate-and-profile-installer@1: {}
    - nvm@1:
        title: Initialise Node
        run_if: .IsCI
    - script@1:
        inputs:
        - content: git config --global url."https://".insteadOf git://
    - npm@1:
        title: Install dependencies (CI)
        run_if: .IsCI
        inputs:
        - command: ci
        - cache_local_deps: "true"
        - workdir: $IONIC_WORK_DIR
    - npm@1:
        title: Install dependencies (Local)
        run_if: not .IsCI
        inputs:
        - command: install
        - cache_local_deps: "true"
        - workdir: $IONIC_WORK_DIR
    - npm@1:
        title: Lint
        inputs:
        - command: run lint
        - workdir: $IONIC_WORK_DIR
    - npm@1:
        title: Run unit tests
        inputs:
        - command: run test:ci
        - workdir: $IONIC_WORK_DIR
    - custom-test-results-export@0:
        inputs:
        - base_path: $BITRISE_SOURCE_DIR/test-results/unit/UnitTests.xml
        - search_pattern: '*'
        - test_name: Unit Tests
    - npm@1:
        title: Run e2e tests
        run_if: .IsCI
        inputs:
        - command: run e2e:ci
        - workdir: $IONIC_WORK_DIR
    - npm@1:
        title: Merge e2e test results
        run_if: .IsCI
        inputs:
        - command: run e2e:merge
        - workdir: $IONIC_WORK_DIR
    - custom-test-results-export@0:
        run_if: .IsCI
        inputs:
        - base_path: $BITRISE_SOURCE_DIR/test-results/e2e/E2ETests.xml
        - search_pattern: '*'
        - test_name: E2E Tests
    - npm@1:
        title: Semantic Release
        run_if: .IsCI
        inputs:
        - command: run semantic-release
        - workdir: $IONIC_WORK_DIR
    - bitbucket-snippet-runner@1:
        title: Set version name
        inputs:
        - script_args: '"-n VERSION_NAME"'
        - is_debug: "yes"
        - script_url: https://bitbucket.org/snippets/waracle/eL5ybo
  _prod:
    envs:
    - APPCENTER_APP_NAME_ANDROID: ${APP_NAME}-PROD-1
    - RISKWISE_ANGULAR_DEV_MODE: false
    - APPCENTER_APP_NAME_IOS: ${APP_NAME}-PROD
    - RISKWISE_BASE_URL: api-layer.s2riskwise.com
      opts:
        is_expand: false
    - RISKWISE_API_URL: https://${RISKWISE_BASE_URL}/xml_api_2_9_1
    - APPEND_NAME: _LIVE
    - APPCENTER_DISTRIBUTE_DESTINATIONS: Collaborators
    - APP_ID: com.s2partnership.JLLRiskWise
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    steps:
    - npm@1:
        title: Set AppId
        inputs:
        - command: run appId -- --appId=${APP_ID}
    - script@1:
        title: Set AppId in Android project
        inputs:
        - is_debug: "yes"
        - working_dir: $BITRISE_SOURCE_DIR/android
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # Fix for 'sed: RE error: illegal byte sequence' error
            export LC_ALL=C

            grep -rli 'com.waracle.s2.riskwise' * | xargs -I@ sed -i '' -E "s/com.waracle.s2.riskwise.(dev|staging|prod)/${APP_ID}/g" @
    - npm@1:
        title: Build Web Project PROD
        inputs:
        - command: run build:prod
    - script@1:
        title: Sync Android Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx jetify
            npx cap sync android
    - android-build@0:
        title: Build Android PROD
        inputs:
        - variant: ${BITRISE_SCHEME_PROD}Release
        - module: app
        - project_location: $BITRISE_SOURCE_DIR/android
    - sign-apk@1:
        title: Sign Android PROD
        run_if: '{{getenv "BITRISE_APK_PATH" | ne ""}}'
        inputs:
        - output_name: $APPCENTER_APP_NAME_ANDROID-release-bitrise-signed
    - fastlane@2:
        title: AppCenter Android Deploy
        description: Deploy the Android build to AppCenter
        run_if: .IsCI
        inputs:
        - update_fastlane: "false"
        - verbose_log: "yes"
        - lane: upload_appcenter app_name:$APPCENTER_APP_NAME_ANDROID file:$BITRISE_SIGNED_APK_PATH mapping:$BITRISE_MAPPING_PATH platform:android
    - script@1:
        title: Sync iOS Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx cap sync ios
    - xcode-archive@2:
        title: Build iOS PROD
        inputs:
        - export_method: enterprise
        - team_id: $FASTLANE_TEAM_ID_WARACLE
        - force_provisioning_profile: ${sigh_com.waracle.s2.riskwise.prod_enterprise}
        - configuration: $BITRISE_SCHEME_PROD Release
        - scheme: $BITRISE_SCHEME_PROD
    - fastlane@2:
        title: AppCenter iOS Deploy
        description: Deploy the iOS build to AppCenter
        run_if: .IsCI
        inputs:
        - update_fastlane: "false"
        - verbose_log: "yes"
        - lane: upload_appcenter app_name:$APPCENTER_APP_NAME_IOS file:$BITRISE_IPA_PATH dsym:$BITRISE_DSYM_PATH platform:ios
  _S2_post-workflow:
    envs:
    - HOMEBREW_NO_AUTO_UPDATE: "1"
      opts:
        is_expand: false
    steps:
    - deploy-to-bitrise-io:
        inputs:
        - is_enable_public_page: "false"
        - notify_user_groups: none
    - cache-push@2:
        is_always_run: true
  _S2-pre-work:
    after_run: []
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: "true"
      opts:
        is_expand: false
    - RISKWISE_API_URL: https://delivery-api-layer.s2qa.com/xml_api_2_9_1
      opts:
        is_expand: false
    - APPEND_NAME: _DEL
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    steps:
    - set-java-version@1:
        inputs:
        - set_java_version: "17"
    - activate-ssh-key@4:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@6: {}
    - cache-pull@2: {}
    - build-number-adjust@1.0.0:
        title: Set build number locally
        run_if: not .IsCI
        inputs:
        - change: "1"
    - certificate-and-profile-installer@1: {}
    - script@1:
        inputs:
        - content: git config --global url."https://".insteadOf git://
        title: Applying git fix to use https:// instead of git://
    - brew-install@1:
        inputs:
        - packages: rbenv ruby-build
        - verbose_log: "yes"
        title: Installing rbenv
    - script@1:
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
            set -o pipefail
            # debug log
            set -x

            # write your script here
            rbenv version

            # or run a script from your repository, like:
            # bash ./path/to/script.sh
            # not just bash, e.g.:
            # ruby ./path/to/script.rb
        title: Show installed ruby version
    - nvm@1:
        title: Initialise Node
        run_if: .IsCI
    - npm@1:
        title: Install dependencies (CI)
        run_if: .IsCI
        inputs:
        - command: ci
        - cache_local_deps: "true"
        - workdir: $IONIC_WORK_DIR
    - npm@1:
        title: Install dependencies (Local)
        run_if: not .IsCI
        inputs:
        - command: install
        - cache_local_deps: "true"
        - workdir: $IONIC_WORK_DIR
    - npm@1:
        title: Semantic Release
        run_if: .IsCI
        inputs:
        - command: run semantic-release
        - workdir: $IONIC_WORK_DIR
    - script@1:
        title: Set version name script
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
            set -o pipefail
            # debug log
            set -x

            name="VERSION_NAME"

            # write your script here

            #!/usr/bin/env bash

            # Begin Standard 'imports'
            set -e
            set -o pipefail

            ## Bash v4.x and bash v.3x use different escape characters
            if [ "${BASH_VERSINFO:-0}" -ge 4 ]; then
              ESCAPE_CHAR='\e'
            else
              ESCAPE_CHAR='\033'
            fi

            gray="${ESCAPE_CHAR}[37m"
            blue="${ESCAPE_CHAR}[36m"
            red="${ESCAPE_CHAR}[31m"
            yellow="${ESCAPE_CHAR}[33m"
            green="${ESCAPE_CHAR}[32m"
            reset="${ESCAPE_CHAR}[0m"

            #######################################
            # echoes a message in blue
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            info() { echo -e "${blue}INFO: $*${reset}"; }

            #######################################
            # echoes a message in red
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            error() { echo -e "${red}ERROR: $*${reset}"; }

            #######################################
            # echoes a message in yellow
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            warn() { echo -e "${yellow}WARN: $*${reset}"; }

            #######################################
            # echoes a message in grey. Only if debug mode is enabled
            # Globals:
            #   DEBUG
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            debug() {
              echo -e "${gray}DEBUG: $*${reset}"
            }

            #######################################
            # echoes a message in green
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            success() { echo -e "${green}âœ” $*${reset}"; }

            #######################################
            # echoes a message in red and terminates the program
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            fail() {
              echo -e "${red}âœ– $*${reset}"
              exit 1
            }

            ## Enable debug mode.
            enable_debug() {
              if [[ "${DEBUG}" == "true" ]]; then
                info "Enabling debug mode."
                set -x
              fi
            }

            #######################################
            # echoes a message in blue
            # Globals:
            #   status: Exit status of the command that was executed.
            #   output_file: Local path with captured output generated from the command.
            # Arguments:
            #   command: command to run
            # Returns:
            #   None
            #######################################
            run() {
              output_file="/var/tmp/pipe-$(date +%s)-$RANDOM"

              echo "$@"
              set +e
              "$@" | tee "$output_file"
              status=$?
              set -e
            }

            # End standard 'imports'

            usage() {
              printf "Usage: %s -n [-p] [-v] [-?] -- program to populate the specified version param with version from package.json

            where:
                -?, --help                show this help text
                -n, --name                the name of the environment variable to set
                -p, --package-json        the path to the package.json
                                          defaults to './package.json'
                -v, --verbose             enable verbose mode (for debuggin)\n" "$(basename "$0")" 1>&2
              exit 1
            }

            # Transform long options to short ones
            for arg in "$@"; do
              shift
              case "$arg" in
              "--help") set -- "$@" "-?" ;;
              "--name") set -- "$@" "-n" ;;
              "--package-json") set -- "$@" "-p" ;;
              "--verbose") set -- "$@" "-v" ;;
              *) set -- "$@" "$arg" ;;
              esac
            done

            while getopts 'n:p:v?' option; do
              case "$option" in
              n) name="${OPTARG}" ;;
              p) package_json="${OPTARG}" ;;
              v) set -x ;;
              \?)
                usage
                exit 1
                ;;
              :)
                printf "%s","Option -${OPTARG} requires an argument."
                usage
                exit 1
                ;;
              esac
            done
            shift $((OPTIND - 1))

            if ! command -v envman > /dev/null; then
              fail "envman not found. Are you running within a bitrise environment?"
            fi

            # name must be provided, fail if not
            if [[ -z ${name+x} ]]; then
              error "Parameter 'name' must be provided"
              usage
            fi

            # get the package.json path or use default
            if [[ -z ${package_json+x} ]]; then
              info "Setting package_json to default (./package.json)"
              package_json="./package.json"
            fi

            # if package.json doesn't exist now, fail
            if [ ! -f "${package_json}" ]; then
              fail "No package.json found at ${package_json}"
            fi

            debug "Reading version number from package.json"
            version="$(node -p require\("'${package_json}'"\).version)"
    description: The full pre-work workflow that sets up the MacOSX virtual machine, installs all dependencies and runs linting, unit tests and e2e tests.
  _S2delivery:
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: true
    - opts:
        is_expand: false
      RISKWISE_BASE_URL: delivery-api-layer.s2qa.com
    - RISKWISE_API_URL: https://${RISKWISE_BASE_URL}/xml_api_2_9_1
    - APPEND_NAME: _DEL
    - APP_ID: com.s2partnership.development.JLLRiskWise
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    - opts:
        is_expand: false
      PORTAL_TEAM: 8AU8ZNPGJH
    steps:
    - npm@1:
        title: Set AppId
        inputs:
        - command: run appId -- --appId=${APP_ID}
    - script@1:
        title: Set AppId in Android project
        inputs:
        - is_debug: "yes"
        - working_dir: $BITRISE_SOURCE_DIR/android
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # Fix for 'sed: RE error: illegal byte sequence' error
            export LC_ALL=C

            grep -rli 'com.s2partnership.development.JLLRiskWise' * | xargs -I@ sed -i '' -E "s/com.s2partnership.development.JLLRiskWise.(dev|staging|prod)/${APP_ID}/g" @

            echo $RISKWISE_API_URL
            echo $RISKWISE_BASE_URL
    - npm@1:
        title: Build Web Project
        inputs:
        - command: run build
    - script@1:
        title: Sync Android Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx jetify
            npx cap sync android
    - android-build@1:
        title: Build Android DEV
        inputs:
        - variant: ${BITRISE_SCHEME_DELIVERY}Debug
        - module: app
        - project_location: $BITRISE_SOURCE_DIR/android
    - script@1:
        title: Sync iOS Platform
        inputs:
        - is_debug: "yes"
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx cap sync ios
    - xcode-archive@4:
        title: Build iOS DEV
        inputs:
        - scheme: $BITRISE_SCHEME_DELIVERY
        - export_development_team: $PORTAL_TEAM
        - distribution_method: ad-hoc
        - configuration: $BITRISE_SCHEME_DELIVERY Debug
        is_always_run: true
  _S2dev:
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: true
    - RISKWISE_API_URL: https://${RISKWISE_BASE_URL}/xml_api_2_9_1
    - APPEND_NAME: _QA
    - APP_ID: com.s2partnership.development.JLLRiskWise
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    - opts:
        is_expand: false
      PORTAL_TEAM: 8AU8ZNPGJH
    steps:
    - npm@1:
        title: Set AppId
        inputs:
        - command: run appId -- --appId=${APP_ID}
    - script@1:
        title: Set AppId in Android project
        inputs:
        - is_debug: "yes"
        - working_dir: $BITRISE_SOURCE_DIR/android
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # Fix for 'sed: RE error: illegal byte sequence' error
            export LC_ALL=C

            grep -rli 'com.s2partnership.development.JLLRiskWise' * | xargs -I@ sed -i '' -E "s/com.s2partnership.development.JLLRiskWise.(dev|staging|prod)/${APP_ID}/g" @

            echo $RISKWISE_API_URL
    - npm@1:
        title: Build Web Project
        inputs:
        - command: run build
    - script@1:
        title: Sync Android Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx jetify
            npx cap sync android
    - android-build@1:
        title: Build Android DEV
        inputs:
        - variant: ${BITRISE_SCHEME_DEV}Debug
        - module: app
        - project_location: $BITRISE_SOURCE_DIR/android
    - script@1:
        title: Sync iOS Platform
        inputs:
        - is_debug: "yes"
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx cap sync ios
    - xcode-archive@4:
        title: Build iOS DEV
        inputs:
        - scheme: $BITRISE_SCHEME_DEV
        - export_development_team: $PORTAL_TEAM
        - distribution_method: ad-hoc
        - configuration: $BITRISE_SCHEME_DEV Release
        is_always_run: true
  _S2JLLproduction:
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: "false"
    - opts:
        is_expand: false
      RISKWISE_BASE_URL: api-layer.s2riskwise.com
    - RISKWISE_API_URL: https://${RISKWISE_BASE_URL}/xml_api_2_9_1
    - APPEND_NAME: ""
    - APP_ID: com.s2partnership.JLLRiskWise
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "1"
    - opts:
        is_expand: false
      PORTAL_TEAM: R797FP47HK
    - APPCENTER_APP_NAME_ANDROID: ${APP_NAME}-JLLPROD
    - APPCENTER_APP_NAME_IOS: ${APP_NAME}-JLLPROD
    steps:
    - npm@1:
        title: Set AppId
        inputs:
        - command: run appId -- --appId=${APP_ID}
    - script@1:
        title: Set AppId in Android project
        inputs:
        - is_debug: "yes"
        - working_dir: $BITRISE_SOURCE_DIR/android
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # Fix for 'sed: RE error: illegal byte sequence' error
            export LC_ALL=C

            grep -rli 'com.s2partnership.JLLRiskWise' * | xargs -I@ sed -i '' -E "s/com.s2partnership.JLLRiskWise.(dev|staging|prod)/${APP_ID}/g" @

            echo $RISKWISE_API_URL
            echo $RISKWISE_BASE_URL
    - npm@1:
        title: Build Web Project
        inputs:
        - command: run build
    - script@1:
        title: Sync Android Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx jetify
            npx cap sync android
    - android-build@1:
        title: Build Android DEV
        inputs:
        - variant: ${BITRISE_SCHEME_JLLPROD}Debug
        - module: app
        - project_location: $BITRISE_SOURCE_DIR/android
    - script@1:
        title: Sync iOS Platform
        inputs:
        - is_debug: "yes"
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx cap sync ios
    - xcode-archive@4:
        title: Build iOS DEV
        inputs:
        - scheme: $BITRISE_SCHEME_JLLPROD
        - export_development_team: $PORTAL_TEAM
        - distribution_method: enterprise
        - configuration: $BITRISE_SCHEME_JLLPROD Release
        is_always_run: true
    description: The workflow used to produce a general (non client specific build) pointing to the live api-layer endpoint.
  _S2limited-pre-work:
    after_run: []
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: "true"
      opts:
        is_expand: false
    - RISKWISE_API_URL: https://delivery-api-layer.s2qa.com/xml_api_2_9_1
      opts:
        is_expand: false
    - APPEND_NAME: _DEL
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    steps:
    - set-java-version@1:
        inputs:
        - set_java_version: "17"
    - activate-ssh-key@4:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@6: {}
    - cache-pull@2: {}
    - build-number-adjust@1.0.0:
        title: Set build number locally
        run_if: not .IsCI
        inputs:
        - change: "1"
    - certificate-and-profile-installer@1: {}
    - script@1:
        inputs:
        - content: git config --global url."https://".insteadOf git://
        title: Applying git fix to use https:// instead of git://
    - brew-install@0:
        inputs:
        - verbose_log: "yes"
        - packages: rbenv ruby-build
        title: Installing rbenv
    - script@1:
        title: Show installed ruby version
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
            set -o pipefail
            # debug log
            set -x

            # write your script here
            rbenv version

            # or run a script from your repository, like:
            # bash ./path/to/script.sh
            # not just bash, e.g.:
            # ruby ./path/to/script.rb
    - nvm@1.2:
        title: Initialise Node
        run_if: .IsCI
        inputs:
        - node_version: 16.19.1
    - npm@1.0:
        title: Install dependencies (CI)
        run_if: .IsCI
        inputs:
        - command: ci
        - cache_local_deps: "true"
        - workdir: $IONIC_WORK_DIR
    - npm@1.0:
        title: Install dependencies (Local)
        run_if: not .IsCI
        inputs:
        - command: install
        - cache_local_deps: "true"
        - workdir: $IONIC_WORK_DIR
    - script@1:
        title: Set version name script
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
            set -o pipefail
            # debug log
            set -x

            name="VERSION_NAME"

            # write your script here

            #!/usr/bin/env bash

            # Begin Standard 'imports'
            set -e
            set -o pipefail

            ## Bash v4.x and bash v.3x use different escape characters
            if [ "${BASH_VERSINFO:-0}" -ge 4 ]; then
              ESCAPE_CHAR='\e'
            else
              ESCAPE_CHAR='\033'
            fi

            gray="${ESCAPE_CHAR}[37m"
            blue="${ESCAPE_CHAR}[36m"
            red="${ESCAPE_CHAR}[31m"
            yellow="${ESCAPE_CHAR}[33m"
            green="${ESCAPE_CHAR}[32m"
            reset="${ESCAPE_CHAR}[0m"

            #######################################
            # echoes a message in blue
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            info() { echo -e "${blue}INFO: $*${reset}"; }

            #######################################
            # echoes a message in red
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            error() { echo -e "${red}ERROR: $*${reset}"; }

            #######################################
            # echoes a message in yellow
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            warn() { echo -e "${yellow}WARN: $*${reset}"; }

            #######################################
            # echoes a message in grey. Only if debug mode is enabled
            # Globals:
            #   DEBUG
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            debug() {
              echo -e "${gray}DEBUG: $*${reset}"
            }

            #######################################
            # echoes a message in green
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            success() { echo -e "${green}âœ” $*${reset}"; }

            #######################################
            # echoes a message in red and terminates the program
            # Globals:
            #   None
            # Arguments:
            #   Message
            # Returns:
            #   None
            #######################################
            fail() {
              echo -e "${red}âœ– $*${reset}"
              exit 1
            }

            ## Enable debug mode.
            enable_debug() {
              if [[ "${DEBUG}" == "true" ]]; then
                info "Enabling debug mode."
                set -x
              fi
            }

            #######################################
            # echoes a message in blue
            # Globals:
            #   status: Exit status of the command that was executed.
            #   output_file: Local path with captured output generated from the command.
            # Arguments:
            #   command: command to run
            # Returns:
            #   None
            #######################################
            run() {
              output_file="/var/tmp/pipe-$(date +%s)-$RANDOM"

              echo "$@"
              set +e
              "$@" | tee "$output_file"
              status=$?
              set -e
            }

            # End standard 'imports'

            usage() {
              printf "Usage: %s -n [-p] [-v] [-?] -- program to populate the specified version param with version from package.json

            where:
                -?, --help                show this help text
                -n, --name                the name of the environment variable to set
                -p, --package-json        the path to the package.json
                                          defaults to './package.json'
                -v, --verbose             enable verbose mode (for debuggin)\n" "$(basename "$0")" 1>&2
              exit 1
            }

            # Transform long options to short ones
            for arg in "$@"; do
              shift
              case "$arg" in
              "--help") set -- "$@" "-?" ;;
              "--name") set -- "$@" "-n" ;;
              "--package-json") set -- "$@" "-p" ;;
              "--verbose") set -- "$@" "-v" ;;
              *) set -- "$@" "$arg" ;;
              esac
            done

            while getopts 'n:p:v?' option; do
              case "$option" in
              n) name="${OPTARG}" ;;
              p) package_json="${OPTARG}" ;;
              v) set -x ;;
              \?)
                usage
                exit 1
                ;;
              :)
                printf "%s","Option -${OPTARG} requires an argument."
                usage
                exit 1
                ;;
              esac
            done
            shift $((OPTIND - 1))

            if ! command -v envman > /dev/null; then
              fail "envman not found. Are you running within a bitrise environment?"
            fi

            # name must be provided, fail if not
            if [[ -z ${name+x} ]]; then
              error "Parameter 'name' must be provided"
              usage
            fi

            # get the package.json path or use default
            if [[ -z ${package_json+x} ]]; then
              info "Setting package_json to default (./package.json)"
              package_json="./package.json"
            fi

            # if package.json doesn't exist now, fail
            if [ ! -f "${package_json}" ]; then
              fail "No package.json found at ${package_json}"
            fi

            debug "Reading version number from package.json"
            version="$(node -p require\("'${package_json}'"\).version)"

            info "Setting ${name} to ${version}"
            run envman add --key "${name}" --value "${version}"

            if [[ "${status}" -ne "0" ]]; then
              fail "Failed to set ${name} to ${version} using envman"
            fi

            success "Set ${name} to ${version}"

            # or run a script from your repository, like:
            # bash ./path/to/script.sh
            # not just bash, e.g.:
            # ruby ./path/to/script.rb
  _S2production:
    envs:
    - RISKWISE_ANGULAR_DEV_MODE: true
    - opts:
        is_expand: false
      RISKWISE_BASE_URL: api-layer.s2riskwise.com
    - RISKWISE_API_URL: https://${RISKWISE_BASE_URL}/xml_api_2_9_1
    - APPEND_NAME: _LIVE
    - APP_ID: com.s2partnership.hybridRiskWise
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    - opts:
        is_expand: false
      PORTAL_TEAM: 8AU8ZNPGJH
    steps:
    - npm@1:
        title: Set AppId
        inputs:
        - command: run appId -- --appId=${APP_ID}
    - script@1:
        title: Set AppId in Android project
        inputs:
        - is_debug: "yes"
        - working_dir: $BITRISE_SOURCE_DIR/android
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # Fix for 'sed: RE error: illegal byte sequence' error
            export LC_ALL=C

            grep -rli 'com.s2partnership.hybrid' * | xargs -I@ sed -i '' -E "s/com.s2partnership.hybrid.(dev|staging|prod)/${APP_ID}/g" @

            echo $RISKWISE_API_URL
            echo $RISKWISE_BASE_URL
    - npm@1:
        title: Build Web Project
        inputs:
        - command: run build
    - script@1:
        title: Sync Android Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx jetify
            npx cap sync android
    - android-build@1:
        title: Build Android DEV
        inputs:
        - variant: ${BITRISE_SCHEME_PROD}Debug
        - module: app
        - project_location: $BITRISE_SOURCE_DIR/android
    - script@1:
        title: Sync iOS Platform
        inputs:
        - is_debug: "yes"
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx cap sync ios
    - xcode-archive@4:
        title: Build iOS DEV
        inputs:
        - scheme: $BITRISE_SCHEME_PROD
        - export_development_team: $PORTAL_TEAM
        - distribution_method: app-store
        - configuration: $BITRISE_SCHEME_PROD Debug
        is_always_run: true
    description: The workflow used to produce a general (non client specific build) pointing to the live api-layer endpoint.
  _staging:
    envs:
    - APPCENTER_APP_NAME_ANDROID: ${APP_NAME}-DELIVERY-1
    - APPCENTER_APP_NAME_IOS: ${APP_NAME}-DELIVERY
    - APPCENTER_DISTRIBUTE_DESTINATIONS: Collaborators
    - RISKWISE_ANGULAR_DEV_MODE: true
    - RISKWISE_BASE_URL: delivery-api-layer.s2qa.com
      opts:
        is_expand: false
    - RISKWISE_API_URL: https://${RISKWISE_BASE_URL}/xml_api_2_9_1
    - APPEND_NAME: _DEL
    - APP_ID: com.s2partnership.development.JLLRiskWise
      opts:
        is_expand: false
    - opts:
        is_expand: false
      IS_JLL_BUILD: "0"
    steps:
    - npm@1:
        title: Set AppId
        inputs:
        - command: run appId -- --appId=${APP_ID}
    - script@1:
        title: Set AppId in Android project
        inputs:
        - is_debug: "yes"
        - working_dir: $BITRISE_SOURCE_DIR/android
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # Fix for 'sed: RE error: illegal byte sequence' error
            export LC_ALL=C

            grep -rli 'com.waracle.s2.riskwise' * | xargs -I@ sed -i '' -E "s/com.waracle.s2.riskwise.(dev|staging|prod)/${APP_ID}/g" @
    - npm@1:
        title: Build Web Project
        inputs:
        - command: run build
    - script@1:
        title: Sync Android Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx jetify
            npx cap sync android
    - android-build@0:
        title: Build Android DELIVERY
        inputs:
        - variant: ${BITRISE_SCHEME_DELIVERY}Debug
        - module: app
        - project_location: $BITRISE_SOURCE_DIR/android
    - sign-apk@1:
        title: Sign Android STAGING
        run_if: '{{getenv "BITRISE_APK_PATH" | ne ""}}'
        inputs:
        - output_name: $APPCENTER_APP_NAME_ANDROID-release-bitrise-signed
    - fastlane@2:
        title: AppCenter Android Deploy
        description: Deploy the Android build to AppCenter
        inputs:
        - update_fastlane: "false"
        - verbose_log: "yes"
        - lane: upload_appcenter app_name:$APPCENTER_APP_NAME_ANDROID file:$BITRISE_SIGNED_APK_PATH mapping:$BITRISE_MAPPING_PATH platform:android
    - git::https://github.com/Waracle/bitbucket-pr-comment-bitrise-step.git@0.1.2:
        title: Add Android AppCenter comment to PR
        is_skippable: true
        inputs:
        - bitbucket_url: $BITBUCKET_URL
        - bitbucket_user: $BITBUCKET_PR_USER
        - bitbucket_password: $BITBUCKET_PR_PASSWORD
        - bitbucket_pr_comment: |-
            The Android build from [build $BITRISE_BUILD_NUMBER]($BITRISE_BUILD_URL) of this pull request is now available on App Center.

            The build can be installed from [here]($APPCENTER_DEPLOY_DOWNLOAD_URL)
    - script@1:
        title: Sync iOS Platform
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            # write your script here
            npx cap sync ios
    - xcode-archive@2:
        title: Build iOS STAGING
        inputs:
        - export_method: enterprise
        - team_id: $FASTLANE_TEAM_ID_WARACLE
        - force_provisioning_profile: ${sigh_com.waracle.s2.riskwise.staging_enterprise}
        - configuration: $BITRISE_SCHEME_DELIVERY Debug
        - scheme: $BITRISE_SCHEME_DELIVERY
    - fastlane@2:
        title: AppCenter iOS Deploy
        description: Deploy the iOS build to AppCenter
        inputs:
        - update_fastlane: "false"
        - verbose_log: "yes"
        - lane: upload_appcenter app_name:$APPCENTER_APP_NAME_IOS file:$BITRISE_IPA_PATH dsym:$BITRISE_DSYM_PATH platform:ios
    - git::https://github.com/Waracle/bitbucket-pr-comment-bitrise-step.git@0.1.2:
        title: Add iOS AppCenter comment to PR
        is_skippable: true
        inputs:
        - bitbucket_url: $BITBUCKET_URL
        - bitbucket_user: $BITBUCKET_PR_USER
        - bitbucket_password: $BITBUCKET_PR_PASSWORD
        - bitbucket_pr_comment: |-
            The iOS build from [build $BITRISE_BUILD_NUMBER]($BITRISE_BUILD_URL) of this pull request is now available on App Center.

            The build can be installed from [here]($APPCENTER_DEPLOY_DOWNLOAD_URL)
  _store:
    steps:
    - generate-cordova-build-configuration@0:
        inputs:
        - code_sign_identity: 'iPhone Developer: Bitrise CI (RXNS25CZ82)'
        - package_type: enterprise
        - development_team: $GIT_REPOSITORY_URL
    - script@1:
        title: Build Android STORE
        inputs:
        - content: |-
            #!/usr/bin/env bash

            # fail if any commands fails
            set -e

            ionic capacitor build android
    - script@1:
        title: Build iOS STORE
        inputs:
        - content: |-
            #!/usr/bin/env bash

            # fail if any commands fails
            set -e

            ionic capacitor build ios
    - fastlane:
        inputs:
        - update_fastlane: "false"
        - lane: upload_testflight app_identifier:com.apex-rides.mobile.store ipa:$BITRISE_IPA_PATH team_id:$PILOT_TEAM_ID_CLIENT
  dev:
    before_run:
    - _pre-work
    - _dev
    after_run:
    - _post-workflow
  download_profiles:
    steps:
    - script@1:
        title: Print Signing Environment Variables
        inputs:
        - content: |-
            #!/usr/bin/env bash

            # fail if any commands fails
            set -e

            env | sort
    - activate-ssh-key@4:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@6:
        run_if: '{{(getenv "GIT_CLONE_COMMIT_HASH" | eq "") | and .IsCI }}'
    - fastlane:
        title: Download Profiles (Waracle - Enterprise)
        run_if: '{{getenv "FASTLANE_TEAM_ID_WARACLE" | ne ""}}'
        inputs:
        - update_fastlane: "false"
        - lane: download_profiles app_identifier:$MATCH_APP_IDENTIFIER_WARACLE team_id:$FASTLANE_TEAM_ID_WARACLE git_branch:$MATCH_GIT_BRANCH_WARACLE type:enterprise
    - fastlane:
        title: Download Profiles (Client Development)
        run_if: '{{getenv "FASTLANE_TEAM_ID_CLIENT" | ne ""}}'
        inputs:
        - update_fastlane: "false"
        - lane: download_profiles app_identifier:$MATCH_APP_IDENTIFIER_CLIENT git_branch:$MATCH_GIT_BRANCH_CLIENT team_id:$FASTLANE_TEAM_ID_CLIENT type:development
    - fastlane:
        title: Download Profiles (Client Distribution)
        run_if: '{{getenv "FASTLANE_TEAM_ID_CLIENT" | ne ""}}'
        inputs:
        - update_fastlane: "false"
        - lane: download_profiles app_identifier:$MATCH_APP_IDENTIFIER_CLIENT git_branch:$MATCH_GIT_BRANCH_CLIENT team_id:$FASTLANE_TEAM_ID_CLIENT type:appstore
    - script@1:
        title: Print Signing Environment Variables
        inputs:
        - content: |-
            #!/usr/bin/env bash

            # fail if any commands fails
            set -e

            env | grep sigh | sort
  external_qa:
    before_run:
    - _pre-work
    - _staging
    - _prod
    after_run:
    - _post-workflow
  internal_qa:
    before_run:
    - _pre-work
    - _dev
    after_run:
    - _post-workflow
  pull_request:
    before_run:
    - _pre-work
    - _dev
    after_run:
    - _post-workflow
  release:
    before_run:
    - _pre-work
    - _store
    after_run:
    - _post-workflow
  S2DeliveryWorkflow:
    before_run:
    - _S2limited-pre-work
    - _S2delivery
    after_run:
    - _S2_post-workflow
  S2devWorkflow:
    before_run:
    - _S2limited-pre-work
    - _S2dev
    after_run:
    - _S2_post-workflow
  S2JLLProductionWorkflow:
    before_run:
    - _S2-pre-work
    - _S2JLLproduction
    after_run:
    - _S2_post-workflow
  S2ProductionWorkflow:
    before_run:
    - _S2limited-pre-work
    - _S2production
    after_run:
    - _S2_post-workflow
meta:
  bitrise.io:
    stack: osx-xcode-15.2.x
    machine_type_id: g2-m1.4core
