From 3ef7b2f971325f5ffa2f2bb43a8272b940bd8399 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Mon, 11 Sep 2023 17:02:06 +0100 Subject: [PATCH] Update workflows and fastlane to include basic ios build --- .github/workflows/android-preview.yml | 34 +++++ .../{preview.yml => ios-preview.yml} | 2 +- fastlane/Fastfile | 144 +++++++++++++++--- 3 files changed, 154 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/android-preview.yml rename .github/workflows/{preview.yml => ios-preview.yml} (93%) diff --git a/.github/workflows/android-preview.yml b/.github/workflows/android-preview.yml new file mode 100644 index 000000000..dec03e4e7 --- /dev/null +++ b/.github/workflows/android-preview.yml @@ -0,0 +1,34 @@ +name: Preview + +on: pull_request + +jobs: + distribute: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "2.6" + bundler-cache: true + + - uses: actions/setup-ruby@v1 + with: + ruby-version: '2.6' + + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Install packages + run: | + yarn + + - name: Preview app on Appetize 🚀 + run: bundle exec fastlane android preview + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + SOURCE_BRANCH: ${{ github.head_ref }} + APPETIZE_API_TOKEN: ${{ secrets.APPETIZE_API_TOKEN }} diff --git a/.github/workflows/preview.yml b/.github/workflows/ios-preview.yml similarity index 93% rename from .github/workflows/preview.yml rename to .github/workflows/ios-preview.yml index 16b505c72..9e8b64a5e 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/ios-preview.yml @@ -27,7 +27,7 @@ jobs: yarn - name: Preview app on Appetize 🚀 - run: bundle exec fastlane preview + run: bundle exec fastlane ios preview env: PR_NUMBER: ${{ github.event.pull_request.number }} SOURCE_BRANCH: ${{ github.head_ref }} diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 32903c0ce..42c8991b0 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -2,70 +2,76 @@ require 'net/http' default_platform(:android) -platform :android do +# Github +github_run_id = ENV["GITHUB_RUN_ID"] +github_run_number = ENV["GITHUB_RUN_NUMBER"] +pr_number = ENV['PR_NUMBER'] + +# Xcode +app_workspace = "example/ios/example_0_70_6.xcworkspace" +app_xcode_proj = "example/ios/example_0_70_6.xcodeproj" +app_scheme = "example_0_70_6" +app_output_path = "/var/tmp/Primer.io_ReactNativeExample.xcarchive/Products/Applications/example_0_70_6.app" +app_output_archive_path = "/var/tmp/Primer.io_ReactNativeExample.xcarchive" +platform :android do + def set_version_name (version_name) path = '../example/android/app/build.gradle' re = /versionName\s+\"(\S+)\"/ - + s = File.read(path) s[re, 1] = version_name - + f = File.new(path, 'w') f.write(s) f.close end - + def set_version_code (version_code) path = '../example/android/app/build.gradle' re = /versionCode\s+(\d+)/ - + s = File.read(path) s[re, 1] = version_code.to_s - + f = File.new(path, 'w') f.write(s) f.close end - + def get_sdk_version_name () path = '../example/android/app/gradle.properties' re = /VERSION\_NAME=(\S+)/ - + s = File.read(path) return s[re, 1] end - - lane :preview do - pr_number = ENV["PR_NUMBER"] - if(!pr_number) then - puts "NO PR NUMBER" - next - end - + + lane :≈ do appetize_api_token = ENV['APPETIZE_API_TOKEN'] - + puts "PR_NUMBER: " + pr_number version_name = "preview-" + pr_number - + time = Time.new str_time = time.strftime("%Y-%m-%d %H:%M:%S") - + # Set timestamp as version_code to differentiate builds in firebase version_code = time.to_i - + set_version_name version_name set_version_code version_code - + gradle(task: "clean assembleRelease", project_dir: 'example/android/') - + sdk_version_name_source_branch = ENV['SOURCE_BRANCH'] pr_number = ENV['PR_NUMBER'] - + uri = URI('https://livedemostore.common.primer.io/appetize/android/' + version_name) public_key = Net::HTTP.get(uri) # => String puts "public_key: " + public_key - + appetize( path: "./example/android/app/build/outputs/apk/release/app-release.apk", platform: "android", @@ -74,5 +80,93 @@ platform :android do note: version_name ) end - + end + +platform :ios do + desc 'This action builds the app and uplads it to Appetize' + lane :preview do + + common_pre_build_action + + # Build for appetize + + build_app( + scheme: app_scheme, + sdk: "iphonesimulator", # Appetize needs a simulator app + workspace: app_workspace, + configuration: "Debug", + destination: "generic/platform=iOS Simulator", + xcargs: "EXCLUDED_ARCHS[sdk=iphonesimulator*]=arm64", + include_bitcode: false, + export_method: "development", + archive_path: app_output_archive_path, + # Build speed optimisation + skip_package_ipa: true, + skip_package_pkg: true, + skip_package_dependencies_resolution: true, + silent: true + ) + + # # Appetize needs the .app to be zipped + + zip_path = "./PrimerSDK_Debug_Build.zip" + + zip( + path: app_output_path, + output_path: zip_path, + symlinks: true + ) + + # Find public key of appetize + uri = URI('https://livedemostore.shared.primer.io/appetize/ios_rn/preview_' + "#{pr_number}_#{github_run_id}_#{github_run_number}") + public_key = Net::HTTP.get(uri) + puts "public_key: " + public_key + + # Upload to Appetize + appetize( + path: zip_path, + platform: "ios", + api_token: appetize_api_token, + public_key: public_key, + note: sdk_version_name_source_branch + ) + + save_simulator_app(app_path: zip_path) + update_deployment_url(lane_context[SharedValues::APPETIZE_APP_URL]) + + end + + desc 'Common build pre-action' + private_lane :common_pre_build_action do + + set_version_and_build_number + + setup_signing( + match_type: "development" + ) + + end + + desc 'This action sets the version and build number' + private_lane :set_version_and_build_number do + + # We don't really need the version number + # at this moment. + # The Build number is the unique identifier of the package + # matching the Github Workflow run ID and number + + # Set version number + # increment_version_number( + # version_number: sdk_version_name_source_branch, + # xcodeproj: app_xcode_proj + # ) + + # Set build number + increment_build_number( + build_number: "#{github_run_id}.#{github_run_number}", + xcodeproj: app_xcode_proj + ) + + end +end \ No newline at end of file