Skip to content

Commit 9bce1fd

Browse files
authored
feat: add release tagging and clean up code (#133)
* feat: add release tagging and clean up code * fix: add commitlint and releaserc * chore: add release drafter file
1 parent d781a58 commit 9bce1fd

File tree

16 files changed

+201
-78
lines changed

16 files changed

+201
-78
lines changed

.commitlintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@commitlint/config-conventional"]
3+
}

.github/release-drafter.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
template: |
2+
## What’s Changed
3+
4+
$CHANGES

.github/workflows/create_release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
# We create a new version if the branch is master.
10+
version_and_publish:
11+
name: Create Release
12+
if: github.ref == 'refs/heads/master'
13+
runs-on: ubuntu-latest
14+
outputs:
15+
release_version: ${{ steps.generate_version.outputs.release_version }}
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
21+
# In future we should run tests to ensure if it's worth making a release.
22+
- name: Install semantic-release
23+
run: |
24+
npm set registry https://registry.npmjs.org/
25+
sudo npm install -g \
26+
semantic-release \
27+
@semantic-release/commit-analyzer \
28+
@semantic-release/github \
29+
@semantic-release/exec \
30+
@semantic-release/release-notes-generator \
31+
conventional-changelog-conventionalcommits
32+
33+
- name: Generate version
34+
id: generate_version
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
37+
NPM_TOKEN: ${{ secrets.GH_TOKEN }}
38+
run: |
39+
npx semantic-release --ci
40+
41+
- name: No Releases Done
42+
if: "!steps.generate_version.outputs.release_version"
43+
run: |
44+
echo "No Release was done either due to wrong commit or no major changes."

.github/workflows/release_drafter.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
# branches to consider in the event; optional, defaults to all
6+
branches:
7+
- dev
8+
pull_request:
9+
types: [opened, reopened, synchronize]
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
update_release_draft:
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: release-drafter/release-drafter@v5
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

.releaserc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"branches": ["main"],
3+
"tagFormat": "${version}",
4+
"plugins": [
5+
[
6+
"@semantic-release/commit-analyzer", {
7+
"preset": "conventionalcommits",
8+
"releaseRules": [
9+
{"type": "doc", "release": false},
10+
{"type": "test", "release": false},
11+
{"type": "chore", "release": "patch"},
12+
{"type": "devx", "release": false}
13+
],
14+
"parserOpts": {
15+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
16+
}
17+
}
18+
],
19+
"@semantic-release/github",
20+
[
21+
"@semantic-release/exec", {
22+
"publishCmd": "echo \"::set-output name=release_version::${nextRelease.version}\""
23+
}
24+
],
25+
[
26+
"@semantic-release/release-notes-generator", {
27+
"preset": "conventionalcommits",
28+
"presetConfig": {
29+
"types": [
30+
{"type": "feat", "section": "Features"},
31+
{"type": "fix", "section": "Bug Fixes"},
32+
{"type": "doc", "section": "Documentation", "hidden": true},
33+
{"type": "test", "section": "Tests", "hidden": true},
34+
{"type": "chore", "section": "Chore / Improvements"},
35+
{"type": "devx", "section": "Improved Developer Experience", "hidden": false}
36+
]
37+
},
38+
"parserOpts": {
39+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
40+
},
41+
"writerOpts": {
42+
"commitsSort": ["subject", "scope"]
43+
}
44+
}
45+
]
46+
]
47+
}

Core/Constants.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ enum AccessControl: String, CaseIterable {
4141
case .internal:
4242
// The default access control type, no need to explicitly set it
4343
return ""
44-
case .private:
45-
return "private "
46-
case .public:
47-
return "public "
44+
default:
45+
return rawValue
4846
}
4947
}
5048
}
@@ -76,6 +74,6 @@ enum PropertyType: String {
7674
}
7775

