invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.6k stars 2.19k forks source link

CI build hangs on Running script '[CP-User] [RNFB] Core Configuration' #3706

Closed martinalderson closed 4 years ago

martinalderson commented 4 years ago

Issue

On CI (bitrise) our iOS build is hanging 50% of the time on the ▸ Running script '[CP-User] [RNFB] Core Configuration' step. Android works fine. Rerunning the build also seems to fix it as it only happens 50% of the time.


Project Files

Javascript

Click To Expand

#### `package.json`: ```json # N/A ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` OUTPUT GOES HERE ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `e.g. 5.4.3` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`


mikehardy commented 4 years ago

What's in the script at that line?

My experience with bitrise builds is that they have had lots of problems in the past, and all seemed like phantoms from the modules perspective, i.e., all strange bitrise platform issues :shrug: https://github.com/invertase/react-native-firebase/issues?q=is%3Aissue++bitrise

The only reproducible success has come from the submitter doggedly pursuing the thing, module maintainers (like me) here have had no effect unfortunately

martinalderson commented 4 years ago
#!/usr/bin/env bash
#
# Copyright (c) 2016-present Invertase Limited & Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this library except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -e
_MAX_LOOKUPS=2;
_SEARCH_RESULT=''
_RN_ROOT_EXISTS=''
_CURRENT_LOOKUPS=1
_JSON_ROOT="'react-native'"
_JSON_FILE_NAME='firebase.json'
_JSON_OUTPUT_BASE64='e30=' # { }
_CURRENT_SEARCH_DIR=${PROJECT_DIR}
_PLIST_BUDDY=/usr/libexec/PlistBuddy
_TARGET_PLIST="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
_DSYM_PLIST="${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist"
# plist arrays
_PLIST_ENTRY_KEYS=()
_PLIST_ENTRY_TYPES=()
_PLIST_ENTRY_VALUES=()
function setPlistValue {
  echo "info:      setting plist entry '$1' of type '$2' in file '$4'"
  ${_PLIST_BUDDY} -c "Add :$1 $2 '$3'" $4 || echo "info:      '$1' already exists"
}
function getFirebaseJsonKeyValue () {
  if [[ ${_RN_ROOT_EXISTS} ]]; then
    ruby -e "require 'rubygems';require 'json'; output=JSON.parse('$1'); puts output[$_JSON_ROOT]['$2']"
  else
    echo ""
  fi;
}
function jsonBoolToYesNo () {
  if [[ $1 == "false" ]]; then
    echo "NO"
  elif [[ $1 == "true" ]]; then
    echo "YES"
  else echo "NO"
  fi
}
echo "info: -> RNFB build script started"
echo "info: 1) Locating ${_JSON_FILE_NAME} file:"
if [[ -z ${_CURRENT_SEARCH_DIR} ]]; then
  _CURRENT_SEARCH_DIR=$(pwd)
fi;
while true; do
  _CURRENT_SEARCH_DIR=$(dirname "$_CURRENT_SEARCH_DIR")
  if [[ "$_CURRENT_SEARCH_DIR" == "/" ]] || [[ ${_CURRENT_LOOKUPS} -gt ${_MAX_LOOKUPS} ]]; then break; fi;
  echo "info:      ($_CURRENT_LOOKUPS of $_MAX_LOOKUPS) Searching in '$_CURRENT_SEARCH_DIR' for a ${_JSON_FILE_NAME} file."
  _SEARCH_RESULT=$(find "$_CURRENT_SEARCH_DIR" -maxdepth 2 -name ${_JSON_FILE_NAME} -print | head -n 1)
  if [[ ${_SEARCH_RESULT} ]]; then
    echo "info:      ${_JSON_FILE_NAME} found at $_SEARCH_RESULT"
    break;
  fi;
  _CURRENT_LOOKUPS=$((_CURRENT_LOOKUPS+1))
