Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Configure CircleCI #24

Merged
merged 30 commits into from
Mar 5, 2017
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dfa6cef
circle setup
djbe Feb 20, 2017
849d079
re-add the lint and compile steps
djbe Feb 20, 2017
68be4ee
use curl
djbe Feb 20, 2017
a19704f
Fix text diffing function + some missing lines from output files
djbe Feb 20, 2017
15e5ff2
disable cache for linting
djbe Feb 23, 2017
8a95f49
modules: ensure script fails if compilation fails
djbe Feb 23, 2017
9bbda4f
output: ensure script fails if one of the compilation tasks fails, bu…
djbe Feb 23, 2017
365e10a
lint: fail on warnings
djbe Feb 23, 2017
4cfaf83
smale namespace change
djbe Feb 23, 2017
a99b283
move swiftlint scripts into rakefile
djbe Feb 24, 2017
21050b4
split rakefile into libs per functional unit
djbe Feb 24, 2017
79c46e6
changelog entry
djbe Feb 24, 2017
85b1611
use xcrun with version select
djbe Feb 25, 2017
3951bb8
convert output compile scripts to ruby, also compile universal output…
djbe Feb 25, 2017
f234ca7
refactor ouput compile script to group outputs per file
djbe Feb 26, 2017
4f22d0c
print info about task
djbe Feb 26, 2017
99121eb
copy changes from stencilswiftkit
djbe Feb 28, 2017
0e5b506
run lint steps in xcode when not on CI
djbe Feb 28, 2017
1fc63cc
move files around to match kit repos
djbe Feb 28, 2017
70f0499
fix some missed lint issues
djbe Feb 28, 2017
d5cecdf
add changelog reset command
djbe Mar 1, 2017
33b6165
add gemfile and modify rake commands where needed
djbe Mar 1, 2017
0b582fa
enable/disable lint tasks automatically
djbe Mar 1, 2017
9696b6b
do the same for pod, spm and output
djbe Mar 1, 2017
4ff63a7
better run function parameters
djbe Mar 1, 2017
54bdd30
implement feedback
djbe Mar 2, 2017
42384c3
synchronize common files
djbe Mar 4, 2017
be24a2e
Move output compilation back into rakefile
djbe Mar 4, 2017
7101348
better output
djbe Mar 4, 2017
c8c1d60
pod update
djbe Mar 5, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ xcuserdata/
## Other
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
Expand Down
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

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_
* Switch from Travis CI to Circle CI, clean up the Rakefile in the process.
[David Jennes](https://github.com/djbe)
[#24](https://github.com/SwiftGen/SwiftGenKit/issues/24)

## 1.0.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SwiftGen Templates

[![Build Status](https://travis-ci.org/SwiftGen/templates.svg?branch=master)](https://travis-ci.org/SwiftGen/templates)
[![CircleCI](https://circleci.com/gh/SwiftGen/templates/tree/master.svg?style=svg)](https://circleci.com/gh/SwiftGen/templates/tree/master)
![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg)

This repository contains [Stencil](https://github.com/kylef/Stencil) templates that are dedicated for being used with [SwiftGen](https://github.com/SwiftGen/swiftgen).
Expand Down
22 changes: 7 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
def xcpretty(cmd)
if `which xcpretty` && $?.success?
sh "set -o pipefail && #{cmd} | xcpretty -c"
else
sh cmd
end
end
#!/usr/bin/rake

task :build_for_testing do
xcpretty "xcodebuild -workspace Tests/Templates.xcworkspace -scheme Tests build-for-testing"
end
## [ Constants ] ##############################################################

desc 'Run Unit Tests'
task :test => :build_for_testing do
xcpretty "xcodebuild -workspace Tests/Templates.xcworkspace -scheme Tests test-without-building"
end
WORKSPACE = 'Tests/Templates'
TARGET_NAME = 'Tests'
CONFIGURATION = 'Debug'

task :default => :test

task :default => "xcode:test"
30 changes: 0 additions & 30 deletions Scripts/compile-modules.sh

This file was deleted.

21 changes: 0 additions & 21 deletions Scripts/compile-output.sh

This file was deleted.

25 changes: 0 additions & 25 deletions Scripts/install_swiftlint.sh

This file was deleted.

6 changes: 0 additions & 6 deletions Scripts/swiftlint-code.sh

This file was deleted.

6 changes: 0 additions & 6 deletions Scripts/swiftlint-output.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,5 @@ enum StoryboardSegue {
case ShowPassword
}
}

private final class BundleToken {}
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,5 @@ enum StoryboardSegue {
case ShowPassword
}
}

private final class BundleToken {}
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,5 @@ enum StoryboardSegue {
case showPassword = "ShowPassword"
}
}

private final class BundleToken {}
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,5 @@ enum StoryboardSegue {
case ShowPassword
}
}

private final class BundleToken {}
3 changes: 3 additions & 0 deletions Tests/TestsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func diff(_ result: String, _ expected: String) -> String? {
break
}
}
if firstDiff == nil && lhsLines.count != rhsLines.count {
firstDiff = min(lhsLines.count, rhsLines.count)
}
if let badLineIdx = firstDiff {
let slice = { (lines: [String], context: Int) -> ArraySlice<String> in
let start = max(0, badLineIdx-context)
Expand Down
15 changes: 15 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
machine:
xcode:
version: 8.2

dependencies:
pre:
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
- rake lint:install

test:
override:
- rake lint:tests
- rake xcode:test
- rake output:compile
- rake lint:output
28 changes: 28 additions & 0 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace :lint do
desc 'Install swiftlint'
task :install do |task|
swiftlint = `which swiftlint`

if !(swiftlint && $?.success?)
url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg'
tmppath = '/tmp/SwiftLint.pkg'

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

desc 'Lint the tests'
task :tests => :install do |task|
print_info 'Linting the unit test code'
plain(%Q(swiftlint lint --no-cache --strict --path Tests/TestSuites), task)
end

desc 'Lint the output'
task :output => :install do |task|
print_info 'Linting the template output code'
plain(%Q(swiftlint lint --no-cache --strict --path Tests/Expected), task)
end
end
92 changes: 92 additions & 0 deletions rakelib/output.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
MODULE_INPUT_PATH = 'Fixtures/stub-env/Modules'
MODULE_OUTPUT_PATH = 'Fixtures/stub-env'
SDKS = {
:macosx => 'x86_64-apple-macosx10.12',
:iphoneos => 'armv7s-apple-ios10.0'
}
TOOLCHAINS = {
:swift2 => {
:module_path => "#{MODULE_OUTPUT_PATH}/swift2.3",
:toolchain => 'com.apple.dt.toolchain.Swift_2_3'
},
:swift3 => {
:module_path => "#{MODULE_OUTPUT_PATH}/swift3",
:toolchain => 'com.apple.dt.toolchain.XcodeDefault'
}
}

namespace :output do
desc 'Compile modules'
task :modules do |task|
print_info 'Compile output modules'

# macOS
modules = ['PrefsWindowController']
modules.each do |m|
print "Compiling module #{m}… (macos)\n"
compile_module(m, :macosx, task)
end

# iOS
modules = ['CustomSegue', 'LocationPicker', 'SlackTextViewController']
modules.each do |m|
print "Compiling module #{m}… (ios)\n"
compile_module(m, :iphoneos, task)
end

# delete swiftdoc
Dir.glob("#{MODULE_OUTPUT_PATH}/*.swiftdoc").each do |f|
FileUtils.rm_rf(f)
end
end

desc 'Compile output'
task :compile => :modules do |task|
print_info 'Compiling template output files'

exit Dir.glob('Tests/Expected/**/*.swift').map { |f|
print "Compiling #{f}…\n"
compile_file(f, task)
}.reduce(true) { |result, status|
result && status
}
end

def compile_module(m, sdk, task)
target = SDKS[sdk]
subtask = File.basename(m, '.*')
commands = TOOLCHAINS.map do |key, toolchain|
%Q(--toolchain #{toolchain[:toolchain]} -sdk #{sdk} swiftc -emit-module "#{MODULE_INPUT_PATH}/#{m}.swift" -module-name "#{m}" -emit-module-path "#{toolchain[:module_path]}" -target "#{target}")
end

xcrun(commands, task, subtask)
end

def compile_file(f, task)
if f.match('swift3')
toolchain = TOOLCHAINS[:swift3]
else
toolchain = TOOLCHAINS[:swift2]
end

if f.match('iOS')
sdks = [:iphoneos]
elsif f.match('macOS')
sdks = [:macosx]
else
sdks = [:iphoneos, :macosx]
end

commands = sdks.map do |sdk|
%Q(--toolchain #{toolchain[:toolchain]} -sdk #{sdk} swiftc -parse -target #{SDKS[sdk]} -I #{toolchain[:module_path]} "#{MODULE_OUTPUT_PATH}/Definitions.swift" #{f})
end
subtask = File.basename(f, '.*')

begin
xcrun(commands, task, subtask)
return true
rescue
return false
end
end
end
58 changes: 58 additions & 0 deletions rakelib/utils.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# run a command, pipe output through 'xcpretty' and store the output in CI artifacts
def xcpretty(cmd, task, subtask = '')
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_")
command = [*cmd].join(' && ')
xcpretty = `which xcpretty`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same remarks for rakelib/lint.rake rakelib/utils.rake here than the ones in SwiftGen/SwiftGen#269 (review)


if ENV['CI']
sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\""
elsif xcpretty && $?.success?
sh "set -o pipefail && (#{command}) | xcpretty -c"
else
sh command
end
end

# run a command and store the output in CI artifacts
def plain(cmd, task, subtask = '')
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_")
command = [*cmd].join(' && ')

if ENV['CI']
sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\""
else
sh command
end
end

# select the xcode version we want/support
def version_select
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '8.*'"`.chomp.split("\n")
if xcodes.empty?
raise "\n[!!!] You need to have Xcode 8.x to compile SwiftGen.\n\n"
end

# Order by version and get the latest one
vers = lambda { |path| `mdls -name kMDItemVersion -raw "#{path}"` }
latest_xcode_version = xcodes.sort { |p1, p2| vers.call(p1) <=> vers.call(p2) }.last
%Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer")
end

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

if commands.join.match('xcodebuild')
xcpretty(commands, task, subtask)
else
plain(commands, task, subtask)
end
end

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