From 89c178470abf8c1f9f9f2cc90764fbf1f23ead51 Mon Sep 17 00:00:00 2001
From: Rodrigo Nascimento <rodrigoknascimento@gmail.com>
Date: Wed, 10 Jan 2018 00:35:31 -0200
Subject: [PATCH] Fix build of PRs from forks (#184)

---
 .circleci/config.yml    | 30 +++++++++++++++++++++++-------
 ios/fastlane/Fastfile   | 30 +++++++++++++++++-------------
 ios/fastlane/README.md  |  4 ++--
 ios/fastlane/report.xml | 10 +++++-----
 4 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index 50a78a96a..d718b52fc 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -72,11 +72,16 @@ jobs:
           command: |
             cd android
 
-            echo $KEYSTORE_BASE64 | base64 --decode > ./app/$KEYSTORE
-            echo -e "KEYSTORE=$KEYSTORE" > ./gradle.properties
-            echo -e "KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD" >> ./gradle.properties
-            echo -e "KEY_ALIAS=$KEY_ALIAS" >> ./gradle.properties
-            echo -e "KEY_PASSWORD=$KEYSTORE_PASSWORD" >> ./gradle.properties
+            echo -e "" > ./gradle.properties
+
+            if [[ $KEYSTORE ]]; then
+              echo $KEYSTORE_BASE64 | base64 --decode > ./app/$KEYSTORE
+              echo -e "KEYSTORE=$KEYSTORE" >> ./gradle.properties
+              echo -e "KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD" >> ./gradle.properties
+              echo -e "KEY_ALIAS=$KEY_ALIAS" >> ./gradle.properties
+              echo -e "KEY_PASSWORD=$KEYSTORE_PASSWORD" >> ./gradle.properties
+            fi
+
             echo -e "VERSIONCODE=$CIRCLE_BUILD_NUM" >> ./gradle.properties
 
       - run:
@@ -89,7 +94,11 @@ jobs:
           name: Build Android App
           command: |
             cd android
-            ./gradlew assembleRelease
+            if [[ $KEYSTORE ]]; then
+              ./gradlew assembleRelease
+            else
+              ./gradlew assembleDebug
+            fi
 
             mkdir -p /tmp/build
 
@@ -155,7 +164,14 @@ jobs:
           command: |
             cd ios
             agvtool new-version -all $CIRCLE_BUILD_NUM
-            fastlane ios build
+
+            if [[ $MATCH_KEYCHAIN_NAME ]]; then
+              fastlane ios release
+            else
+              export MATCH_KEYCHAIN_NAME="temp"
+              export MATCH_KEYCHAIN_PASSWORD="temp"
+              fastlane ios build
+            fi
 
       - store_artifacts:
           path: ios/RocketChatRN.ipa
diff --git a/ios/fastlane/Fastfile b/ios/fastlane/Fastfile
index 780a629ae..b9513cd89 100644
--- a/ios/fastlane/Fastfile
+++ b/ios/fastlane/Fastfile
@@ -47,20 +47,8 @@ platform :ios do
     # You can also use other beta testing services here (run `fastlane actions`)
   end
 
-  desc "Deploy a new version to the App Store"
+  desc "Build App for release"
   lane :release do
-    # match(type: "appstore")
-    # snapshot
-    match(
-      type: "appstore",
-      git_url: "git@github.com:RocketChat/Rocket.Chat.ReactNative.FastLane.git"
-    ) # more information: https://codesigning.guide
-    deliver(force: true)
-    # frameit
-  end
-
-  desc "Build App"
-  lane :build do
     # match(type: "appstore")
     # snapshot
     match(
@@ -72,6 +60,22 @@ platform :ios do
     # frameit
   end
 
+  desc "Build App for development"
+  lane :build do |options|
+    xcodebuild(
+      project: "RocketChatRN.xcodeproj",
+      scheme: "RocketChatRN",
+      configuration: "Debug",
+      clean: options[:clean],
+      build: true,
+      destination: "generic/platform=iOS",
+      build_settings: {
+        "CODE_SIGNING_REQUIRED" => "NO",
+        "CODE_SIGN_IDENTITY" => ""
+      }
+    )
+  end
+
   # You can define as many lanes as you want
 
   after_all do |lane|
diff --git a/ios/fastlane/README.md b/ios/fastlane/README.md
index 25c79d48b..737b41e33 100644
--- a/ios/fastlane/README.md
+++ b/ios/fastlane/README.md
@@ -46,12 +46,12 @@ This will also make sure the profile is up to date
 ```
 fastlane ios release
 ```
-Deploy a new version to the App Store
+Build App for release
 ### ios build
 ```
 fastlane ios build
 ```
-Build App
+Build App for development
 
 ----
 
diff --git a/ios/fastlane/report.xml b/ios/fastlane/report.xml
index d3e0f05cb..a44d86446 100644
--- a/ios/fastlane/report.xml
+++ b/ios/fastlane/report.xml
@@ -5,27 +5,27 @@
     
     
       
-      <testcase classname="fastlane.lanes" name="0: Verifying required fastlane version" time="0.003408">
+      <testcase classname="fastlane.lanes" name="0: Verifying required fastlane version" time="0.002207">
         
       </testcase>
     
       
-      <testcase classname="fastlane.lanes" name="1: default_platform" time="0.003022">
+      <testcase classname="fastlane.lanes" name="1: default_platform" time="0.002098">
         
       </testcase>
     
       
-      <testcase classname="fastlane.lanes" name="2: match" time="12.238978">
+      <testcase classname="fastlane.lanes" name="2: create_keychain" time="0.106586">
         
       </testcase>
     
       
-      <testcase classname="fastlane.lanes" name="3: gym" time="237.52302">
+      <testcase classname="fastlane.lanes" name="3: xcodebuild" time="170.328674">
         
       </testcase>
     
       
-      <testcase classname="fastlane.lanes" name="4: pilot" time="72.313015">
+      <testcase classname="fastlane.lanes" name="4: delete_keychain" time="0.060332">
         
       </testcase>
     
-- 
GitLab