done
if [[ ${_SEARCH_RESULT} ]]; then
  _JSON_OUTPUT_RAW=$(cat "${_SEARCH_RESULT}")
  _RN_ROOT_EXISTS=$(ruby -e "require 'rubygems';require 'json'; output=JSON.parse('$_JSON_OUTPUT_RAW'); puts output[$_JSON_ROOT]" || echo '')
  if [[ ${_RN_ROOT_EXISTS} ]]; then
    _JSON_OUTPUT_BASE64=$(python -c 'import json,sys,base64;print(base64.b64encode(json.dumps(json.loads(open('"'${_SEARCH_RESULT}'"').read())['${_JSON_ROOT}'])))' || echo "e30=")
  fi
  _PLIST_ENTRY_KEYS+=("firebase_json_raw")
  _PLIST_ENTRY_TYPES+=("string")
  _PLIST_ENTRY_VALUES+=("$_JSON_OUTPUT_BASE64")
  # config.messaging_auto_init_enabled
  _MESSAGING_AUTO_INIT=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "messaging_auto_init_enabled")
  if [[ $_MESSAGING_AUTO_INIT ]]; then
    _PLIST_ENTRY_KEYS+=("FirebaseMessagingAutoInitEnabled")
    _PLIST_ENTRY_TYPES+=("bool")
    _PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_MESSAGING_AUTO_INIT")")
  fi
  # config.crashlytics_disable_auto_disabler - undocumented for now - mainly for debugging, document if becomes usful
  _CRASHLYTICS_AUTO_DISABLE_ENABLED=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "crashlytics_disable_auto_disabler")
  if [[ $_CRASHLYTICS_AUTO_DISABLE_ENABLED == "true" ]]; then
    echo "Disabled Crashlytics auto disabler." # do nothing
  else
    _PLIST_ENTRY_KEYS+=("firebase_crashlytics_collection_enabled")
    _PLIST_ENTRY_TYPES+=("bool")
    _PLIST_ENTRY_VALUES+=("NO")
  fi
  # config.admob_delay_app_measurement_init
  _ADMOB_DELAY_APP_MEASUREMENT=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "admob_delay_app_measurement_init")
  if [[ $_ADMOB_DELAY_APP_MEASUREMENT == "true" ]]; then
    _PLIST_ENTRY_KEYS+=("GADDelayAppMeasurementInit")
    _PLIST_ENTRY_TYPES+=("bool")
    _PLIST_ENTRY_VALUES+=("YES")
  fi
  # config.admob_ios_app_id
  _ADMOB_IOS_APP_ID=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "admob_ios_app_id")
  if [[ $_ADMOB_IOS_APP_ID ]]; then
    _PLIST_ENTRY_KEYS+=("GADApplicationIdentifier")
    _PLIST_ENTRY_TYPES+=("string")
    _PLIST_ENTRY_VALUES+=("$_ADMOB_IOS_APP_ID")
  fi
else
  _PLIST_ENTRY_KEYS+=("firebase_json_raw")
  _PLIST_ENTRY_TYPES+=("string")
  _PLIST_ENTRY_VALUES+=("$_JSON_OUTPUT_BASE64")
  **echo "warning:   A firebase.json file was not found, whilst this file is optional it is recommended to include it to configure firebase services in React Native Firebase."**
fi;
echo "info: 2) Injecting Info.plist entries: "
# Log out the keys we're adding
for i in "${!_PLIST_ENTRY_KEYS[@]}"; do
  echo "    ->  $i) ${_PLIST_ENTRY_KEYS[$i]}" "${_PLIST_ENTRY_TYPES[$i]}" "${_PLIST_ENTRY_VALUES[$i]}"
done
for plist in "${_TARGET_PLIST}" "${_DSYM_PLIST}" ; do
  if [[ -f "${plist}" ]]; then
    # paths with spaces break the call to setPlistValue. temporarily modify
    # the shell internal field separator variable (IFS), which normally 
    # includes spaces, to consist only of line breaks
    oldifs=$IFS
    IFS="
