From 3d8ccb6f3bac570ad5396279072cff63f83de0ce Mon Sep 17 00:00:00 2001 From: andykitt Date: Thu, 30 Apr 2020 17:51:49 +0100 Subject: [PATCH 1/9] prompt user to install fastlane, run script if true. --- generators/base/index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/generators/base/index.js b/generators/base/index.js index f789606..e0a3563 100644 --- a/generators/base/index.js +++ b/generators/base/index.js @@ -19,11 +19,24 @@ module.exports = class extends Generator { message: "Do you want i18n support?", default: true, }, - ]).then(answers => { + ]).then((answers) => { this.i18nSupport = answers.i18nSupport; }); } + prompting() { + return this.prompt([ + { + type: "confirm", + name: "fastlane", + message: "Do you want add Fastlane to this project?", + default: true, + }, + ]).then((answers) => { + this.fastlane = answers.fastlane; + }); + } + writing() { // create entry points for Android and iOS this.fs.copyTpl( @@ -377,6 +390,13 @@ module.exports = class extends Generator { } ); + if (this.fastlane) { + this.log("Installing Fastlane..."); + this.spawnCommandSync("sh", [`${this.templatePath("bin")}/fastlane.sh`], { + cwd: this.destinationPath(), + }); + } + this.log("Setup complete!"); this.log("Please refer to the post-install notes"); this.log( From aae9fe1b982572155aaf14cb7a7082d8be151952 Mon Sep 17 00:00:00 2001 From: andykitt Date: Thu, 30 Apr 2020 17:51:57 +0100 Subject: [PATCH 2/9] fastlane script --- generators/base/templates/bin/fastlane.sh | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 generators/base/templates/bin/fastlane.sh diff --git a/generators/base/templates/bin/fastlane.sh b/generators/base/templates/bin/fastlane.sh new file mode 100644 index 0000000..c71fa58 --- /dev/null +++ b/generators/base/templates/bin/fastlane.sh @@ -0,0 +1,31 @@ +# current path +current=$PWD + +#fastlane init +fastlaneInit(){ + echo "Adding Fastlane to iOS..." + cd $current && cd ios && fastlane init + echo "Adding Fastlane to Android..." + cd .. && cd android && fastlane init + cd .. + cd bin && rm fastlane.sh +} + +# check if fastlane is installed +isInstalled() { +if hash fastlane 2>/dev/null; then + fastlaneInit +else + echo "How do you want to install Fastlane?" +select yn in "RubyGems" "Homebrew"; do + case $yn in + RubyGems ) echo "Installing Fastlane via RubyGems (you maybe asked for a password)... "; sudo gem install fastlane -NV ; break;; + Homebrew ) echo "Installing Fastlane via Homebrew..."; brew install fastlane ; break;; + esac + done + fastlaneInit +fi +}; + +echo "Installing fastlane..." +isInstalled; \ No newline at end of file From 637bedb4b18af3bf281b2dbf56b68e83d21a869f Mon Sep 17 00:00:00 2001 From: andykitt Date: Fri, 1 May 2020 11:39:37 +0100 Subject: [PATCH 3/9] fix prompting --- generators/base/index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/generators/base/index.js b/generators/base/index.js index e0a3563..f437c89 100644 --- a/generators/base/index.js +++ b/generators/base/index.js @@ -19,13 +19,6 @@ module.exports = class extends Generator { message: "Do you want i18n support?", default: true, }, - ]).then((answers) => { - this.i18nSupport = answers.i18nSupport; - }); - } - - prompting() { - return this.prompt([ { type: "confirm", name: "fastlane", @@ -33,6 +26,7 @@ module.exports = class extends Generator { default: true, }, ]).then((answers) => { + this.i18nSupport = answers.i18nSupport; this.fastlane = answers.fastlane; }); } From e17c68f1525d402da3c684149b6eb1a4aa99d6ad Mon Sep 17 00:00:00 2001 From: andykitt Date: Fri, 1 May 2020 11:40:12 +0100 Subject: [PATCH 4/9] remove unnecessary commands --- generators/base/templates/bin/fastlane.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/generators/base/templates/bin/fastlane.sh b/generators/base/templates/bin/fastlane.sh index c71fa58..06771b2 100644 --- a/generators/base/templates/bin/fastlane.sh +++ b/generators/base/templates/bin/fastlane.sh @@ -7,8 +7,6 @@ fastlaneInit(){ cd $current && cd ios && fastlane init echo "Adding Fastlane to Android..." cd .. && cd android && fastlane init - cd .. - cd bin && rm fastlane.sh } # check if fastlane is installed From d1e60d86ded56b2f38f0d9b82137e985adfcfdbf Mon Sep 17 00:00:00 2001 From: andykitt Date: Tue, 5 May 2020 14:44:26 +0100 Subject: [PATCH 5/9] new approach --- generators/base/index.js | 23 +++- generators/base/templates/bin/fastlane.sh | 15 +-- .../base/templates/fastlane/.env.example | 12 ++ generators/base/templates/fastlane/Appfile | 11 ++ generators/base/templates/fastlane/Fastfile | 127 ++++++++++++++++++ generators/base/templates/fastlane/Pluginfile | 6 + 6 files changed, 178 insertions(+), 16 deletions(-) create mode 100644 generators/base/templates/fastlane/.env.example create mode 100644 generators/base/templates/fastlane/Appfile create mode 100644 generators/base/templates/fastlane/Fastfile create mode 100644 generators/base/templates/fastlane/Pluginfile diff --git a/generators/base/index.js b/generators/base/index.js index f437c89..caa3323 100644 --- a/generators/base/index.js +++ b/generators/base/index.js @@ -25,7 +25,7 @@ module.exports = class extends Generator { message: "Do you want add Fastlane to this project?", default: true, }, - ]).then((answers) => { + ]).then(answers => { this.i18nSupport = answers.i18nSupport; this.fastlane = answers.fastlane; }); @@ -219,6 +219,19 @@ module.exports = class extends Generator { this.destinationPath("__mocks__") ); + // Add fastlane folder + if (this.fastlane) { + this.fs.copy( + this.templatePath("fastlane"), + this.destinationPath("fastlane") + ); + + this.fs.copy( + this.templatePath("fastlane/.env.example"), + this.destinationPath("fastlane/.env.example") + ); + } + // copy TypeScript types this.fs.copyTpl( this.templatePath("@types"), @@ -258,6 +271,12 @@ module.exports = class extends Generator { pretty: "prettier --config .prettierrc.js --write '**/*.{ts,tsx,js}'", lint: "eslint --fix './App/**/*.{ts,tsx,js}'", bump: "./bin/bump-ios.sh", + "version:bump": + "npm version patch && cd fastlane && bundle exec fastlane version_bump", + "github:release": + "cd fastlane && bundle exec fastlane github_release", + "firebase:release": + "cd fastlane && bundle exec fastlane firebase_release", test: "jest --verbose", coverage: "jest --coverage", "test:watch": "npm test -- --watch", @@ -385,7 +404,7 @@ module.exports = class extends Generator { ); if (this.fastlane) { - this.log("Installing Fastlane..."); + this.log("Checking if Fastlane is installed on your machine..."); this.spawnCommandSync("sh", [`${this.templatePath("bin")}/fastlane.sh`], { cwd: this.destinationPath(), }); diff --git a/generators/base/templates/bin/fastlane.sh b/generators/base/templates/bin/fastlane.sh index 06771b2..f17f6e0 100644 --- a/generators/base/templates/bin/fastlane.sh +++ b/generators/base/templates/bin/fastlane.sh @@ -1,18 +1,7 @@ -# current path -current=$PWD - -#fastlane init -fastlaneInit(){ - echo "Adding Fastlane to iOS..." - cd $current && cd ios && fastlane init - echo "Adding Fastlane to Android..." - cd .. && cd android && fastlane init -} - # check if fastlane is installed isInstalled() { if hash fastlane 2>/dev/null; then - fastlaneInit + echo "Fastlane already installed!" else echo "How do you want to install Fastlane?" select yn in "RubyGems" "Homebrew"; do @@ -21,9 +10,7 @@ select yn in "RubyGems" "Homebrew"; do Homebrew ) echo "Installing Fastlane via Homebrew..."; brew install fastlane ; break;; esac done - fastlaneInit fi }; -echo "Installing fastlane..." isInstalled; \ No newline at end of file diff --git a/generators/base/templates/fastlane/.env.example b/generators/base/templates/fastlane/.env.example new file mode 100644 index 0000000..8a5cd9f --- /dev/null +++ b/generators/base/templates/fastlane/.env.example @@ -0,0 +1,12 @@ +# Version Bump +GITHUB_TOKEN= +REPO_NAME= + +# Github Release +CODESIGNING_IDENTITY= + +# Firebase Release +IOS_APP_ID= +ANDROID_APP_ID= +SLACK_URL= +TESTERS= \ No newline at end of file diff --git a/generators/base/templates/fastlane/Appfile b/generators/base/templates/fastlane/Appfile new file mode 100644 index 0000000..06b6203 --- /dev/null +++ b/generators/base/templates/fastlane/Appfile @@ -0,0 +1,11 @@ +#IOS config +# app_identifier "com.app.identifier" # The bundle identifier of your app +# apple_id "apple@id.co.uk"# Your Apple email address +# team_name "TEAM NAME"# Team name for your itunes connect account +# team_id "TEAMID" # Team ID for your itunes connect account - found at https://developer.apple.com/account/#/membership/S7R8RC82YA +# itc_team_name "TEAM NAME"# Team name for your itunes connect account +# itc_team_id "TEAM ID"# Team ID for your itunes connect account + +# Android config +# json_key_file "./path-to-json-key.json"# JSON key generated for the android play store account instructions for creating at: https://docs.fastlane.tools/getting-started/android/setup/#collect-your-google-credentials +# package_name "com.android.package.id" # Application id for the android app found in build.gradle fil# \ No newline at end of file diff --git a/generators/base/templates/fastlane/Fastfile b/generators/base/templates/fastlane/Fastfile new file mode 100644 index 0000000..0d6fc75 --- /dev/null +++ b/generators/base/templates/fastlane/Fastfile @@ -0,0 +1,127 @@ +# Customise this file, documentation can be found here: +# https://github.com/fastlane/fastlane/tree/master/fastlane/docs +# All available actions: https://docs.fastlane.tools/actions +# can also be listed using the `fastlane actions` command + +# Change the syntax highlighting to Ruby +# All lines starting with a # are ignored when running `fastlane` + +# If you want to automatically update fastlane if a new version is available: +# update_fastlane + +# This is the minimum version number required. +# Update this, if you use features of a newer version +fastlane_version "2.28.3" + +# Check that there is nothing to commit and pull the latest repo. +before_all do + ensure_git_branch + ensure_git_status_clean + git_pull +end + +package = load_json(json_path: "./package.json") +appname = package["name"] +version = package["version"] + +#################### +### TEST LANE ### +#################### +lane :test_setup do + puts('FASTLANE CORRECTLY SETUP 🔥') +end + +#################### +### VERSION BUMP ### +#################### +lane :version_bump do + increment_version_number(version_number: package["version"], xcodeproj: "ios/#{appname}.xcodeproj") + commit_version_bump(message: "Release v#{version} :rocket:", xcodeproj: "ios/#{appname}.xcodeproj") + push_to_git_remote( + remote: "origin", + tags: false, + no_verify: true + ) +end + +###################### +### GITHUB RELEASE ### +###################### +lane :github_release do + ensure_env_vars( + env_vars: ['CODESIGNING_IDENTITY', 'GITHUB_TOKEN'] + ) + + ## BUILD IOS + build_ios_app( + workspace: "ios/#{appname}.xcworkspace", + output_directory: "builds/v#{version}", + export_options: { method: "app-store" }, + codesigning_identity: ENV['CODESIGNING_IDENTITY'] + ) + + ## BUILD ANDROID + gradle(task: 'clean', project_dir: 'android/') + gradle(task: 'bundle', build_type: 'Release', project_dir: 'android/') + + ## ADD TO GITHUB + set_github_release( + repository_name: "simpleweb/#{ENV['REPO_NAME']}", + api_token: ENV['GITHUB_TOKEN'], + name: "#{version}", + tag_name: "v#{version}", + description: "Add release notes here...", + commitish: "master", + is_prerelease: true, + upload_assets: ["builds/v#{version}/#{appname}.ipa", "android/app/build/outputs/bundle/release/app.aab"] + ) +end + +############################# +### FIREBASE BETA RELEASE ### +############################# +lane :firebase_release do + ensure_env_vars( + env_vars: ['IOS_APP_ID', 'ANDROID_APP_ID', 'TESTERS'] + ) + + ## SEND SLACK NOTIFICATION + if ENV['SLACK_URL'] + slack( + slack_url: ENV['SLACK_URL'], + message: "A beta release of #{appname}(v#{version}) is being uploaded to Firebase..." + ) + end + + ## UPLOAD IPA + puts "-------------------------------------------------------" + puts "--- Uploading #{appname}(v#{version}) IPA to Firebase ---" + puts "-------------------------------------------------------" + firebase_app_distribution( + app: ENV['IOS_APP_ID'], + ipa_path: "builds/v#{version}/#{appname}.ipa", + testers: ENV['TESTERS'], + release_notes: "Add release notes here...", + firebase_cli_path: "/usr/local/bin/firebase" + ) + + ## UPLOAD APK + puts "-------------------------------------------------------" + puts "--- Uploading #{appname}(v#{version}) APK to Firebase ---" + puts "-------------------------------------------------------" + firebase_app_distribution( + app: ENV['ANDROID_APP_ID'], + apk_path: "android/app/build/outputs/apk/debug/app-debug.apk", + testers: ENV['TESTERS'], + release_notes: "Add release notes here...", + firebase_cli_path: "/usr/local/bin/firebase" + ) + + ## SEND SLACK NOTIFICATION + if ENV['SLACK_URL'] + slack( + slack_url: ENV['SLACK_URL'], + message: "A beta release of #{appname}(v#{version}) is now available for testing on Firebase" + ) + end +end \ No newline at end of file diff --git a/generators/base/templates/fastlane/Pluginfile b/generators/base/templates/fastlane/Pluginfile new file mode 100644 index 0000000..9a39b1b --- /dev/null +++ b/generators/base/templates/fastlane/Pluginfile @@ -0,0 +1,6 @@ +# Autogenerated by fastlane +# +# Ensure this file is checked in to source control! + +gem 'fastlane-plugin-firebase_app_distribution' +gem 'fastlane-plugin-load_json' From 9468a8351d065128517776c0833a511d91fc0861 Mon Sep 17 00:00:00 2001 From: andykitt Date: Tue, 5 May 2020 15:11:05 +0100 Subject: [PATCH 6/9] add skip build --- generators/base/templates/fastlane/Fastfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/generators/base/templates/fastlane/Fastfile b/generators/base/templates/fastlane/Fastfile index 0d6fc75..c9c262e 100644 --- a/generators/base/templates/fastlane/Fastfile +++ b/generators/base/templates/fastlane/Fastfile @@ -80,7 +80,7 @@ end ############################# ### FIREBASE BETA RELEASE ### ############################# -lane :firebase_release do +lane :firebase_release do |options| ensure_env_vars( env_vars: ['IOS_APP_ID', 'ANDROID_APP_ID', 'TESTERS'] ) @@ -93,6 +93,16 @@ lane :firebase_release do ) end + ## BUILD IOS unless skip_build:true + unless options[:skip_build] + build_ios_app( + workspace: "ios/#{appname}.xcworkspace", + output_directory: "builds/v#{version}", + export_options: { method: "app-store" }, + codesigning_identity: ENV['CODESIGNING_IDENTITY'] + ) + end + ## UPLOAD IPA puts "-------------------------------------------------------" puts "--- Uploading #{appname}(v#{version}) IPA to Firebase ---" From 4f78994909d8528af9a3f9556efe2f2f9e5d223b Mon Sep 17 00:00:00 2001 From: andykitt Date: Tue, 5 May 2020 16:18:31 +0100 Subject: [PATCH 7/9] allow android/ios only, and build skipping --- generators/base/templates/fastlane/Fastfile | 69 ++++++++++++--------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/generators/base/templates/fastlane/Fastfile b/generators/base/templates/fastlane/Fastfile index c9c262e..8d29128 100644 --- a/generators/base/templates/fastlane/Fastfile +++ b/generators/base/templates/fastlane/Fastfile @@ -93,39 +93,48 @@ lane :firebase_release do |options| ) end - ## BUILD IOS unless skip_build:true - unless options[:skip_build] - build_ios_app( - workspace: "ios/#{appname}.xcworkspace", - output_directory: "builds/v#{version}", - export_options: { method: "app-store" }, - codesigning_identity: ENV['CODESIGNING_IDENTITY'] + + ## BUILD & UPLOAD IPA + unless options[:android_only] + unless options[:skip_build] + build_ios_app( + workspace: "ios/#{appname}.xcworkspace", + output_directory: "builds/v#{version}", + export_options: { method: "app-store" }, + codesigning_identity: ENV['CODESIGNING_IDENTITY'] + ) + end + + puts "-------------------------------------------------------" + puts "--- Uploading #{appname}(v#{version}) IPA to Firebase ---" + puts "-------------------------------------------------------" + firebase_app_distribution( + app: ENV['IOS_APP_ID'], + ipa_path: "builds/v#{version}/#{appname}.ipa", + testers: ENV['TESTERS'], + release_notes: "Add release notes here...", + firebase_cli_path: "/usr/local/bin/firebase" ) end - ## UPLOAD IPA - puts "-------------------------------------------------------" - puts "--- Uploading #{appname}(v#{version}) IPA to Firebase ---" - puts "-------------------------------------------------------" - firebase_app_distribution( - app: ENV['IOS_APP_ID'], - ipa_path: "builds/v#{version}/#{appname}.ipa", - testers: ENV['TESTERS'], - release_notes: "Add release notes here...", - firebase_cli_path: "/usr/local/bin/firebase" - ) - - ## UPLOAD APK - puts "-------------------------------------------------------" - puts "--- Uploading #{appname}(v#{version}) APK to Firebase ---" - puts "-------------------------------------------------------" - firebase_app_distribution( - app: ENV['ANDROID_APP_ID'], - apk_path: "android/app/build/outputs/apk/debug/app-debug.apk", - testers: ENV['TESTERS'], - release_notes: "Add release notes here...", - firebase_cli_path: "/usr/local/bin/firebase" - ) + ## BUILD & UPLOAD APK + unless options[:ios_only] + unless options[:skip_build] + gradle(task: 'clean', project_dir: 'android/') + gradle(task: 'bundle', build_type: 'Release', project_dir: 'android/') + end + + puts "-------------------------------------------------------" + puts "--- Uploading #{appname}(v#{version}) APK to Firebase ---" + puts "-------------------------------------------------------" + firebase_app_distribution( + app: ENV['ANDROID_APP_ID'], + apk_path: "android/app/build/outputs/apk/debug/app-debug.apk", + testers: ENV['TESTERS'], + release_notes: "Add release notes here...", + firebase_cli_path: "/usr/local/bin/firebase" + ) + end ## SEND SLACK NOTIFICATION if ENV['SLACK_URL'] From 19d5a7bee29f7b8e873163bffbe216b76251adfc Mon Sep 17 00:00:00 2001 From: andykitt Date: Tue, 5 May 2020 16:19:53 +0100 Subject: [PATCH 8/9] change debug to release in firebase release lane --- generators/base/templates/fastlane/Fastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/base/templates/fastlane/Fastfile b/generators/base/templates/fastlane/Fastfile index 8d29128..ea1e438 100644 --- a/generators/base/templates/fastlane/Fastfile +++ b/generators/base/templates/fastlane/Fastfile @@ -129,7 +129,7 @@ lane :firebase_release do |options| puts "-------------------------------------------------------" firebase_app_distribution( app: ENV['ANDROID_APP_ID'], - apk_path: "android/app/build/outputs/apk/debug/app-debug.apk", + apk_path: "android/app/build/outputs/apk/release/app-release.apk", testers: ENV['TESTERS'], release_notes: "Add release notes here...", firebase_cli_path: "/usr/local/bin/firebase" From 2606b9772c67bf621e76da0f111e3954b99a41d1 Mon Sep 17 00:00:00 2001 From: andykitt Date: Tue, 5 May 2020 16:31:09 +0100 Subject: [PATCH 9/9] update env variable checkpoints --- generators/base/templates/fastlane/Fastfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/generators/base/templates/fastlane/Fastfile b/generators/base/templates/fastlane/Fastfile index ea1e438..16e7b1c 100644 --- a/generators/base/templates/fastlane/Fastfile +++ b/generators/base/templates/fastlane/Fastfile @@ -81,9 +81,7 @@ end ### FIREBASE BETA RELEASE ### ############################# lane :firebase_release do |options| - ensure_env_vars( - env_vars: ['IOS_APP_ID', 'ANDROID_APP_ID', 'TESTERS'] - ) + ## SEND SLACK NOTIFICATION if ENV['SLACK_URL'] @@ -97,6 +95,9 @@ lane :firebase_release do |options| ## BUILD & UPLOAD IPA unless options[:android_only] unless options[:skip_build] + ensure_env_vars( + env_vars: ['CODESIGNING_IDENTITY'] + ) build_ios_app( workspace: "ios/#{appname}.xcworkspace", output_directory: "builds/v#{version}", @@ -105,6 +106,9 @@ lane :firebase_release do |options| ) end + ensure_env_vars( + env_vars: ['IOS_APP_ID', 'TESTERS'] + ) puts "-------------------------------------------------------" puts "--- Uploading #{appname}(v#{version}) IPA to Firebase ---" puts "-------------------------------------------------------" @@ -124,6 +128,9 @@ lane :firebase_release do |options| gradle(task: 'bundle', build_type: 'Release', project_dir: 'android/') end + ensure_env_vars( + env_vars: ['ANDROID_APP_ID', 'TESTERS'] + ) puts "-------------------------------------------------------" puts "--- Uploading #{appname}(v#{version}) APK to Firebase ---" puts "-------------------------------------------------------"