Skip to content

Commit 451b3fe

Browse files
committed
Support for --version flag
1 parent dba57a8 commit 451b3fe

File tree

6 files changed

+117
-70
lines changed

6 files changed

+117
-70
lines changed

R.swift.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
D56F923F1C2942B400177FF7 /* Struct+ChildValidation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F923E1C2942B400177FF7 /* Struct+ChildValidation.swift */; };
1919
D56F92401C29475F00177FF7 /* Struct+ChildValidation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F923E1C2942B400177FF7 /* Struct+ChildValidation.swift */; };
2020
D56F92411C29476700177FF7 /* TypeVar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F923C1C29421600177FF7 /* TypeVar.swift */; };
21+
D578CAD61CE064E900C50B7E /* version.swift in Sources */ = {isa = PBXBuildFile; fileRef = D578CAD51CE064E900C50B7E /* version.swift */; };
22+
D578CAD71CE06AB000C50B7E /* version.swift in Sources */ = {isa = PBXBuildFile; fileRef = D578CAD51CE064E900C50B7E /* version.swift */; };
2123
D579466B1B9347C20044D2FC /* XCProjectFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D579466A1B9347C20044D2FC /* XCProjectFile.swift */; };
2224
D58672491C21FC9700A760EC /* TypeSequenceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58672481C21FC9700A760EC /* TypeSequenceProvider.swift */; };
2325
D586724A1C21FF7D00A760EC /* TypeSequenceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58672481C21FC9700A760EC /* TypeSequenceProvider.swift */; };
@@ -116,6 +118,7 @@
116118
D56DC76C1C41758800623437 /* AccessModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccessModifier.swift; sourceTree = "<group>"; };
117119
D56F923C1C29421600177FF7 /* TypeVar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeVar.swift; sourceTree = "<group>"; };
118120
D56F923E1C2942B400177FF7 /* Struct+ChildValidation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Struct+ChildValidation.swift"; sourceTree = "<group>"; };
121+
D578CAD51CE064E900C50B7E /* version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = version.swift; sourceTree = "<group>"; };
119122
D579466A1B9347C20044D2FC /* XCProjectFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCProjectFile.swift; sourceTree = "<group>"; };
120123
D58672481C21FC9700A760EC /* TypeSequenceProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeSequenceProvider.swift; sourceTree = "<group>"; };
121124
D59F72251C1963DA0089767C /* Type.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Type.swift; sourceTree = "<group>"; };
@@ -275,6 +278,7 @@
275278
D5F97E361C1789E50066D7C0 /* ResourceTypes */,
276279
D5F97E501C18D5EF0066D7C0 /* SwiftTypes */,
277280
D5B7997B1C1B06F5009EA901 /* Util */,
281+
D578CAD51CE064E900C50B7E /* version.swift */,
278282
);
279283
path = R.swift;
280284
sourceTree = "<group>";
@@ -459,6 +463,7 @@
459463
D59F72311C19644F0089767C /* Function.swift in Sources */,
460464
E241E4A11CD6545200F449E3 /* Unifiable.swift in Sources */,
461465
D5B799721C199755009EA901 /* ImageGenerator.swift in Sources */,
466+
D578CAD71CE06AB000C50B7E /* version.swift in Sources */,
462467
D5B7997A1C19C1BD009EA901 /* WhiteListedExtensionsResourceType.swift in Sources */,
463468
D59F722A1C1963EA0089767C /* Struct.swift in Sources */,
464469
E2156B8F1CC5255000F341DC /* StringParam.swift in Sources */,
@@ -493,6 +498,7 @@
493498
D5B129B11C3BA65C00A1C5FC /* Property.swift in Sources */,
494499
E22D43651C95845200692FFF /* ColorPalette.swift in Sources */,
495500
D5F97E421C1816360066D7C0 /* Image.swift in Sources */,
501+
D578CAD61CE064E900C50B7E /* version.swift in Sources */,
496502
D56F923D1C29421600177FF7 /* TypeVar.swift in Sources */,
497503
D5B7996E1C19940F009EA901 /* ResourceFileGenerator.swift in Sources */,
498504
E2762ACF1CCD0B970009BCAA /* LocalizableStrings.swift in Sources */,