"
    for i in "${!_PLIST_ENTRY_KEYS[@]}"; do
      setPlistValue "${_PLIST_ENTRY_KEYS[$i]}" "${_PLIST_ENTRY_TYPES[$i]}" "${_PLIST_ENTRY_VALUES[$i]}" "${plist}"
    done
    # restore the original internal field separator value
    IFS=$oldifs
  else
    echo "warning:   A Info.plist build output file was not found (${plist})"
  fi
done
echo "info: <- RNFB build script finished"`

I think it's this one? We don't have a firebase.json configured. If it runs sucessfully it gets to the bolded part, so it is hanging somewhere inbetween. Is there a way to skip this script if we don't use a firebase.json?

boennemann commented 4 years ago

We're experiencing the same issue from time to time.

I mean this script does have a while true in there 🤔 No idea though, why the max lookups thing wouldn't bail then.

mikehardy commented 4 years ago

@boennemann also it prints information every iteration there (all 2 of them!) so it seems it would be easy to localize? Does bitrise use some terrible version of bash?

vomchik commented 4 years ago

We have the same problem.

loopiezlol commented 4 years ago

Also experiencing this issue.

This was on GH actions, during a build_app Fastlane step. Essentially, the command ran was:

set -o pipefail && xcodebuild -workspace workspace.xcworkspace -scheme scheme -destination 'generic/platform=iOS' -archivePath /Users/runner/Library/Developer/Xcode/Archives/2020-07-06/app\ 2020-07-06\ 19.51.01.xcarchive archive | tee /Users/runner/Library/Logs/gym/app.log | xcpretty

Everything seemed to build fine and it suddenly hangs at:

[19:55:44]: ▸ Processing Info.plist
[19:55:44]: ▸ Running script 'Bundle React Native code and images'
[19:55:49]: ▸     the transform cache was reset.
[19:56:56]: ▸ Generating 'app.app.dSYM'
[19:56:56]: ▸ Running script '[CP-User] [RNFB] Core Configuration'
[19:56:58]: ▸ Running script '[CP] Copy Pods Resources'
[19:57:00]: ▸ Running script '[CP-User] [RNFB] Crashlytics Configuration'
loopiezlol commented 4 years ago

Actually, for me, it was that I wasn't running fastlane with setup_ci(force: true)

mikehardy commented 4 years ago

@Loopiezlol that tip might save lots of people time - we have a tips and tricks [edited: hit save too soon] page with an edit button - maybe a link to that fastlane docs page for CI users? with the error they would see

loopiezlol commented 4 years ago

@mikehardy good shout, aiming to do so in the next couple of days

vomchik commented 4 years ago

Actually, for me, it was that I wasn't running fastlane with setup_ci(force: true)

Doesn't work for me on bitrise :(

hamidhadi commented 4 years ago

Hey guys, Any update for this issue? We have the same issue on Bitrise and are not using Fastlane.

mikehardy commented 4 years ago

Unfortunately none of use these CI systems, we can only speak authoritatively and/or make fixes for the CI we use (github actions at this point). For all other CI systems, the community (you, us, we - not "them" or "someone") will have to experiment, try things etc and post PRs that work for you. We're happy to include things of course but can't come up with the fixes I don't think

loopiezlol commented 4 years ago

@hamidhadi

I never used bitrise, but maybe something in here could be of help? https://devcenter.bitrise.io/troubleshooting/frequent-ios-issues/#a-step-hangs

one of the points in there mention:

Your script tries to access an item in the OS X Keychain and the item is configured to ask for permission before access (this is the default type of Access Control configuration if you add an item - for example a password - to Keychain)

I reckon this might be related somehow. I'm saying this as, with Fastlane, the setup_ci instruction which fixed my issue is essentially documented as:

setup_ci Setup the keychain and match to work with CI Creates a new temporary keychain for use with match Switches match to readonly mode to not create new profiles/cert on CI Sets up log and test result paths to be easily collectible This action helps with CI integration. Add this to the top of your Fastfile if you use CI.

going down this rabbit hole, you can even check the exact implementation of that method: https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/setup_ci.rb#L26

keep in mind this is just a wild guess

mikehardy commented 4 years ago

yes in fact, I do fastlane builds on other macs in the house that I access by ssh sometimes, and this blocks my builds. I put this check in now as a fail fast early in my build:

before_all do
  # Make sure we have access to the keychain we use for certificates / codesign
  system "security show-keychain-info login.keychain > /dev/null 2>&1"
  UI.user_error! "login.keychain is locked, codesign will fail unless you run 'security unlock-keychain login.keychain'" unless $?.exits
tatus == 0
end
vomchik commented 4 years ago

BTW, looks like that script freezing if can't find a file firebase.json. I have added this file and now all works fine on Bitrise 🤷‍♂️

hamidhadi commented 4 years ago

@vomchik The problem is it sometimes freezing sometimes not. 🤔 Where did you add the firebase.json file? From my understanding, it should be created by the script right?

vomchik commented 4 years ago

@hamidhadi in the root of a project. No, the script analyzes the file and apply the configuration to Info.plist

Example: firebase.json

{
  "react-native": {
    "crashlytics_auto_collection_enabled": false,
    "perf_auto_collection_enabled": false,
    "analytics_auto_collection_enabled": false
  }
}
mikehardy commented 4 years ago

Anything that could help others would be a great addition here: https://rnfirebase.io/faqs-and-tips - edit button top right 🙏

Javi commented 4 years ago

Just chiming in to say that creating an empty firebase.json file on the root of the project unlocked my Bitrise build. Didn't want to change any values so I just left it empty like this.

{
  "react-native": {
  }
}
StijnCoolen commented 3 years ago

I'm experiencing the same on Github Actions. Adding firebase.json does not help.

mikehardy commented 3 years ago

@StijnCoolen unsure what might be the problem but this module's test app that runs our E2E CI tests is all in GitHub actions now, so we provide an example of how it might work if you browse through this repo

StijnCoolen commented 3 years ago

@mikehardy I will check it out, anything about keychain that should be added in particular? I tried your keychain before_alllane above.

mikehardy commented 3 years ago

I don't believe so - the keychain stuff for me is because I use fastlane to push builds to TestFlight, and fastlane stores Xcode cert info and passwords in the keychain so it needs access. If I do them headless (via ssh to one of the laptops I use to build some time, instead of logging in to macOS UI from the machine itself) the keychain is locked, and it may produce a hang but it's an obvious 🤦 type error you see in the build log in my experience

thanhdevapp commented 2 years ago

How to fix run DSYM Stuck:

Open XCODE - Build Phases -> DSYM section -> Check Run script: For Install builds only

aprilmintacpineda commented 1 year ago

I'm experiencing this today, the build was successful 18 days ago, the difference then and now is the xcode version, the github actions is now using xcode 14.0.1, back then it was using 13.4.1.

mikehardy commented 1 year ago

Strange, been working fine for me: https://github.com/invertase/react-native-firebase/actions/runs/3164853338/jobs/5153445701#step:5:9

aprilmintacpineda commented 1 year ago

I'm experiencing this today, the build was successful 18 days ago, the difference then and now is the xcode version, the github actions is now using xcode 14.0.1, back then it was using 13.4.1.

I tried archiving it on my mac and it failed but it has a different error (on github actions there's actually no error message, it just stops and hangs on the warning messages that says n will run every build)

ios/Pods/Pods.xcodeproj error project: Signing for "EXConstants-EXConstants" requires a development team. Select a development team in the Signing & Capabilities editor.

and there's one similar error but with a different package.

The error lead me to this https://github.com/facebook/react-native/issues/34673 and found this https://github.com/facebook/react-native/issues/34673#issuecomment-1245445193 which lead me to the solution that seems to have fixed the problem. Gonna come back to this after the build on GA completes.

EDIT 1: I got past the point when the error happens. So I think it's safe to say that it fixed it. EDIT 2: Build finish, deployment successful. Fix confirmed.

bang9 commented 1 year ago

@otterji It might be the same case as ours 🤔 https://rnfirebase.io/faqs-and-tips#my-ci-build-hangs-at-the-running-script-cp-user-core-configuration-step