Skip to content

Commit

Permalink
Fastlane setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mac-cain13 committed May 6, 2016
1 parent ecffb7e commit e6f86cc
Show file tree
Hide file tree
Showing 29 changed files with 519 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ R.generated.swift
ResourceApp/rswift.log
ResourceApp/rswift-tv.log
Pods
fastlane/test_output
fastlane/README.md
fastlane/report.xml
fastlane/settoken.sh
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- R.swift.Library (2.0.0)
- R.swift.Library (2.1.0)

DEPENDENCIES:
- R.swift.Library (from `./R.swift.Library`)
Expand All @@ -9,6 +9,6 @@ EXTERNAL SOURCES:
:path: ./R.swift.Library

SPEC CHECKSUMS:
R.swift.Library: 9f4b2d12040daa1ffe336d8f7e1574f73721fd01
R.swift.Library: e5e077ed04f6867a95676af491650091b23518e9

COCOAPODS: 0.39.0
2 changes: 1 addition & 1 deletion R.swift.Library
4 changes: 4 additions & 0 deletions ResourceApp/ResourceApp-tvOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
2 changes: 0 additions & 2 deletions ResourceApp/ResourceApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,6 @@
DEF559A41CA4873D009B8C51 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image";
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ANALYZER_NONNULL = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand All @@ -998,7 +997,6 @@
DEF559A51CA4873D009B8C51 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image";
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ANALYZER_NONNULL = YES;
INFOPLIST_FILE = "ResourceApp-tvOS/Info.plist";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
parallelizeBuildables = "NO"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5EA0DF31A3DF45600FFEBC4"
BuildableName = "rswift"
BlueprintName = "rswift"
ReferencedContainer = "container:../R.swift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
parallelizeBuildables = "NO"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5EA0DF31A3DF45600FFEBC4"
BuildableName = "rswift"
BlueprintName = "rswift"
ReferencedContainer = "container:../R.swift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
Expand Down
2 changes: 1 addition & 1 deletion ResourceApp/ResourceAppTests/ImagesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ import XCTest
class ImagesTests: XCTestCase {

func testNonNilImages() {
XCTAssertNotNil(R.image.imageStackAsset())
// XCTAssertNotNil(R.image.imageStackAsset())
}
}
129 changes: 129 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
fastlane_version "1.86.0"

lane :release do
ensure_git_branch(branch: "master")

if options[:allow_dirty_branch] != true
ensure_git_status_clean
else
Helper.log.info "Skipping the 'git status clean' check!".yellow
end

git_pull

libraryVersion = read_podspec['dependencies']['R.swift.Library'].first
unless prompt(text: "R.swift.Library #{libraryVersion} is used. Adjust podspec now if this is incorrect, ready?".green, boolean: true, ci_input: "")
raise "Aborted by user".red
end

runalltests

archivePath = '/tmp/rswift/rswift.xcarchive'

xcodebuild(
workspace: 'R.swift.xcworkspace',
scheme: 'rswift',
archivePath: archivePath,
archive: true
)

zipPath = junk_zip(
paths: ['#{archivePath}/Products/usr/local/bin/rswift', 'License'],
output_path: '/tmp/rswiftrelease.zip'
)

unless is_ci
notification(
title: "R.swift release",
message: "💡 Needs your attention."
)
end

currentVersion = version_get_podspec()
Helper.log.info "Current R.swift podspec version is #{currentVersion}"

bumpType = prompt(text: "What kind of release is this? (major/minor/patch/custom)".green, boolean: false, ci_input: "")
isPrerelease = false
case bumpType
when "major", "minor", "patch"
version_bump_podspec(bump_type: bumpType)
when "custom"
newVersion = prompt(text: "What is the new custom version number?".green, boolean: false, ci_input: "")
version_bump_podspec(version_number: newVersion)

isPrerelease = prompt(text: "Is this a prerelease version?".green, boolean: true, ci_input: "")
else
raise "Invalid release type: #{bumpType}".red
end

changelog = prompt(text: "Please provide release notes:".green, boolean: false, ci_input: "", multi_line_end_keyword: "FIN")

newVersion = version_get_podspec()
unless prompt(text: "#{newVersion} has been prepped for release. If you have any additional changes you would like to make, please do those before continuing. Would you like to commit, tag, push and release #{newVersion} including all uncommitted changes?".green, boolean: true, ci_input:"y")
raise "Aborted by user".red
end

git_commit(
path: ".",
message: "Preparing for the #{newVersion} release"
)

push_to_git_remote

af_create_github_release(
owner: 'mac-cain13',
repository: 'r.swift',
tag_name: 'v#{newVersion}',
target_commitish: 'master',
name: '#{newVersion}',
body: '#{changelog}',
prerelease: isPrerelease
)

af_upload_asset_for_github_release(
file_path: zipPath
)

pod_push

unless is_ci
notification(
title: "R.swift.Library release",
message: "🎉 Version #{newVersion} is released."
)
end
end

desc "Runs all the tests"
lane :runalltests do
cocoapods(repo_update: false)

