Skip to content

Commit

Permalink
Gemfile (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe authored Mar 10, 2017
1 parent 486c0c9 commit 73b0114
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 51 deletions.
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Build generated
build/
DerivedData/
Fixtures/stub-env/**/*.swiftmodule

## Various settings
*.pbxuser
Expand Down Expand Up @@ -49,8 +50,7 @@ Packages/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Checkouts
Carthage/Build

# fastlane
Expand All @@ -64,3 +64,11 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

# Other stuff
.apitoken
.DS_Store
.idea/
bin/
Frameworks/
Rome/
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ _None_

### Internal Changes

_None_
* Further refactor the Rakefile into rakelibs, and add a Gemfile for gem dependencies.
[David Jennes](https://github.com/djbe)
[#28](https://github.com/SwiftGen/SwiftGenKit/issues/28)

## 1.0.1

Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'

gem 'cocoapods', '1.2.0'
gem 'xcpretty'
77 changes: 77 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.5)
activesupport (4.2.8)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
claide (1.0.1)
cocoapods (1.2.0)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.1, < 2.0)
cocoapods-core (= 1.2.0)
cocoapods-deintegrate (>= 1.0.1, < 2.0)
cocoapods-downloader (>= 1.1.3, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.1.2, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored (~> 1.2)
escape (~> 0.0.4)
fourflusher (~> 2.0.1)
gh_inspector (~> 1.0)
molinillo (~> 0.5.5)
nap (~> 1.0)
ruby-macho (~> 0.2.5)
xcodeproj (>= 1.4.1, < 2.0)
cocoapods-core (1.2.0)
activesupport (>= 4.0.2, < 5)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.1)
cocoapods-downloader (1.1.3)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.1.2)
nap (>= 0.8, < 2.0)
netrc (= 0.7.8)
cocoapods-try (1.1.0)
colored (1.2)
escape (0.0.4)
fourflusher (2.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.0.3)
i18n (0.8.1)
minitest (5.10.1)
molinillo (0.5.6)
nanaimo (0.2.3)
nap (1.1.0)
netrc (0.7.8)
rouge (1.11.1)
ruby-macho (0.2.6)
thread_safe (0.3.6)
tzinfo (1.2.2)
thread_safe (~> 0.1)
xcodeproj (1.4.2)
CFPropertyList (~> 2.3.3)
activesupport (>= 3)
claide (>= 1.0.1, < 2.0)
colored (~> 1.2)
nanaimo (~> 0.2.3)
xcpretty (0.2.4)
rouge (~> 1.8)

PLATFORMS
ruby

DEPENDENCIES
cocoapods (= 1.2.0)
xcpretty

BUNDLED WITH
1.13.7
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
## [ Constants ] ##############################################################

WORKSPACE = 'StencilSwiftKit'
TARGET_NAME = 'Tests'
SCHEME_NAME = 'Tests'
CONFIGURATION = 'Debug'
POD_NAME = 'StencilSwiftKit'
TEST_PATH = "Tests/#{POD_NAME}Tests"


task :default => 'xcode:test'
3 changes: 1 addition & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ machine:
version: 8.2

dependencies:
pre:
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
post:
- rake lint:install
- curl -sS https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash

Expand Down
3 changes: 3 additions & 0 deletions rakelib/changelog.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Used constants:
# none

namespace :changelog do
desc 'Add the empty CHANGELOG entries after a new release'
task :reset do |task|
Expand Down
41 changes: 27 additions & 14 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
# Used constants:
# - WORKSPACE

namespace :lint do
desc 'Install swiftlint'
task :install do |task|
if !system('which swiftlint > /dev/null')
url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg'
tmppath = '/tmp/SwiftLint.pkg'
next if system('which swiftlint > /dev/null')

Utils.run([
"curl -Lo #{tmppath} #{url}",
"sudo installer -pkg #{tmppath} -target /"
], task)
end
url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg'
tmppath = '/tmp/SwiftLint.pkg'

Utils.run([
"curl -Lo #{tmppath} #{url}",
"sudo installer -pkg #{tmppath} -target /"
], task)
end

desc 'Lint the code'
task :code => :install do |task|
Utils.print_info 'Linting the code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task)
if File.directory?('Sources')
desc 'Lint the code'
task :code => :install do |task|
Utils.print_header 'Linting the code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task)
end
end

desc 'Lint the tests'
task :tests => :install do |task|
Utils.print_info 'Linting the unit test code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path "#{TEST_PATH}"), task)
Utils.print_header 'Linting the unit test code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path "Tests/#{WORKSPACE}Tests"), task)
end

if File.directory?('Tests/Expected')
desc 'Lint the output'
task :output => :install do |task|
Utils.print_header 'Linting the template output code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path Tests/Expected), task)
end
end
end
15 changes: 10 additions & 5 deletions rakelib/pod.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace :pod do
desc 'Lint the Pod'
task :lint do |task|
Utils.print_info 'Linting the pod spec'
Utils.run(%Q(pod lib lint "#{POD_NAME}.podspec" --quick), task)
# Used constants:
# - POD_NAME

