Skip to content
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

memoize version_select #10

Merged
merged 8 commits into from
Aug 27, 2017
Merged
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
20 changes: 20 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
AllCops:
TargetRubyVersion: 2.0
Exclude:
- SwiftGenKit/Tests/Resources/**/*
- SwiftGen/Resources/**/*

Style/HashSyntax:
Enabled: false

Metrics/AbcSize:
Max: 24

Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Max: 140

Metrics/MethodLength:
Max: 20
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'cocoapods', '1.3.1'
gem 'xcpretty'
gem 'rake'
gem 'octokit', '~> 4.7'
gem 'plist', '~> 3.2'
gem 'rake'
gem 'rubocop'
gem 'xcpretty'
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
ast (2.3.0)
claide (1.0.2)
cocoapods (1.3.1)
activesupport (>= 4.0.2, < 5)
Expand Down Expand Up @@ -59,17 +60,32 @@ GEM
netrc (0.7.8)
octokit (4.7.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.11.2)
parser (2.4.0.0)
ast (~> 2.2)
plist (3.3.0)
powerpack (0.1.1)
public_suffix (2.0.5)
rainbow (2.2.2)
rake
rake (12.0.0)
rouge (2.0.7)
rubocop (0.49.1)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-macho (1.1.0)
ruby-progressbar (1.8.1)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unicode-display_width (1.2.1)
xcodeproj (1.5.1)
CFPropertyList (~> 2.3.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -86,6 +102,7 @@ DEPENDENCIES
octokit (~> 4.7)
plist (~> 3.2)
rake
rubocop
xcpretty

BUNDLED WITH
Expand Down
80 changes: 52 additions & 28 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ require 'uri'
require 'plist'

namespace :repos do
REPOS = [:StencilSwiftKit, :SwiftGenKit, :SwiftGen, :templates].freeze
REPOS = %i[StencilSwiftKit SwiftGenKit SwiftGen templates].freeze
desc 'Bootstrap this repository for development'
task :bootstrap do
REPOS.each do |repository|
next if Dir.exists? "#{repository}"
next if Dir.exist? repository.to_s

sh "git clone [email protected]:SwiftGen/#{repository}.git --recursive"
Dir.chdir("#{repository}") do
sh "git submodule update --init --recursive"
Dir.chdir(repository.to_s) do
sh 'git submodule update --init --recursive'
end
end
end
Expand Down Expand Up @@ -46,7 +46,7 @@ end

namespace :submodules do
def submodules(cmd)
[:SwiftGenKit, :SwiftGen].each do |repository|
%i[SwiftGenKit SwiftGen].each do |repository|
Utils.print_header repository.to_s
Dir.chdir(repository.to_s) do
sh(cmd)
Expand All @@ -62,8 +62,8 @@ namespace :submodules do
desc 'Show status for submodules of each repo'
task :status do
Utils.print_header "Current 'templates' commit"
Dir.chdir('templates') { sh "git describe --all && git describe --always" }
submodules("git submodule status")
Dir.chdir('templates') { sh 'git describe --all && git describe --always' }
submodules('git submodule status')
end
end

Expand All @@ -79,7 +79,11 @@ namespace :release do

# Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early)
`which bundler`
results << Utils.table_result( $?.success?, 'Bundler installed', 'Please install bundler using `gem install bundler` and run `bundle install` first.')
results << Utils.table_result(
$CHILD_STATUS.success?,
'Bundler installed',
'Please install bundler using `gem install bundler` and run `bundle install` first.'
)

# Extract version from SwiftGen.podspec
version = Utils.podspec_version('SwiftGen')
Expand All @@ -89,32 +93,52 @@ namespace :release do
check_dep_versions = lambda do |pod|
lock_version = Utils.podfile_lock_version(pod)
pod_version = Utils.podspec_version(pod)
results << Utils.table_result(lock_version == pod_version, "#{pod.ljust(Utils::COLUMN_WIDTH-10)} (#{pod_version})", "Please update #{pod} to latest version in your Podfile")
results << Utils.table_result(
lock_version == pod_version,
"#{pod.ljust(Utils::COLUMN_WIDTH - 10)} (#{pod_version})",
"Please update #{pod} to latest version in your Podfile"
)
end
check_dep_versions.call('SwiftGenKit')
check_dep_versions.call('StencilSwiftKit')

# Check if version matches the Info.plist
results << Utils.table_result(version == Utils.plist_version, "Info.plist version matches", "Please update the version numbers in the Info.plist file")
results << Utils.table_result(
version == Utils.plist_version,
'Info.plist version matches',
'Please update the version numbers in the Info.plist file'
)

# Check if submodule is aligned
submodule_aligned = Dir.chdir('SwiftGen/Resources') do
sh "git fetch origin >/dev/null"
sh 'git fetch origin >/dev/null'
`git rev-parse origin/master`.chomp == `git rev-parse HEAD`.chomp
end
results << Utils.table_result(submodule_aligned, "Submodule on origin/master", "Please align the submodule to master")
results << Utils.table_result(
submodule_aligned,
'Submodule on origin/master',
'Please align the submodule to master'
)

# Check if entry present in CHANGELOG
changelog_entry = system(%Q{grep -q '^## #{Regexp.quote(version)}$' SwiftGen/CHANGELOG.md})
results << Utils.table_result(changelog_entry, "CHANGELOG, Entry added", "Please add an entry for #{version} in CHANGELOG.md")

changelog_master = system(%q{grep -qi '^## Master' SwiftGen/CHANGELOG.md})
results << Utils.table_result(!changelog_master, "CHANGELOG, No master", 'Please remove entry for master in CHANGELOG')
changelog_entry = system("grep -q '^## #{Regexp.quote(version)}$' SwiftGen/CHANGELOG.md")
results << Utils.table_result(
changelog_entry,
'CHANGELOG, Entry added',
"Please add an entry for #{version} in CHANGELOG.md"
)

changelog_master = system("grep -qi '^## Master' SwiftGen/CHANGELOG.md")
results << Utils.table_result(
!changelog_master,
'CHANGELOG, No master',
'Please remove entry for master in CHANGELOG'
)

exit 1 unless results.all?

print "Release version #{version} [Y/n]? "
exit 2 unless (STDIN.gets.chomp == 'Y')
exit 2 unless STDIN.gets.chomp == 'Y'
end

desc 'Create a zip containing all the prebuilt binaries'
Expand All @@ -125,7 +149,7 @@ namespace :release do

def post(url, content_type)
uri = URI.parse(url)
req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' => content_type})
req = Net::HTTP::Post.new(uri, initheader: { 'Content-Type' => content_type })
yield req if block_given?
req.basic_auth 'AliSoftware', File.read('.apitoken').chomp

Expand All @@ -144,15 +168,15 @@ namespace :release do
task :github => :zip do
v = Utils.podspec_version

changelog = `sed -n /'^## #{v}$'/,/'^## '/p SwiftGen/CHANGELOG.md`.gsub(/^## .*$/,'').strip
changelog = `sed -n /'^## #{v}$'/,/'^## '/p SwiftGen/CHANGELOG.md`.gsub(/^## .*$/, '').strip
Utils.print_header "Releasing version #{v} on GitHub"
puts changelog

json = post('https://api.github.com/repos/SwiftGen/SwiftGen/releases', 'application/json') do |req|
req.body = { :tag_name => v, :name => v, :body => changelog, :draft => false, :prerelease => false }.to_json
end

upload_url = json['upload_url'].gsub(/\{.*\}/,"?name=swiftgen-#{v}.zip")
upload_url = json['upload_url'].gsub(/\{.*\}/, "?name=swiftgen-#{v}.zip")
zipfile = "SwiftGen/build/swiftgen-#{v}.zip"
zipsize = File.size(zipfile)

Expand All @@ -166,15 +190,15 @@ namespace :release do

desc 'pod trunk push SwiftGen to CocoaPods'
task :cocoapods do
Utils.print_header "Pushing pod to CocoaPods Trunk"
Utils.print_header 'Pushing pod to CocoaPods Trunk'
Dir.chdir('SwiftGen') do
sh 'bundle exec pod trunk push SwiftGen.podspec'
end
end

desc 'Release a new version on Homebrew and prepare a PR'
task :homebrew do
Utils.print_header "Updating Homebrew Formula"
Utils.print_header 'Updating Homebrew Formula'
tag = Utils.podspec_version
revision = Dir.chdir('SwiftGen') { `git rev-list -1 #{tag}`.chomp }
formulas_dir = Bundler.with_clean_env { `brew --repository homebrew/core`.chomp }
Expand All @@ -187,17 +211,17 @@ namespace :release do
formula = File.read(formula_file)

new_formula = formula
.gsub(%r(:tag => ".*"), %Q(:tag => "#{tag}"))
.gsub(%r(:revision => ".*"), %Q(:revision => "#{revision}"))
.gsub(/:tag => ".*"/, %(:tag => "#{tag}"))
.gsub(/:revision => ".*"/, %(:revision => "#{revision}"))
File.write(formula_file, new_formula)
Utils.print_header "Checking Homebrew formula..."
Utils.print_header 'Checking Homebrew formula...'
Bundler.with_clean_env do
sh 'brew audit --strict --online swiftgen'
sh 'brew upgrade swiftgen'
sh 'brew test swiftgen'
end

Utils.print_header "Pushing to Homebrew"
Utils.print_header 'Pushing to Homebrew'
sh "git add #{formula_file}"
sh "git commit -m 'swiftgen #{tag}'"
sh "git push -u AliSoftware swiftgen-#{tag}"
Expand All @@ -206,4 +230,4 @@ namespace :release do
end
end

task :default => "release:new"
task :default => 'release:new'
5 changes: 3 additions & 2 deletions common/Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'cocoapods', '1.3.1'
gem 'xcpretty'
gem 'rake'
gem 'octokit', '~> 4.7'
gem 'rake'
gem 'xcpretty'
23 changes: 11 additions & 12 deletions common/rakelib/changelog.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace :changelog do
desc 'Add the empty CHANGELOG entries after a new release'
task :reset do |task|
task :reset do
changelog = File.read('CHANGELOG.md')
abort('A Master entry already exists') if changelog =~ /^##\s*Master$/
changelog.sub!(/^##[^#]/, "#{header}\\0")
File.write('CHANGELOG.md', changelog)
end

def header
return <<-HEADER.gsub(/^\s*\|/,'')
<<-HEADER.gsub(/^\s*\|/, '')
|## Master
|
|### Bug Fixes
Expand All @@ -34,20 +34,19 @@ namespace :changelog do
end

desc 'Check if links to issues and PRs use matching numbers between text & link'
task :check do |task|
task :check do
current_repo = File.basename(`git remote get-url origin`.chomp, '.git').freeze
slug_re = '([a-zA-Z]*/[a-zA-Z]*)'
links = %r{\[#{slug_re}?\#([0-9]+)\]\(https://github.com/#{slug_re}/(issues|pull)/([0-9]+)\)}
all_wrong_links = []
File.readlines('CHANGELOG.md').each_with_index do |line, idx|
wrong_links = line.scan(links)
.reject do |m|
(slug, num, url_slug, url_num) = [m[0] || "SwiftGen/#{current_repo}", m[1], m[2], m[4]]
(slug == url_slug) && (num == url_num)
end.map do |m|
" - Line #{idx+1}, link text is #{m[0]}##{m[1]} but links points to #{m[2]}##{m[4]}"
end
all_wrong_links.concat(wrong_links)
wrong_links = line.scan(links).reject do |m|
slug = m[0] || "SwiftGen/#{current_repo}"
(slug == m[2]) && (m[1] == m[4])
end
all_wrong_links.concat wrong_links.map do |m|
" - Line #{idx + 1}, link text is #{m[0]}##{m[1]} but links points to #{m[2]}##{m[4]}"
end
end
if all_wrong_links.empty?
puts "\u{2705} All links correct"
Expand All @@ -65,6 +64,6 @@ namespace :changelog do
body = Utils.top_changelog_entry

repo_name = File.basename(`git remote get-url origin`.chomp, '.git').freeze
client.create_release("SwiftGen/#{repo_name}", tag, :body => body)
client.create_release("SwiftGen/#{repo_name}", tag, body: body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 does that with with system ruby? I though that syntax was Ruby 2.1 or 2.2 only?

Copy link
Member Author

@djbe djbe Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik, it's ruby 1.9 syntax:

utils.rake:49:25: C: [Corrected] Use the new Ruby 1.9 hash syntax.
Octokit::Client.new(:access_token => token)
_____________________^^^^^^^^^^^^^^^

end
end
Loading