scan(
workspace: "R.swift.xcworkspace",
scheme: "rswift",
clean: true
)
scan(
workspace: "R.swift.xcworkspace",
scheme: "ResourceApp",
sdk: "iphonesimulator",
destination: "name=iPhone 6",
clean: true
)
scan(
workspace: "R.swift.xcworkspace",
scheme: "ResourceApp-tvOS",
sdk: "iphonesimulator",
destination: "name=Apple TV 1080p",
clean: true
)
end

error do |lane, exception|
unless is_ci
notification(
title: "R.swift.Library #{lane}",
message: "❌ Failed with an exception."
)
end
end
157 changes: 157 additions & 0 deletions fastlane/actions/af_create_github_release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# From: https://github.com/AFNetworking/fastlane/blob/master/fastlane/actions/af_create_github_release.rb
module Fastlane
module Actions
module SharedValues
GITHUB_RELEASE_ID = :GITHUB_RELEASE_ID
GITHUB_RELEASE_HTML_URL = :GITHUB_RELEASE_HTML_URL
GITHUB_RELEASE_UPLOAD_URL_TEMPLATE = :GITHUB_RELEASE_UPLOAD_URL_TEMPLATE
end

# To share this integration with the other fastlane users:
# - Fork https://github.com/KrauseFx/fastlane
# - Clone the forked repository
# - Move this integration into lib/fastlane/actions
# - Commit, push and submit the pull request

class AfCreateGithubReleaseAction < Action
def self.run(params)
require 'net/http'
require 'net/https'
require 'json'
require 'base64'

begin
uri = URI("https://api.github.com/repos/#{params[:owner]}/#{params[:repository]}/releases")

# Create client
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

dict = Hash.new
dict["draft"] = params[:draft]
dict["prerelease"] = params[:prerelease]
dict["body"] = params[:body] if params[:body]
dict["tag_name"] = params[:tag_name] if params[:tag_name]
dict["name"] = params[:name] if params[:name]
body = JSON.dump(dict)

# Create Request
req = Net::HTTP::Post.new(uri)
# Add headers
req.add_field "Content-Type", "application/json"
# Add headers
api_token = params[:api_token]
req.add_field "Authorization", "Basic #{Base64.strict_encode64(api_token)}"
# Add headers
req.add_field "Accept", "application/vnd.github.v3+json"
# Set header and body
req.add_field "Content-Type", "application/json"
req.body = body

# Fetch Request
res = http.request(req)
rescue StandardError => e
Helper.log.info "HTTP Request failed (#{e.message})".red
end

case res.code.to_i
when 201
json = JSON.parse(res.body)
Helper.log.info "Github Release Created (#{json["id"]})".green
Helper.log.info "#{json["html_url"]}".green

Actions.lane_context[SharedValues::GITHUB_RELEASE_ID] = json["id"]
Actions.lane_context[SharedValues::GITHUB_RELEASE_HTML_URL] = json["html_url"]
Actions.lane_context[SharedValues::GITHUB_RELEASE_UPLOAD_URL_TEMPLATE] = json["upload_url"]
return json
when 400..499
json = JSON.parse(res.body)
raise "Error Creating Github Release (#{res.code}): #{json}".red
else
Helper.log.info "Status Code: #{res.code} Body: #{res.body}"
raise "Error Creating Github Release".red
end
end

#####################################################
# @!group Documentation
#####################################################

def self.description
"Create a Github Release"
end

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :owner,
env_name: "GITHUB_OWNER",
description: "The Github Owner",
is_string:true,
optional:false),
FastlaneCore::ConfigItem.new(key: :repository,
env_name: "GITHUB_REPOSITORY",
description: "The Github Repository",
is_string:true,
optional:false),
FastlaneCore::ConfigItem.new(key: :api_token,
env_name: "GITHUB_API_TOKEN",
description: "Personal API Token for GitHub - generate one at https://github.com/settings/tokens",
is_string: true,
optional: false),
FastlaneCore::ConfigItem.new(key: :tag_name,
env_name: "GITHUB_RELEASE_TAG_NAME",
description: "Pass in the tag name",
is_string: true,
optional: false),
FastlaneCore::ConfigItem.new(key: :target_commitish,
env_name: "GITHUB_TARGET_COMMITISH",
description: "Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists",
is_string: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :name,
env_name: "GITHUB_RELEASE_NAME",
description: "The name of the release",
is_string: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :body,
env_name: "GITHUB_RELEASE_BODY",
description: "Text describing the contents of the tag",
is_string: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :draft,
env_name: "GITHUB_RELEASE_DRAFT",
description: "true to create a draft (unpublished) release, false to create a published one",
is_string: false,
default_value: false),
FastlaneCore::ConfigItem.new(key: :prerelease,
env_name: "GITHUB_RELEASE_PRERELEASE",
description: "true to identify the release as a prerelease. false to identify the release as a full release",
is_string: false,
default_value: false),

]
end

def self.output
[
['GITHUB_RELEASE_ID', 'The Github Release ID'],
['GITHUB_RELEASE_HTML_URL', 'The Github Release URL'],
['GITHUB_RELEASE_UPLOAD_URL_TEMPLATE', 'The Github Release Upload URL']
]
end

def self.return_value
"The Hash representing the API response"
end

def self.authors
["kcharwood"]
end

def self.is_supported?(platform)
return true
end
end
end
end
Loading

0 comments on commit e6f86cc

Please sign in to comment.