Skip to content

Fastlane #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions generators/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ module.exports = class extends Generator {
message: "Do you want i18n support?",
default: true,
},
{
type: "confirm",
name: "fastlane",
message: "Do you want add Fastlane to this project?",
default: true,
},
]).then((answers) => {
this.i18nSupport = answers.i18nSupport;
this.fastlane = answers.fastlane;
this.usingReactQuery = answers.httpLayer === "react-query";
this.usingReduxSaga = answers.httpLayer === "redux-saga";
});
Expand Down Expand Up @@ -246,6 +253,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")
);
}

this.fs.copyTpl(
this.templatePath("README.md"),
this.destinationPath("README.md"),
Expand All @@ -270,6 +290,12 @@ module.exports = class extends Generator {
"prettier --config .prettierrc.js --write 'App/**/*.{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",
Expand Down Expand Up @@ -383,6 +409,13 @@ module.exports = class extends Generator {
}
);

if (this.fastlane) {
this.log("Checking if Fastlane is installed on your machine...");
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(
Expand Down
16 changes: 16 additions & 0 deletions generators/base/templates/bin/fastlane.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# check if fastlane is installed
isInstalled() {
if hash fastlane 2>/dev/null; then
echo "Fastlane already installed!"
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
fi
};

isInstalled;
12 changes: 12 additions & 0 deletions generators/base/templates/fastlane/.env.example
Original file line number Diff line number Diff line change
@@ -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=
11 changes: 11 additions & 0 deletions generators/base/templates/fastlane/Appfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#IOS config
# app_identifier "com.app.identifier" # The bundle identifier of your app
# apple_id "[email protected]"# 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#
153 changes: 153 additions & 0 deletions generators/base/templates/fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# 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 |options|


## 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


## 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}",
export_options: { method: "app-store" },
codesigning_identity: ENV['CODESIGNING_IDENTITY']
)
end

ensure_env_vars(
env_vars: ['IOS_APP_ID', 'TESTERS']
)
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

## 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

ensure_env_vars(
env_vars: ['ANDROID_APP_ID', 'TESTERS']
)
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/release/app-release.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']
slack(
slack_url: ENV['SLACK_URL'],
message: "A beta release of #{appname}(v#{version}) is now available for testing on Firebase"
)
end
end
6 changes: 6 additions & 0 deletions generators/base/templates/fastlane/Pluginfile
Original file line number Diff line number Diff line change
@@ -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'