if defined?(POD_NAME) && File.file?("#{POD_NAME}.podspec")
namespace :pod do
desc 'Lint the Pod'
task :lint do |task|
Utils.print_header 'Linting the pod spec'
Utils.run(%Q(bundle exec pod lib lint "#{POD_NAME}.podspec" --quick), task)
end
end
end
25 changes: 15 additions & 10 deletions rakelib/spm.rake
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
namespace :spm do
desc 'Build using SPM'
task :build do |task|
Utils.print_info 'Compile using SPM'
Utils.run("swift build", task, xcrun: true)
end
# Used constants:
# none

if File.file?('Package.swift')
namespace :spm do
desc 'Build using SPM'
task :build do |task|
Utils.print_header 'Compile using SPM'
Utils.run('swift build', task, xcrun: true)
end

desc 'Run SPM Unit Tests'
task :test => :build do |task|
Utils.print_info 'Run the unit tests using SPM'
Utils.run("swift test", task, xcrun: true)
desc 'Run SPM Unit Tests'
task :test => :build do |task|
Utils.print_header 'Run the unit tests using SPM'
Utils.run('swift test', task, xcrun: true)
end
end
end
77 changes: 66 additions & 11 deletions rakelib/utils.rake
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
# Used constants:
# none

class Utils
# formatter types
:xcpretty # pass through xcpretty and store in artifacts
:raw # store in artifacts
:to_string # run using backticks and return output

# run a command using xcrun and xcpretty if applicable
def self.run(cmd, task, subtask = '', xcrun: false, xcpretty: false, direct: false)
def self.run(cmd, task, subtask = '', xcrun: false, formatter: :raw)
commands = xcrun ? [*cmd].map { |cmd|
"#{version_select} xcrun #{cmd}"
} : [*cmd]

if xcpretty
xcpretty(commands, task, subtask)
elsif !direct
plain(commands, task, subtask)
else
`#{commands.join(' && ')}`
case formatter
when :xcpretty then xcpretty(commands, task, subtask)
when :raw then plain(commands, task, subtask)
when :to_string then `#{commands.join(' && ')}`
else raise "Unknown formatter '#{formatter}'"
end
end

# print an info header
def self.print_header(str)
puts "== #{str.chomp} ==".format(:yellow, :bold)
end

# print an info message
def self.print_info(str)
(red,clr) = (`tput colors`.chomp.to_i >= 8) ? %W(\e[33m \e[m) : ["", ""]
puts red, "== #{str.chomp} ==", clr
puts str.chomp.format(:green)
end

# print an error message
def self.print_error(str)
puts str.chomp.format(:red)
end

## [ Private helper functions ] ##################################################
Expand All @@ -29,9 +44,9 @@ class Utils
command = [*cmd].join(' && ')

if ENV['CI']
Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\""
Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | bundle exec xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\""
elsif system('which xcpretty > /dev/null')
Rake.sh "set -o pipefail && (#{command}) | xcpretty -c"
Rake.sh "set -o pipefail && (#{command}) | bundle exec xcpretty -c"
else
Rake.sh command
end
Expand Down Expand Up @@ -64,5 +79,45 @@ class Utils
%Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer")
end
private_class_method :version_select
end


class String
# colorization
FORMATTING = {
# text styling
:bold => 1,
:faint => 2,
:italic => 3,
:underline => 4,
# foreground colors
:black => 30,
:red => 31,
:green => 32,
:yellow => 33,
:blue => 34,
:magenta => 35,
:cyan => 36,
:white => 37,
# background colors
:bg_black => 40,
:bg_red => 41,
:bg_green => 42,
:bg_yellow => 43,
:bg_blue => 44,
:bg_magenta => 45,
:bg_cyan => 46,
:bg_white => 47
}

# only enable formatting if terminal supports it
if `tput colors`.chomp.to_i >= 8
def format(*styles)
styles.reduce("") { |r, s| r << "\e[#{FORMATTING[s]}m" } << "#{self}\e[0m"
end
else
def format(*styles)
self
end
end
end
13 changes: 9 additions & 4 deletions rakelib/xcode.rake
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Used constants:
# - CONFIGURATION
# - SCHEME_NAME
# - WORKSPACE

namespace :xcode do
desc 'Build using Xcode'
task :build do |task|
Utils.print_info 'Compile using Xcode'
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, xcpretty: true)
Utils.print_header 'Compile using Xcode'
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, formatter: :xcpretty)
end

desc 'Run Xcode Unit Tests'
task :test => :build do |task|
Utils.print_info 'Run the unit tests using Xcode'
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, xcpretty: true)
Utils.print_header 'Run the unit tests using Xcode'
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty)
end
end

0 comments on commit 73b0114

Please sign in to comment.