R.swift/input.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,39 @@ enum InputParsingError: ErrorType {
1313
case IllegalOption(error: String, helpString: String)
1414
case MissingOption(error: String, helpString: String)
1515
case UserAskedForHelp(helpString: String)
16+
case UserRequestsVersionInformation(helpString: String)
17+
18+
var helpString: String {
19+
switch self {
20+
case let .IllegalOption(_, helpString):
21+
return helpString
22+
case let .MissingOption(_, helpString):
23+
return helpString
24+
case let .UserAskedForHelp(helpString):
25+
return helpString
26+
case let .UserRequestsVersionInformation(helpString):
27+
return helpString
28+
}
29+
}
30+
31+
var errorDescription: String? {
32+
switch self {
33+
case let .IllegalOption(error, _):
34+
return error
35+
case let .MissingOption(error, _):
36+
return error
37+
case .UserAskedForHelp, .UserRequestsVersionInformation:
38+
return nil
39+
}
40+
}
1641
}
1742

43+
private let versionOption = Option(
44+
trigger: .Long( "version"),
45+
numberOfParameters: 0,
46+
helpDescription: "Prints version information about this release."
47+
)
48+
1849
private let xcodeprojOption = Option(
1950
trigger: .Mixed("p", "xcodeproj"),
2051
numberOfParameters: 1,
@@ -57,6 +88,7 @@ private let sdkRootOption = Option(
5788
)
5889

5990
private let AllOptions = [
91+
versionOption,
6092
xcodeprojOption,
6193
targetOption,
6294
bundleIdentifierOption,
@@ -96,6 +128,10 @@ struct CallInformation {
96128
throw InputParsingError.UserAskedForHelp(helpString: optionParser.helpStringForCommandName(commandName))
97129
}
98130

131+
if options[versionOption] != nil {
132+
throw InputParsingError.UserRequestsVersionInformation(helpString: "\(commandName) (R.swift) \(version)")
133+
}
134+
99135
guard let outputPath = extraArguments.first where extraArguments.count == 1 else {
100136
throw InputParsingError.IllegalOption(
101137
error: "Output folder for the 'R.generated.swift' file is mandatory as last argument.",

R.swift/main.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,27 @@ do {
5656
}
5757
}
5858

59-
} catch let InputParsingError.UserAskedForHelp(helpString: helpString) {
60-
print(helpString)
61-
exit(0)
62-
} catch let InputParsingError.IllegalOption(error: error, helpString: helpString) {
63-
fail(error)
64-
print(helpString)
65-
exit(2)
66-
} catch let InputParsingError.MissingOption(error: error, helpString: helpString) {
67-
fail(error)
68-
print(helpString)
69-
exit(2)
70-
} catch let ResourceParsingError.ParsingFailed(description) {
71-
fail(description)
59+
} catch let error as InputParsingError {
60+
if let errorDescription = error.errorDescription {
61+
fail(errorDescription)
62+
}
63+
64+
print(error.helpString)
65+
66+
switch error {
67+
case .IllegalOption, .MissingOption:
68+
exit(2)
69+
case .UserAskedForHelp, .UserRequestsVersionInformation:
70+
exit(0)
71+
}
72+
} catch let error as ResourceParsingError {
73+
switch error {
74+
case let .ParsingFailed(description):
75+
fail(description)
76+
case let .UnsupportedExtension(givenExtension, supportedExtensions):
77+
let joinedSupportedExtensions = supportedExtensions.joinWithSeparator(", ")
78+
fail("File extension '\(givenExtension)' is not one of the supported extensions: \(joinedSupportedExtensions)")
79+
}
80+
7281
exit(3)
7382
}

R.swift/version.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// version.swift
3+
// R.swift
4+
//
5+
// Created by Mathijs Kadijk on 09-05-16.
6+
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
let version = "nightly build"

fastlane/Fastfile

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,41 @@ lane :release do |options|
1616
raise "Aborted by user".red
1717
end
1818

19+
currentVersion = version_get_podspec()
20+
Helper.log.info "Current R.swift podspec version is #{currentVersion}"
21+
22+
isPrerelease = false
23+
if options[:skip_version_bump] != true
24+
bumpType = prompt(text: "What kind of release is this? (major/minor/patch/custom)".green, boolean: false, ci_input: "")
25+
case bumpType
26+
when "major", "minor", "patch"
27+
version_bump_podspec(bump_type: bumpType)
28+
when "custom"
29+
newVersion = prompt(text: "What is the new custom version number?".green, boolean: false, ci_input: "")
30+
version_bump_podspec(version_number: newVersion)
31+
32+
isPrerelease = prompt(text: "Is this a prerelease version?".green, boolean: true, ci_input: "")
33+
else
34+
raise "Invalid release type: #{bumpType}".red
35+
end
36+
37+
changelog = prompt(text: "Please provide release notes:".green, boolean: false, ci_input: "", multi_line_end_keyword: "FIN")
38+
af_insert_text_into_file(
39+
file_path: "Changelog.md",
40+
text: "## #{newVersion}\n\n#{changelog}\n\n",
41+
insert_at_bottom: false
42+
)
43+
else
44+
isPrerelease = prompt(text: "Is this a prerelease version?".green, boolean: true, ci_input: "")
45+
end
46+
47+
# Sync version.swift with version in podspec
48+
filepath = '../R.swift/version.swift'
49+
newVersion = version_get_podspec()
50+
51+
content = File.read(filepath).sub(/let version = "(.*)"/, "let version = \"#{currentVersion}\"")
52+
File.open(filepath, 'wb') { |file| file.write(content) }
53+
1954
if options[:skip_tests] != true
2055
runalltests
2156
else
@@ -31,39 +66,6 @@ lane :release do |options|
3166
archive: true
3267
)
3368

34-
unless is_ci
35-
notification(
36-
title: "R.swift release",
37-
message: "💡 Needs your attention."
38-
)
39-
end
40-
41-
currentVersion = version_get_podspec()
42-
Helper.log.info "Current R.swift podspec version is #{currentVersion}"
43-
44-
bumpType = prompt(text: "What kind of release is this? (major/minor/patch/custom)".green, boolean: false, ci_input: "")
45-
isPrerelease = false
46-
case bumpType
47-
when "major", "minor", "patch"
48-
version_bump_podspec(bump_type: bumpType)
49-
when "custom"
50-
newVersion = prompt(text: "What is the new custom version number?".green, boolean: false, ci_input: "")
51-
version_bump_podspec(version_number: newVersion)
52-
53-
isPrerelease = prompt(text: "Is this a prerelease version?".green, boolean: true, ci_input: "")
54-
else
55-
raise "Invalid release type: #{bumpType}".red
56-
end
57-
58-
newVersion = version_get_podspec()
59-
changelog = prompt(text: "Please provide release notes:".green, boolean: false, ci_input: "", multi_line_end_keyword: "FIN")
60-
61-
af_insert_text_into_file(
62-
file_path: "Changelog.md",
63-
text: "## #{newVersion}\n\n#{changelog}\n\n",
64-
insert_at_bottom: false
65-
)
66-
6769
zipPath = "/tmp/rswift-#{newVersion}.zip"
6870
sh "rm -f #{zipPath}"
6971

@@ -72,6 +74,13 @@ lane :release do |options|
7274
output_path: zipPath
7375
)
7476

77+
unless is_ci
78+
notification(
79+
title: "R.swift release",
80+
message: "💡 Needs your attention."
81+
)
82+
end
83+
7584
unless prompt(text: "#{newVersion} has been build and 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")
7685
raise "Aborted by user".red
7786
end

release.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)