Skip to content

Commit

Permalink
Update workflows and fastlane to include basic ios build
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewc committed Sep 11, 2023
1 parent 2bedd10 commit 3ef7b2f
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 26 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/android-preview.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
144 changes: 119 additions & 25 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

0 comments on commit 3ef7b2f

Please sign in to comment.