7876
/// Place to store actual constants that don't fit in classes.
79-
struct Constants {
77+
enum Constants {
8078
static let filePathKey: String = "path"
8179
}

Core/Generator/FileGeneratorExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension FileGenerator {
6161

6262
- returns: Boolean indicating if the process was successful.
6363
*/
64-
internal static func writeToFileWith(_ name: String, content: String, path: String) throws {
64+
static func writeToFileWith(_ name: String, content: String, path: String) throws {
6565
let filename = path.appendingFormat("%@", name + ".swift")
6666
try FileManager.default.createDirectory(at: URL(fileURLWithPath: path),
6767
withIntermediateDirectories: true,

Core/Generator/Model-File-Components/SwiftJSONModelFile.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ struct SwiftJSONModelFile: ModelFile {
8383

8484
func genPrimitiveVariableDeclaration(_ name: String, _ type: String, _ isOptional: Bool) -> String {
8585
let optionalSuffix = isOptional ? "?" : ""
86-
return "\(accessControl.declarationPrefix)var \(name): \(type)\(optionalSuffix)"
86+
var declrationPrefix = ""
87+
if !accessControl.declarationPrefix.isEmpty {
88+
declrationPrefix = "\(accessControl.declarationPrefix) "
89+
}
90+
return "\(declrationPrefix)var \(name): \(type)\(optionalSuffix)"
8791
}
8892

8993
/// Generate the variable declaration string

Core/Generator/MultipleModelGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ enum MultipleModelGeneratorError: Error, Equatable {
5151
}
5252

5353
/// A structure to generate multiple mdoels from JSON files at once.
54-
struct MultipleModelGenerator {
54+
enum MultipleModelGenerator {
5555
/// Generate models for the JSON files in the given path. Use the `.config.json` to load config.
5656
///
5757
/// - Parameter forPath: Path with the JSON files.

Core/Generator/NameGenerator.swift

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,36 @@ struct NameGenerator {
5050
/// - Parameter currentName: The current name which has to be checked.
5151
/// - Returns: New name for the variable.
5252
static func replaceKeywords(_ currentName: String) -> String {
53-
5453
/// Swift keywords from https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID413 as of 2020-10-10
5554
/// Does not include the "sometimes" keywords
5655
/// Thanks to a PR from @TheMadBug.
5756
let swiftKeywords: Set = [
58-
"associatedtype", "class", "deinit",
59-
"enum", "extension", "fileprivate",
60-
"func", "import", "init",
61-
"inout", "internal", "let",
62-
"open", "operator", "private",
63-
"protocol", "public", "rethrows",
64-
"static", "struct", "subscript",
65-
"typealias", "var",
66-
"break", "case", "continue",
67-
"default", "defer", "do",
68-
"else", "fallthrough", "for",
69-
"guard", "if", "in",
70-
"repeat", "return", "switch",
71-
"where", "while",
72-
"as", "Any", "catch",
73-
"false", "is", "nil",
74-
"super", "self", "Self",
75-
"throw", "throws", "true",
76-
"try"
77-
]
78-
57+
"associatedtype", "class", "deinit",
58+
"enum", "extension", "fileprivate",
59+
"func", "import", "init",
60+
"inout", "internal", "let",
61+
"open", "operator", "private",
62+
"protocol", "public", "rethrows",
63+
"static", "struct", "subscript",
64+
"typealias", "var",
65+
"break", "case", "continue",
66+
"default", "defer", "do",
67+
"else", "fallthrough", "for",
68+
"guard", "if", "in",
69+
"repeat", "return", "switch",
70+
"where", "while",
71+
"as", "Any", "catch",
72+
"false", "is", "nil",
73+
"super", "self", "Self",
74+
"throw", "throws", "true",
75+
"try",
76+
]
77+
7978
var keywordsWithReplacements: [String: String] = [:]
8079
for keyword in swiftKeywords {
8180
keywordsWithReplacements[keyword] = "\(keyword)Value"
8281
}
83-
82+
8483
if let value = keywordsWithReplacements[currentName] {
8584
return value
8685
}

Core/Helpers/JSONHelper.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct JSONParserResponse {
2121
}
2222

2323
/// Provide helpers to handle JSON content that the user provided.
24-
struct JSONHelper {
24+
enum JSONHelper {
2525
/// Validate if the string that is provided can be converted into a valid JSON.
2626
///
2727
/// - Parameter jsonString: Input string that is to be checked as JSON.
@@ -77,16 +77,19 @@ struct JSONHelper {
7777
/// - Parameter items: An array of JSON items that have to be reduced.
7878
/// - Returns: Reduced JSON with the common key/value pairs.
7979
static func reduce(_ items: [JSON]) -> JSON {
80-
return items.reduce([:]) { (source, item) -> JSON in
80+
return items.reduce([:]) { source, item -> JSON in
8181
var finalObject = source
8282
for (key, jsonValue) in item {
8383
if let newValue = jsonValue.dictionary {
8484
finalObject[key] = reduce([JSON(newValue), finalObject[key]])
8585
} else if let newValue = jsonValue.array, newValue.first != nil && (newValue.first!.dictionary != nil || newValue.first!.array != nil) {
8686
finalObject[key] = JSON([reduce(newValue + finalObject[key].arrayValue)])
87+
// swiftlint:disable all
88+
// swift-format-ignore
8789
} else if jsonValue != JSON.null || !finalObject[key].exists() {
8890
finalObject[key] = jsonValue
8991
}
92+
// swiftlint:enable all
9093
}
9194
return finalObject
9295
}
@@ -126,7 +129,7 @@ extension JSON {
126129
.cgFloatType,
127130
.doubleType:
128131
return .float
129-
// Covers any future types for CFNumber.
132+
// Covers any future types for CFNumber.
130133
@unknown default:
131134
return .float
132135
}

SwiftyJSONAccelerator.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@
359359
isa = PBXProject;
360360
attributes = {
361361
LastSwiftUpdateCheck = 1030;
362-
LastUpgradeCheck = 1030;
362+
LastUpgradeCheck = 1340;
363363
ORGANIZATIONNAME = "Karthikeya Udupa";
364364
TargetAttributes = {
365365
93E0F10322E859D5008D3B16 = {
@@ -617,6 +617,7 @@
617617
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
618618
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
619619
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
620+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
620621
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
621622
CLANG_WARN_STRICT_PROTOTYPES = YES;
622623
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -678,6 +679,7 @@
678679
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
679680
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
680681
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
682+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
681683
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
682684
CLANG_WARN_STRICT_PROTOTYPES = YES;
683685
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -712,6 +714,7 @@
712714
buildSettings = {
713715
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
714716
CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements;
717+
CODE_SIGN_IDENTITY = "-";
715718
CODE_SIGN_STYLE = Automatic;
716719
COMBINE_HIDPI_IMAGES = YES;
717720
CURRENT_PROJECT_VERSION = 14;
@@ -735,6 +738,7 @@
735738
buildSettings = {
736739
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
737740
CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements;
741+
CODE_SIGN_IDENTITY = "-";
738742
CODE_SIGN_STYLE = Automatic;
739743
COMBINE_HIDPI_IMAGES = YES;
740744
CURRENT_PROJECT_VERSION = 14;

SwiftyJSONAccelerator.xcodeproj/xcshareddata/xcschemes/SwiftyJSONAccelerator.xcscheme

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1030"
3+
LastUpgradeVersion = "1340"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,11 +26,20 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
2930
systemAttachmentLifetime = "keepNever"
3031
userAttachmentLifetime = "keepAlways"
3132
codeCoverageEnabled = "YES"
32-
onlyGenerateCoverageForSpecifiedTargets = "YES"
33-
shouldUseLaunchSchemeArgsEnv = "YES">
33+
onlyGenerateCoverageForSpecifiedTargets = "YES">
34+
<MacroExpansion>
35+
<BuildableReference
36+
BuildableIdentifier = "primary"
37+
BlueprintIdentifier = "93E0F10322E859D5008D3B16"
38+
BuildableName = "SwiftyJSONAccelerator.app"
39+
BlueprintName = "SwiftyJSONAccelerator"
40+
ReferencedContainer = "container:SwiftyJSONAccelerator.xcodeproj">
41+
</BuildableReference>
42+
</MacroExpansion>
3443
<CodeCoverageTargets>
3544
<BuildableReference
3645
BuildableIdentifier = "primary"
@@ -54,17 +63,6 @@
5463
</BuildableReference>
5564
</TestableReference>
5665
</Testables>
57-
<MacroExpansion>
58-
<BuildableReference
59-
BuildableIdentifier = "primary"
60-
BlueprintIdentifier = "93E0F10322E859D5008D3B16"
61-
BuildableName = "SwiftyJSONAccelerator.app"
62-
BlueprintName = "SwiftyJSONAccelerator"
63-
ReferencedContainer = "container:SwiftyJSONAccelerator.xcodeproj">
64-
</BuildableReference>
65-
</MacroExpansion>
66-
<AdditionalOptions>
67-
</AdditionalOptions>
6866
</TestAction>
6967
<LaunchAction
7068
buildConfiguration = "Debug"
@@ -86,8 +84,6 @@
8684
ReferencedContainer = "container:SwiftyJSONAccelerator.xcodeproj">
8785
</BuildableReference>
8886
</BuildableProductRunnable>
89-
<AdditionalOptions>
90-
</AdditionalOptions>
9187
</LaunchAction>
9288
<ProfileAction
9389
buildConfiguration = "Release"

SwiftyJSONAccelerator/UI/External-Libraries/LineNumberRulerView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,17 @@ class LineNumberRulerView: NSRulerView {
8282
ruleThickness = 40
8383
}
8484

85+
@available(*, unavailable)
8586
required init(coder _: NSCoder) {
8687
fatalError("init(coder:) has not been implemented")
8788
}
8889

8990
override func drawHashMarksAndLabels(in _: NSRect) {
90-
if let textView = self.clientView as? NSTextView {
91+
if let textView = clientView as? NSTextView {
9192
if let layoutManager = textView.layoutManager {
9293
let relativePoint = convert(NSZeroPoint, from: textView)
9394
let lineNumberAttributes = [NSAttributedString.Key.font.rawValue: textView.font!, NSAttributedString.Key.foregroundColor: NSColor.gray] as! [NSAttributedString.Key: Any]
94-
let drawLineNumber = { (lineNumberString: String, y: CGFloat) -> Void in
95+
let drawLineNumber = { (lineNumberString: String, y: CGFloat) in
9596
let attString = NSAttributedString(string: lineNumberString, attributes: lineNumberAttributes)
9697
let x = 35 - attString.size().width
9798
attString.draw(at: NSPoint(x: x, y: relativePoint.y + y))

0 commit comments

Comments
 (0)