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
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."
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
}

0 commit comments

Comments
 (0)