Skip to content

Commit

Permalink
Added release script etc (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
osanoj authored Oct 9, 2020
1 parent 7125811 commit 86a4322
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_PATH: "bundler"
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ atlassian-ide-plugin.xml
#Rbenv
.ruby-version

#Carthage
Finjinon.framework.zip
# Bundler
bin/
bundler/

# Fastlane
fastlane/report.xml
.env
3 changes: 3 additions & 0 deletions .pr_changelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"strategy": "squash"
}
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gem 'pr_changelog', '~> 0.4.0'
gem 'fastlane', '~> 2.162.0'
180 changes: 180 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
atomos (0.1.3)
aws-eventstream (1.1.0)
aws-partitions (1.380.0)
aws-sdk-core (3.109.1)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.39.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.83.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.2.2)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
claide (1.0.3)
colored (1.2)
colored2 (3.1.2)
commander-fastlane (4.4.6)
highline (~> 1.7.2)
declarative (0.0.20)
declarative-option (0.1.0)
digest-crc (0.6.1)
rake (~> 13.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.6)
emoji_regex (3.0.0)
excon (0.76.0)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.7)
faraday (>= 0.8.0)
http-cookie (~> 1.0.0)
faraday_middleware (1.0.0)
faraday (~> 1.0)
fastimage (2.2.0)
fastlane (2.162.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
aws-sdk-s3 (~> 1.0)
babosa (>= 1.0.3, < 2.0.0)
bundler (>= 1.12.0, < 3.0.0)
colored
commander-fastlane (>= 4.4.6, < 5.0.0)
dotenv (>= 2.1.1, < 3.0.0)
emoji_regex (>= 0.1, < 4.0)
excon (>= 0.71.0, < 1.0.0)
faraday (~> 1.0)
faraday-cookie_jar (~> 0.0.6)
faraday_middleware (~> 1.0)
fastimage (>= 2.1.0, < 3.0.0)
gh_inspector (>= 1.1.2, < 2.0.0)
google-api-client (>= 0.37.0, < 0.39.0)
google-cloud-storage (>= 1.15.0, < 2.0.0)
highline (>= 1.7.2, < 2.0.0)
json (< 3.0.0)
jwt (>= 2.1.0, < 3)
mini_magick (>= 4.9.4, < 5.0.0)
multipart-post (~> 2.0.0)
plist (>= 3.1.0, < 4.0.0)
rubyzip (>= 2.0.0, < 3.0.0)
security (= 0.1.3)
simctl (~> 1.6.3)
slack-notifier (>= 2.0.0, < 3.0.0)
terminal-notifier (>= 2.0.0, < 3.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (>= 0.6.3, < 1.0.0)
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
gh_inspector (1.1.3)
google-api-client (0.38.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 0.9)
httpclient (>= 2.8.1, < 3.0)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
signet (~> 0.12)
google-cloud-core (1.5.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.3.3)
faraday (>= 0.17.3, < 2.0)
google-cloud-errors (1.0.1)
google-cloud-storage (1.29.1)
addressable (~> 2.5)
digest-crc (~> 0.4)
google-api-client (~> 0.33)
google-cloud-core (~> 1.2)
googleauth (~> 0.9)
mini_mime (~> 1.0)
googleauth (0.13.1)
faraday (>= 0.17.3, < 2.0)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.14)
highline (1.7.10)
http-cookie (1.0.3)
domain_name (~> 0.5)
httpclient (2.8.3)
jmespath (1.4.0)
json (2.3.1)
jwt (2.2.2)
memoist (0.16.2)
mini_magick (4.10.1)
mini_mime (1.0.2)
multi_json (1.15.0)
multipart-post (2.0.0)
nanaimo (0.3.0)
naturally (2.2.0)
os (1.1.1)
plist (3.5.0)
pr_changelog (0.4.0)
public_suffix (4.0.6)
rake (13.0.1)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rouge (2.0.7)
rubyzip (2.3.0)
security (0.1.3)
signet (0.14.0)
addressable (~> 2.3)
faraday (>= 0.17.3, < 2.0)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simctl (1.6.8)
CFPropertyList
naturally
slack-notifier (2.3.2)
terminal-notifier (2.0.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
tty-cursor (0.7.1)
tty-screen (0.8.1)
tty-spinner (0.9.3)
tty-cursor (~> 0.7)
uber (0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
unicode-display_width (1.7.0)
word_wrap (1.0.0)
xcodeproj (1.19.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.0)
xcpretty (~> 0.2, >= 0.0.7)

PLATFORMS
ruby

DEPENDENCIES
fastlane (~> 2.162.0)
pr_changelog (~> 0.4.0)

BUNDLED WITH
2.1.4
169 changes: 169 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.146.0"

skip_docs

desc "Create a new Finjinon version"
lane :make_finjinon_version do |options|
make_release("Finjinon", "", options)
end

desc "Attempt to connect to github.com with ssh"
lane :verify_ssh_to_github do
githuburl = "github.com"
UI.header "Verify ssh is setup and #{githuburl} can be accessed, will prompt for ssh key password if needed"
command = "ssh -T git@#{githuburl}"
sh(
command,
log: true,
error_callback: ->(result) {
sshresult = result
if sshresult.include? "successfully authenticated"
UI.success "Could authenticate to #{githuburl}"
else
UI.shell_error! "Seems connection to #{githuburl} failed"
end
}
)
end

desc "Verify that environment variable exists"
lane :verify_environment_variable do |options|
verify_and_get_github_token
end

def make_release(project, tag_prefix, options)
## Verify and get GithHub token
github_token = verify_and_get_github_token

## Verify the branch.
branch = verify_branch("master")

## Verify clean git status.
ensure_git_status_clean

## Define new tag and version.
version_bump = lookup(options, :bump, %w(major minor patch))
if version_bump.nil?
version_bump = UI.select("What do you want to bump: ", ["major", "minor", "patch"])
end
last_version = version_get_podspec(path: "#{project}.podspec")
new_tag, new_version = new_tag_and_version(last_version, tag_prefix, version_bump)

## Make sure the tag is unique.
ensure_tag_is_unique(new_tag)

## Make the user verify that the tag and version is correct.
unless UI.confirm "Will create a release with version '#{new_version}' and tag '#{new_tag}'. Is that correct?"
UI.user_error! "Version was not accepted by user."
end

version_bump_podspec(path: "#{project}.podspec", version_number: new_version)

## Update the version used when building
#todo: update_version_file("../#{project}/Version.h", new_version)

if UI.confirm "Will commit changes to files"
git_commit(path: "#{project}.podspec", message: "Bumped #{project} version to #{new_version}")
end

## Push the branch
if UI.confirm "Will push branch changes to GitHub"
push_to_git_remote
end

## Publish a new release to GitHub.
if UI.confirm "Will create a release in GitHub with tag '#{new_tag}' on branch '#{branch}'"
github_release = create_github_release("#{project} #{new_version}", new_tag, branch, github_token)
UI.success "Updated version and created release on Github!"
UI.success "Please update its description here: #{github_release['html_url']}"
system('open', github_release['html_url'])
end

## Pull the newly created tag.
git_pull(only_tags: true)
end

def lookup(options, key, allowed_values, default=nil)
if !options[key]
return default
else
value = options[key]
if allowed_values.include? value
return value
else
UI.user_error! "Error! Can't accept value for #{key}. Accepted values are #{allowed_values.join ', '}."
end
end
end

def new_tag_and_version(previous_version, prefix, version_bump=nil)
# Parse the last tag and retrieve each component.
major, minor, patch = previous_version.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/).captures

# Map some of the version components to integers.
major = major.to_i
minor = minor.to_i
patch = patch.to_i

# Bump version, if needed.
# This will reset the release type.
case version_bump
when "major"
major += 1
minor = 0
patch = 0
when "minor"
minor += 1
patch = 0
when "patch"
patch += 1
end

return "#{prefix}#{major}.#{minor}.#{patch}", "#{major}.#{minor}.#{patch}"
end

def verify_branch(branch)
# Check if already on branch.
current_branch = git_branch
if current_branch == branch
UI.success "On '#{branch}' branch"
return branch
else
if !UI.confirm "Not on '#{branch}' branch, are you sure you know what you are doing?"
UI.user_error! "Not on '#{branch}' branch"
end
UI.important "On '#{current_branch}' not '#{branch}' branch!\n"
return git_branch
end
end

def ensure_tag_is_unique(tag)
if git_tag_exists(tag: tag, remote: true)
UI.user_error! "Tag '#{tag}' already exists! Check github for the full list of tags. Bump the version if necessary."
end
end

def create_github_release(title, tag, branch, github_token)
return set_github_release(
repository_name: "finn-no/Finjinon",
name: title,
tag_name: tag,
api_token: github_token,
commitish: branch,
description: "No changelog provided. Edit me!"
)
end

def verify_and_get_github_token
return verify_env_var("FINJINON_GITHUB_ACCESS_TOKEN", "No GitHub token found! Go to https://github.com/settings/tokens to create a new token.")
end

def verify_env_var(envVar, errorMessage)
if ENV[envVar].nil?
UI.user_error! "#{errorMessage} Place this within an envvar called '#{envVar}'"
else
return ENV[envVar]
end
end

0 comments on commit 86a4322

Please sign in to comment.