From 22ced9d3b28b7fee7101aab8974d446f4c2da681 Mon Sep 17 00:00:00 2001 From: Mason Le Date: Fri, 8 Sep 2023 14:41:15 +0700 Subject: [PATCH] feat(all): add guide for gitlab ci --- package.json | 2 +- template/GITLABRUNNER.MD | 321 ++++++++++++++++++ template/README.md | 2 + template/_gitignore | 3 +- template/android/app/build.gradle | 4 - template/build_script/build-android.ts | 25 ++ template/build_script/build-ios.ts | 18 + template/build_script/deploy-android.ts | 18 + template/build_script/deploy-ios.ts | 18 + template/env/.dev | 6 +- template/env/.prod | 6 +- template/fastlane/.env.dev | 8 +- template/fastlane/.env.prod | 8 +- template/fastlane/FastFile | 87 +++-- template/fastlane/Pluginfile | 1 - template/fastlane/api-key/apple/.gitkeep | 0 template/fastlane/api-key/apple/demo.p8 | 3 - template/fastlane/api-key/google/.gitkeep | 0 template/fastlane/api-key/google/demo.json | 12 - .../release-keystore/my-upload-key.keystore | Bin template/ios/.xcode.env.local | 1 - template/ios/Podfile | 9 +- template/package.json | 5 +- template/scripts/android.ts | 2 +- template/scripts/fastlane.ts | 33 -- template/scripts/setup.ts | 2 +- 26 files changed, 491 insertions(+), 103 deletions(-) create mode 100644 template/GITLABRUNNER.MD create mode 100644 template/build_script/build-android.ts create mode 100644 template/build_script/build-ios.ts create mode 100644 template/build_script/deploy-android.ts create mode 100644 template/build_script/deploy-ios.ts create mode 100644 template/fastlane/api-key/apple/.gitkeep delete mode 100644 template/fastlane/api-key/apple/demo.p8 create mode 100644 template/fastlane/api-key/google/.gitkeep delete mode 100644 template/fastlane/api-key/google/demo.json rename template/{android/app => fastlane}/release-keystore/my-upload-key.keystore (100%) delete mode 100644 template/ios/.xcode.env.local delete mode 100644 template/scripts/fastlane.ts diff --git a/package.json b/package.json index 30e3c55f..cf590056 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rn-boiler-template", "private": false, - "version": "1.72.4", + "version": "1.72.6", "description": "Clean and minimalist React Native template for a quick start with TypeScript and components", "scripts": { "test": "exit 0" diff --git a/template/GITLABRUNNER.MD b/template/GITLABRUNNER.MD new file mode 100644 index 00000000..9e561186 --- /dev/null +++ b/template/GITLABRUNNER.MD @@ -0,0 +1,321 @@ + +You can config gitlab CI runner to create build automatically. + +## Config workflow + +- Create new repo for gitlab CI +- Create Runner for gitlab CI +- Move fastlane, build_script folder to new repo +- Add new files [README.MD](#readmemd), [.gitlab-ci.yml](#gitlab-ciyml), [pull_repo.sh](#pull_reposh), [release.sh](#releasesh) and [build_script](#build_script) folder to new repo + +### README.MD + +```md +## Requiement + +- [rbenv](https://github.com/rbenv/rbenv) +- [fnm](https://github.com/Schniz/fnm) +- [fastlane](https://fastlane.tools/) +- [Gitlab-Runner](https://docs.gitlab.com/runner/) for macos. executor should be shell + +## Run Pipeline + + - Step 1: Create new pipeline on gitlab + - Step 2: Add 2 variable: + - BRANCH_NAME: branch of repo want to build. ex: develop, main, ... + - BASE_ENV_ARGS: env want to build. String with "," separator. This will use for fastlane. ex: dev,prod + +``` + +### .gitlab-ci.yml + +```yml +workflow: +stages: [clone, setup-env, install, android, ios, release, cleanup] + +default: + tags: + - macos_shared + +variables: + GIT_CLEAN_FLAGS: "none" + # BRANCH_NAME: "develop" + FASTLANE_SCRIPT_ANDROID: "bundle exec fastlane android" + FASTLANE_SCRIPT_IOS: "bundle exec fastlane ios" + # BASE_ENV_ARGS: "dev" + EXPORT_DIR_ARGS_NAME: "export_dir" + EXPORT_FOLDER: "export/$BRANCH_NAME" + +clone-code-project: + stage: clone + before_script: + - echo "Cloning code ..." + - chmod 777 pull_repo.sh + script: + - ./pull_repo.sh $REPO_SOURCE $BRANCH_NAME + when: manual + +setup-node: + stage: setup-env + before_script: + - echo "Setting up node version ..." + script: + - if [[ $(fnm list | grep v$$(NAME_ARG)) == "" ]]; then (echo "Install node version $NODE_VERSION via fnm" && fnm install $NODE_VERSION) fi + - fnm use $NODE_VERSION + - npm install -g yarn + needs: + - job: clone-code-project + +setup-ruby: + stage: setup-env + before_script: + - echo "Setting up ruby version ..." + script: + - if [[ $(ruby-build --definitions | grep $RUBY_VERSION) == "" ]]; then (echo "Install ruby version $RUBY_VERSION via rbenv" && rbenv install $RUBY_VERSION ) fi + - cd repo/$BRANCH_NAME + - rbenv local $RUBY_VERSION + needs: + - job: setup-node + +install-dependencies: + stage: install + before_script: + - cd repo/$BRANCH_NAME + - fnm use $NODE_VERSION + script: + - echo "Installing dependencies ..." + - yarn install + - bundle update fastlane + needs: + - job: setup-ruby + +build-android: + stage: android + before_script: + - echo "Building android app ..." + - cd repo/$BRANCH_NAME + - fnm use $NODE_VERSION + script: + - echo "sdk.dir=$ANDROID_HOME" > android/local.properties + - npx ts-node build_script/build-android.ts $BASE_ENV_ARGS $EXPORT_FOLDER + needs: + - job: install-dependencies + allow_failure: true + +deploy-android: + stage: android + before_script: + - echo "Deploy android app ..." + - cd repo/$BRANCH_NAME + script: + - npx ts-node build_script/deploy-android.ts $BASE_ENV_ARGS $EXPORT_FOLDER + needs: + - job: build-android + allow_failure: true + +build-ios: + stage: ios + before_script: + - echo "Building ios app ..." + - cd repo/$BRANCH_NAME + - fnm use $NODE_VERSION + script: + - npx ts-node build_script/build-ios.ts $BASE_ENV_ARGS $EXPORT_FOLDER + needs: + - job: install-dependencies + allow_failure: true + +deploy-ios: + stage: ios + before_script: + - echo "Deploy ios app ..." + - cd repo/$BRANCH_NAME + script: + - npx ts-node build_script/deploy-ios.ts $BASE_ENV_ARGS $EXPORT_FOLDER + needs: + - job: build-ios + allow_failure: true + +release: + stage: release + before_script: + - chmod 777 release.sh + - echo "Release ..." + script: + - ./release.sh repo/$BRANCH_NAME/fastlane/export $CI_JOB_TOKEN $CI_API_V4_URL $CI_PROJECT_ID $BRANCH_NAME + needs: [build-android, build-ios] + allow_failure: true + +clean-up: + stage: cleanup + before_script: + - echo "Cleaning up ..." + - cd repo + script: + - rm -rf $BRANCH_NAME + needs: [release, deploy-ios, deploy-android] + +``` + +### pull_repo.sh + +```sh +repo=$1 +branch=$2 +chmod 777 repo +rm -rf repo/$branch +mkdir -p repo/$branch +cd repo/$branch +rm -rf fastlane +git clone $1 -b $branch . +# copy fastlane and build_script to $branch folder +cp -r ../../fastlane . +cp -r ../../build_script . + +``` + +### release.sh + +```sh +export_dir=$1 +CI_JOB_TOKEN=$2 +CI_API_V4_URL=$3 +CI_PROJECT_ID=$4 +BRANCH_NAME=$5 +files_dir=$(find "$export_dir" -type f \( -name "*.apk" -o -name "*.aab" -o -name "*.ipa" -o -name "*.dSYM.zip" \)) +cd repo/$BRANCH_NAME +last_commit=$(git rev-parse --short HEAD) +cd ../.. +for eachfile in $files_dir +do + echo $eachfile + filename=$(basename "$eachfile") + if [[ $filename =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then + version="${BASH_REMATCH[1]}" + else + version="0.0.0" + fi + + curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file $eachfile "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$BRANCH_NAME-$last_commit/$version/$filename" +done + +``` + +### build_script + +#### build-android.ts + +```ts +import { execSync } from 'child_process'; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(',').forEach(envArg => { + console.log(`Building android for ${envArg}`); + + execSync( + `bundle exec fastlane android aab_android --env ${envArg} export_dir:${export_dir}`, + { + stdio: 'inherit', + }, + ); + + execSync( + `bundle exec fastlane android apk_android --env ${envArg} export_dir:${export_dir}`, + { + stdio: 'inherit', + }, + ); + }); +})(); + +``` + +#### deploy-android.ts + +```ts +import { execSync } from 'child_process'; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(',').forEach(envArg => { + console.log(`Deploying android for ${envArg}`); + + execSync( + `bundle exec fastlane android google_internal --env ${envArg} export_dir:${export_dir}`, + { + stdio: 'inherit', + }, + ); + }); +})(); + +``` + +#### build-ios.ts + +```ts +import { execSync } from 'child_process'; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(',').forEach(envArg => { + console.log(`Building ios for ${envArg}`); + + execSync( + `bundle exec fastlane ios build_ipa --env ${envArg} export_dir:${export_dir}`, + { + stdio: 'inherit', + }, + ); + }); +})(); + +``` + +#### deploy-ios.ts + +```ts +import { execSync } from 'child_process'; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(',').forEach(envArg => { + console.log(`Deploying ios for ${envArg}`); + + execSync( + `bundle exec fastlane ios upload_to_TF --env ${envArg} export_dir:${export_dir}`, + { + stdio: 'inherit', + }, + ); + }); +})(); + +``` + +> Folder structure like: + + . + ├── fastlane + ├── build_script + │ ├── build-android.ts + │ ├── deploy-android.ts + │ ├── build-ios.ts + │ └── deploy-ios.ts + ├── .gitlab-ci.yml + ├── pull_repo.sh + ├── release.sh + └── README.md diff --git a/template/README.md b/template/README.md index d8ce389c..85c821b5 100644 --- a/template/README.md +++ b/template/README.md @@ -134,3 +134,5 @@ Ex: New Environment named: Demo ## Caution - With gooogle play, u must publish .aab first time manually. Then, u can upload aab via fastlane. [fastlane/fastlane#14686](https://github.com/fastlane/fastlane/issues/14686) + +## [Gitlab CI Runner config](./GITLABRUNNER.MD) diff --git a/template/_gitignore b/template/_gitignore index 02c6538e..8361a6ef 100644 --- a/template/_gitignore +++ b/template/_gitignore @@ -45,7 +45,8 @@ local.properties *.aab *.aar *.ap_ -release/ +android/**/*.keystore +!debug.keystore # Auto generate env diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index df879d45..98748091 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -113,10 +113,6 @@ android { keyPassword 'android' } release { - storeFile file("./release-keystore/${project.env.get("ANDROID_KEY_STORE_FILE")}") - storePassword project.env.get("ANDROID_KEY_STORE_PASSWORD") - keyAlias project.env.get("ANDROID_KEY_STORE_KEY_ALIAS") - keyPassword project.env.get("ANDROID_KEY_STORE_KEY_PASSWORD") } } buildTypes { diff --git a/template/build_script/build-android.ts b/template/build_script/build-android.ts new file mode 100644 index 00000000..f18b70a9 --- /dev/null +++ b/template/build_script/build-android.ts @@ -0,0 +1,25 @@ +import { execSync } from "child_process"; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(",").forEach((envArg) => { + console.log(`Building android for ${envArg}`); + + execSync( + `bundle exec fastlane android aab_android --env ${envArg} export_dir:${export_dir}`, + { + stdio: "inherit", + } + ); + + execSync( + `bundle exec fastlane android apk_android --env ${envArg} export_dir:${export_dir}`, + { + stdio: "inherit", + } + ); + }); +})(); diff --git a/template/build_script/build-ios.ts b/template/build_script/build-ios.ts new file mode 100644 index 00000000..936f8718 --- /dev/null +++ b/template/build_script/build-ios.ts @@ -0,0 +1,18 @@ +import { execSync } from "child_process"; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(",").forEach((envArg) => { + console.log(`Building ios for ${envArg}`); + + execSync( + `bundle exec fastlane ios build_ipa --env ${envArg} export_dir:${export_dir}`, + { + stdio: "inherit", + } + ); + }); +})(); diff --git a/template/build_script/deploy-android.ts b/template/build_script/deploy-android.ts new file mode 100644 index 00000000..bce92b85 --- /dev/null +++ b/template/build_script/deploy-android.ts @@ -0,0 +1,18 @@ +import { execSync } from "child_process"; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(",").forEach((envArg) => { + console.log(`Deploying android for ${envArg}`); + + execSync( + `bundle exec fastlane android google_internal --env ${envArg} export_dir:${export_dir}`, + { + stdio: "inherit", + } + ); + }); +})(); diff --git a/template/build_script/deploy-ios.ts b/template/build_script/deploy-ios.ts new file mode 100644 index 00000000..7876fcbc --- /dev/null +++ b/template/build_script/deploy-ios.ts @@ -0,0 +1,18 @@ +import { execSync } from "child_process"; + +(() => { + const [envArgs, export_dir] = process.argv.slice(2); + + console.log(`envArgs: ${envArgs}`); + + envArgs.split(",").forEach((envArg) => { + console.log(`Deploying ios for ${envArg}`); + + execSync( + `bundle exec fastlane ios upload_to_TF --env ${envArg} export_dir:${export_dir}`, + { + stdio: "inherit", + } + ); + }); +})(); diff --git a/template/env/.dev b/template/env/.dev index af6e2a18..0ba95d72 100644 --- a/template/env/.dev +++ b/template/env/.dev @@ -15,8 +15,4 @@ RELEASE_PROVISIONING_PROFILE="helloworld_dev_ad_hoc" PUBLISH_PROVISIONING_PROFILE="helloworld_dev_appstore" APPLE_DEVELOPMENT_TEAM="" # Android -FLAVOR="dev" -ANDROID_KEY_STORE_FILE="my-upload-key.keystore" -ANDROID_KEY_STORE_PASSWORD="111111" -ANDROID_KEY_STORE_KEY_ALIAS="my-key-alias" -ANDROID_KEY_STORE_KEY_PASSWORD="111111" \ No newline at end of file +FLAVOR="dev" \ No newline at end of file diff --git a/template/env/.prod b/template/env/.prod index 141d9d63..3cd32c1b 100644 --- a/template/env/.prod +++ b/template/env/.prod @@ -15,8 +15,4 @@ RELEASE_PROVISIONING_PROFILE="helloworld_ad_hoc" PUBLISH_PROVISIONING_PROFILE="helloworld_appstore" APPLE_DEVELOPMENT_TEAM="" # Android -FLAVOR="prod" -ANDROID_KEY_STORE_FILE="my-upload-key.keystore" -ANDROID_KEY_STORE_PASSWORD="111111" -ANDROID_KEY_STORE_KEY_ALIAS="my-key-alias" -ANDROID_KEY_STORE_KEY_PASSWORD="111111" \ No newline at end of file +FLAVOR="prod" \ No newline at end of file diff --git a/template/fastlane/.env.dev b/template/fastlane/.env.dev index 4db518dd..b1e2acf9 100644 --- a/template/fastlane/.env.dev +++ b/template/fastlane/.env.dev @@ -9,12 +9,16 @@ GOOGLE_CHAT_ANDROID_TITLE="HelloWorld Android Staging" GOOGLE_CHAT_TAG_USER=">" GOOGLE_CHAT_IOS_TITLE="HelloWorld IOS Staging" GOOGLE_CHAT_DESCRIPTION="Build for" -APPSTORE_CONNECT_KEY_PATH="fastlane/api-key/apple/demo.p8" +APPSTORE_CONNECT_KEY_PATH="" APPSTORE_CONNECT_KEY_ID="" APPSTORE_CONNECT_ISSUER_ID="" -GOOGLE_API_KEY_PATH="fastlane/api-key/google/demo.json" +GOOGLE_API_KEY_PATH="" FASTLANE_USER="Your_apple_id" FASTLANE_PASSWORD="Your apple password" FASTLANE_ITC_TEAM_NAME="Your_Team_Name" FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD="Your_apple_application_specific_password" ENVFILE="env/.dev" +ANDROID_KEY_STORE_FILE="my-upload-key.keystore" +ANDROID_KEY_STORE_PASSWORD="111111" +ANDROID_KEY_STORE_KEY_ALIAS="my-key-alias" +ANDROID_KEY_STORE_KEY_PASSWORD="111111" \ No newline at end of file diff --git a/template/fastlane/.env.prod b/template/fastlane/.env.prod index eeb7b4fd..137de063 100644 --- a/template/fastlane/.env.prod +++ b/template/fastlane/.env.prod @@ -9,12 +9,16 @@ GOOGLE_CHAT_ANDROID_TITLE="HelloWorld Android" GOOGLE_CHAT_TAG_USER=">" GOOGLE_CHAT_IOS_TITLE="HelloWorld IOS" GOOGLE_CHAT_DESCRIPTION="Build for" -APPSTORE_CONNECT_KEY_PATH="fastlane/api-key/apple/demo.p8" +APPSTORE_CONNECT_KEY_PATH="" APPSTORE_CONNECT_KEY_ID="" APPSTORE_CONNECT_ISSUER_ID="" -GOOGLE_API_KEY_PATH="fastlane/api-key/google/demo.json" +GOOGLE_API_KEY_PATH="" FASTLANE_USER="Your_apple_id" FASTLANE_PASSWORD="Your apple password" FASTLANE_ITC_TEAM_NAME="Your_Team_Name" FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD="Your_apple_application_specific_password" ENVFILE="env/.prod" +ANDROID_KEY_STORE_FILE="my-upload-key.keystore" +ANDROID_KEY_STORE_PASSWORD="111111" +ANDROID_KEY_STORE_KEY_ALIAS="my-key-alias" +ANDROID_KEY_STORE_KEY_PASSWORD="111111" \ No newline at end of file diff --git a/template/fastlane/FastFile b/template/fastlane/FastFile index 952b55d5..7f521590 100644 --- a/template/fastlane/FastFile +++ b/template/fastlane/FastFile @@ -7,11 +7,13 @@ before_all do |lane| unless environment.nil? puts "Load .env file of #{environment}" Dotenv.overload "../" + ENV['ENVFILE'] - + ANDROID_PROJECT_DIR = "android/" ANDROID_VARIANT = "#{ENV['FLAVOR']}" + ANDROID_KEY_STORE_PATH = "/#{ANDROID_PROJECT_DIR}app/" +ENV["ANDROID_KEY_STORE_FILE"] + ANDROID_APK_OUTPUT_DIR = "#{ANDROID_PROJECT_DIR}app/build/outputs/apk/#{ANDROID_VARIANT}/release" ANDROID_AAB_OUTPUT_DIR = "#{ANDROID_PROJECT_DIR}app/build/outputs/bundle/#{ANDROID_VARIANT}Release" @@ -34,49 +36,40 @@ end platform :ios do desc "Upload IPA to TestFlight" - private_lane :ios_upload_to_TF do + lane :upload_to_TF do |params| + ipa_path = "./fastlane/#{params[:export_dir]}" + "/#{BUILD_IOS_FILENAME}.ipa" if ENV['FASTLANE_USER'] upload_to_testflight({ + apple_id: ENV['APPLE_ID'], + ipa: ipa_path, app_identifier: ENV['BUNDLE_IDENTIFIER'], - username: ENV['FASTLANE_USER'] + skip_waiting_for_build_processing: true, }) else api_key = app_store_connect_api_key( key_id: ENV["APPSTORE_CONNECT_KEY_ID"], issuer_id: ENV["APPSTORE_CONNECT_ISSUER_ID"], key_filepath: ENV["APPSTORE_CONNECT_KEY_PATH"], - duration: 1200, + duration: 1200, in_house: false ) upload_to_testflight({ api_key: api_key, - ipa: "#{BUILD_IOS_FILENAME}.ipa", + ipa: ipa_path, skip_submission: true, app_identifier: ENV['BUNDLE_IDENTIFIER'] }) end end - desc "IOS build IPA then upload to TestFlight" - lane :test_flight_build do |params| - ios_build_ipa - ios_upload_to_TF - clean_cache - end - - desc "iOS remove build output file" - private_lane :clean_cache do - File.delete("../#{BUILD_IOS_FILENAME}.ipa") if File.exist?("../#{BUILD_IOS_FILENAME}.ipa") - File.delete("../#{BUILD_IOS_FILENAME}.app.dSYM.zip") if File.exist?("../#{BUILD_IOS_FILENAME}.app.dSYM.zip") - end - desc "IOS ipa" - private_lane :ios_build_ipa do + lane :build_ipa do |params| build_app( workspace: "ios/#{ENV['WORKSPACE_NAME']}.xcworkspace", scheme: "#{ENV['WORKSPACE_NAME']}-#{ENV['SCHEME_SUFFIX']}", export_method: ENV['EXPORT_METHOD'], output_name: "#{BUILD_IOS_FILENAME}.ipa", + output_directory: "./fastlane/#{params[:export_dir]}", export_options: { provisioningProfiles: { "#{ENV['BUNDLE_IDENTIFIER']}" => "#{ENV['PUBLISH_PROVISIONING_PROFILE']}" @@ -92,28 +85,68 @@ platform :android do gradle(task: 'clean', project_dir: "#{ANDROID_PROJECT_DIR}", properties:{"defaultEnvFile" => ENV['ENVFILE']}) end + desc "Copy keystore file to android project" + private_lane :copy_keystore do + FileUtils.cp_r("./release-keystore/#{ENV['ANDROID_KEY_STORE_FILE']}", "../#{ANDROID_PROJECT_DIR}app/#{ENV['ANDROID_KEY_STORE_FILE']}") + end + desc "Android build bundle(aab)" - private_lane :aab_android do - gradle(task: "bundle", build_type: "Release",flavor: "#{ANDROID_VARIANT}", project_dir: "#{ANDROID_PROJECT_DIR}" ) - File.rename(ANDROID_AAB_BUILD_PATH_DEFAULT, "../#{ANDROID_AAB_BUILD_PATH_UPLOAD}") + lane :aab_android do |params| + copy_keystore + gradle( + task: "bundle", + build_type: "Release", + flavor: "#{ANDROID_VARIANT}", + project_dir: "#{ANDROID_PROJECT_DIR}", + properties: { + "android.injected.signing.store.file" => ENV['PWD'] + ANDROID_KEY_STORE_PATH, + "android.injected.signing.store.password" => ENV["ANDROID_KEY_STORE_PASSWORD"], + "android.injected.signing.key.alias" => ENV["ANDROID_KEY_STORE_KEY_ALIAS"], + "android.injected.signing.key.password" => ENV["ANDROID_KEY_STORE_KEY_PASSWORD"], + }) + File.rename(ANDROID_AAB_BUILD_PATH_DEFAULT, "../#{ANDROID_AAB_BUILD_PATH_UPLOAD}") + export_android(export_dir: params[:export_dir]) end desc "Android build release(apk)" - private_lane :apk_android do - gradle(task: "assemble", build_type: "Release",flavor: "#{ANDROID_VARIANT}", project_dir: "#{ANDROID_PROJECT_DIR}" ) - File.rename(ANDROID_APK_BUILD_PATH_DEFAULT, "../#{ANDROID_APK_BUILD_PATH_UPLOAD}") + lane :apk_android do |params| + copy_keystore + gradle( + task: "assemble", + build_type: "Release", + flavor: "#{ANDROID_VARIANT}", + project_dir: "#{ANDROID_PROJECT_DIR}", + properties: { + "android.injected.signing.store.file" => ENV['PWD'] + ANDROID_KEY_STORE_PATH, + "android.injected.signing.store.password" => ENV["ANDROID_KEY_STORE_PASSWORD"], + "android.injected.signing.key.alias" => ENV["ANDROID_KEY_STORE_KEY_ALIAS"], + "android.injected.signing.key.password" => ENV["ANDROID_KEY_STORE_KEY_PASSWORD"], + }) + File.rename(ANDROID_APK_BUILD_PATH_DEFAULT, "../#{ANDROID_APK_BUILD_PATH_UPLOAD}") + export_android(export_dir: params[:export_dir]) + end + + desc "Export aab/apk android to folder" + private_lane :export_android do |params| + ANDROID_EXPORT_DIR = params[:export_dir] + sh("mkdir -p #{ANDROID_EXPORT_DIR}") + if File.file?("../#{ANDROID_AAB_BUILD_PATH_UPLOAD}") + FileUtils.cp_r("../#{ANDROID_AAB_BUILD_PATH_UPLOAD}", "#{ANDROID_EXPORT_DIR}/#{ANDROID_BUILD_FILE_NAME}.aab") + end + if File.file?("../#{ANDROID_APK_BUILD_PATH_UPLOAD}") + FileUtils.cp_r("../#{ANDROID_APK_BUILD_PATH_UPLOAD}", "#{ANDROID_EXPORT_DIR}/#{ANDROID_BUILD_FILE_NAME}.apk") + end end desc "Android build apk then upload to app center" lane :google_internal do |params| - aab_android if File.file?("../#{ENV["GOOGLE_API_KEY_PATH"]}") upload_to_play_store( package_name: ENV['BUNDLE_IDENTIFIER'], track: 'internal', release_status: 'draft', skip_upload_apk: true, - aab: ANDROID_AAB_BUILD_PATH_UPLOAD, + aab: "fastlane/#{params[:export_dir]}/#{ANDROID_BUILD_FILE_NAME}.aab", json_key: ENV["GOOGLE_API_KEY_PATH"] ) else diff --git a/template/fastlane/Pluginfile b/template/fastlane/Pluginfile index 19c767a8..e69de29b 100644 --- a/template/fastlane/Pluginfile +++ b/template/fastlane/Pluginfile @@ -1 +0,0 @@ -gem 'fastlane-plugin-appcenter' \ No newline at end of file diff --git a/template/fastlane/api-key/apple/.gitkeep b/template/fastlane/api-key/apple/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/template/fastlane/api-key/apple/demo.p8 b/template/fastlane/api-key/apple/demo.p8 deleted file mode 100644 index 65a2ce84..00000000 --- a/template/fastlane/api-key/apple/demo.p8 +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- - ------END PRIVATE KEY----- \ No newline at end of file diff --git a/template/fastlane/api-key/google/.gitkeep b/template/fastlane/api-key/google/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/template/fastlane/api-key/google/demo.json b/template/fastlane/api-key/google/demo.json deleted file mode 100644 index d411fdfc..00000000 --- a/template/fastlane/api-key/google/demo.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "", - "project_id": "", - "private_key_id": "", - "private_key": "", - "client_email": "", - "client_id": "", - "auth_uri": "", - "token_uri": "", - "auth_provider_x509_cert_url": "", - "client_x509_cert_url": "" -} diff --git a/template/android/app/release-keystore/my-upload-key.keystore b/template/fastlane/release-keystore/my-upload-key.keystore similarity index 100% rename from template/android/app/release-keystore/my-upload-key.keystore rename to template/fastlane/release-keystore/my-upload-key.keystore diff --git a/template/ios/.xcode.env.local b/template/ios/.xcode.env.local deleted file mode 100644 index 5a15c714..00000000 --- a/template/ios/.xcode.env.local +++ /dev/null @@ -1 +0,0 @@ -export NODE_BINARY="/opt/homebrew/Cellar/node@16/16.19.1/bin/node" diff --git a/template/ios/Podfile b/template/ios/Podfile index 06c4387a..73f25b4c 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -8,6 +8,7 @@ require Pod::Executable.execute_command('node', ['-p', platform :ios, '13' install! 'cocoapods', :deterministic_uuids => false +flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled(["Debug"], {'Flipper' => '0.163.0'}) # dynamic_frameworks = ['libWantToUseUserFramework'] target 'HelloWorld' do @@ -32,7 +33,7 @@ target 'HelloWorld' do # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable the next line. - :flipper_configuration => FlipperConfiguration.enabled(["Debug"]), + :flipper_configuration => flipper_config, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) @@ -67,6 +68,12 @@ target 'HelloWorld' do end end end + # For m1 mac + # installer.pods_project.targets.each do |target| + # target.build_configurations.each do |config| + # config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = "arm64" + # end + # end __apply_Xcode_12_5_M1_post_install_workaround(installer) end end diff --git a/template/package.json b/template/package.json index 19d45b9f..3843880b 100644 --- a/template/package.json +++ b/template/package.json @@ -18,8 +18,7 @@ "android:gen-key": "npx ts-node scripts/android.ts keystore", "ios:dev": "npx ts-node scripts/ios.ts run env/.dev", "android:dev": "npx ts-node scripts/android.ts run env/.dev Debug", - "android:release": "npx ts-node scripts/android.ts run env/.dev Release", - "fastlane:dev": "npx ts-node scripts/fastlane.ts google_internal_test_flight env/.dev dev" + "android:release": "npx ts-node scripts/android.ts run env/.dev Release" }, "dependencies": { "@gorhom/portal": "^1.0.14", @@ -44,7 +43,7 @@ "react-native-animateable-text": "^0.11.0", "react-native-bootsplash": "^4.7.5", "react-native-config": "^1.5.1", - "react-native-flipper": "^0.206.0", + "react-native-flipper": "^0.163.0", "react-native-gesture-handler": "^2.12.1", "react-native-keyboard-controller": "^1.5.8", "react-native-keyboard-manager": "6.5.11-0", diff --git a/template/scripts/android.ts b/template/scripts/android.ts index e546da2e..e031b3a6 100644 --- a/template/scripts/android.ts +++ b/template/scripts/android.ts @@ -114,7 +114,7 @@ const genKeyStore = async () => { rl.close(); - const keyStorePath = `android/app/release-keystore/${keyName}.keystore`; + const keyStorePath = `fastlane/release-keystore/${keyName}.keystore`; const exist = existsSync(keyStorePath); diff --git a/template/scripts/fastlane.ts b/template/scripts/fastlane.ts deleted file mode 100644 index 466810b8..00000000 --- a/template/scripts/fastlane.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { execSync } from 'child_process'; - -import { setupEnv } from './common'; - -(function () { - const { argv } = process; - - const [, , buildType, envPath, fastlaneEnv] = argv; - - setupEnv(envPath); - - switch (buildType) { - case 'google_internal_test_flight': - execSync( - `bundle exec fastlane android google_internal --env ${fastlaneEnv}`, - { - stdio: 'inherit', - }, - ); - - execSync( - `bundle exec fastlane ios test_flight_build --env ${fastlaneEnv}`, - { - stdio: 'inherit', - }, - ); - - break; - - default: - break; - } -})(); diff --git a/template/scripts/setup.ts b/template/scripts/setup.ts index 9a5e6d09..7f7935ac 100644 --- a/template/scripts/setup.ts +++ b/template/scripts/setup.ts @@ -20,7 +20,7 @@ import { execSync } from 'child_process'; ' 🧐🧐🧐🧐🧐 Starting pod install!! 🧐🧐🧐🧐🧐', ); - execSync('bundle exec pod install --project-directory=ios --repo-update', { + execSync('bundle exec pod install --project-directory=ios', { stdio: 'inherit', });