Skip to content

Commit bb70145

Browse files
authored
Merge pull request #90 from janderit/LinuxCompatibility
Linux testing on CI
2 parents 2aa6ff1 + 22ead52 commit bb70145

22 files changed

+387
-127
lines changed

.circleci/config.yml

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defaults:
2-
- &default-config
2+
- &macos-config
33
parallelism: 1
44
environment:
55
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
@@ -8,6 +8,14 @@ defaults:
88
macos:
99
xcode: "9.3.0"
1010
shell: /bin/bash --login -eo pipefail
11+
- &linux-config
12+
environment:
13+
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
14+
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
15+
BUNDLE_PATH: vendor/bundle
16+
docker:
17+
- image: norionomura/jazzy:swift-4.1.3
18+
shell: /bin/bash --login -eo pipefail
1119
- &prepare-storage
1220
run:
1321
name: Create directories for artifacts and reports
@@ -41,7 +49,7 @@ defaults:
4149
version: 2
4250
jobs:
4351
lint:
44-
<<: *default-config
52+
<<: *macos-config
4553
steps:
4654
- *prepare-storage
4755
- checkout
@@ -57,7 +65,7 @@ jobs:
5765
- *store-artifacts
5866

5967
xcode-build-and-test:
60-
<<: *default-config
68+
<<: *macos-config
6169
steps:
6270
- *prepare-storage
6371
- checkout
@@ -72,8 +80,21 @@ jobs:
7280
- *fetch-xcode-logs
7381
- *store-artifacts
7482

75-
spm-build-and-test:
76-
<<: *default-config
83+
spm-linux-build-and-test:
84+
<<: *linux-config
85+
steps:
86+
- *prepare-storage
87+
- checkout
88+
- *restore-gems
89+
- *install-gems
90+
- *store-gems
91+
- run:
92+
name: Run all tests
93+
command: bundle exec rake spm:test
94+
- *store-artifacts
95+
96+
spm-mac-build-and-test:
97+
<<: *macos-config
7798
steps:
7899
- *prepare-storage
79100
- checkout
@@ -86,7 +107,7 @@ jobs:
86107
- *store-artifacts
87108

88109
check-deploy:
89-
<<: *default-config
110+
<<: *macos-config
90111
steps:
91112
- *prepare-storage
92113
- checkout
@@ -107,10 +128,12 @@ workflows:
107128
lint-buildandtest-checkdeploy:
108129
jobs:
109130
- lint
110-
- spm-build-and-test
131+
- spm-linux-build-and-test
132+
- spm-mac-build-and-test
111133
- xcode-build-and-test
112134
- check-deploy:
113135
requires:
114136
- lint
115-
- spm-build-and-test
137+
- spm-linux-build-and-test
138+
- spm-mac-build-and-test
116139
- xcode-build-and-test

.swiftlint.yml

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ line_length:
4848
nesting:
4949
type_level:
5050
warning: 2
51+
52+
# Exclude generated files
53+
excluded:
54+
- XCTestManifests.swift

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
### Breaking Changes
1717

1818
* Migrated to PathKit for url filters. The dirname will return '.' for a filename without base directory.
19-
[Rahul Katariya](https://github.com/RahulKatariya)
19+
[Rahul Katariya](https://github.com/RahulKatariya)
20+
[Philip Jander](https://github.com/janderit)
2021
[#94](https://github.com/SwiftGen/StencilSwiftKit/pull/94)
2122

2223
### New Features
@@ -39,6 +40,9 @@
3940
* Update to SwiftLint 0.27 and enable some extra SwiftLint rules.
4041
[David Jennes](https://github.com/djbe)
4142
[#96](https://github.com/SwiftGen/StencilSwiftKit/pull/96)
43+
* Test Linux SPM support in CI.
44+
[David Jennes](https://github.com/janderit)
45+
[#90](https://github.com/SwiftGen/StencilSwiftKit/pull/90)
4246

4347
## 2.5.0
4448

Package.swift

+22-25
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@
22
import PackageDescription
33

44
let package = Package(
5-
name: "StencilSwiftKit",
6-
products: [
7-
.library(name: "StencilSwiftKit", targets: ["StencilSwiftKit"])
8-
],
9-
dependencies: [
10-
.package(url: "https://github.com/stencilproject/Stencil.git", .upToNextMinor(from: "0.12.0"))
11-
],
12-
targets: [
13-
.target(
14-
name: "StencilSwiftKit",
15-
dependencies: [
16-
"Stencil"
17-
],
18-
path: "",
19-
sources: ["Sources"]
20-
),
21-
.testTarget(
22-
name: "StencilSwiftKitTests",
23-
dependencies: [
24-
"StencilSwiftKit"
25-
],
26-
path: "Tests"
27-
)
28-
],
29-
swiftLanguageVersions: [4]
5+
name: "StencilSwiftKit",
6+
products: [
7+
.library(name: "StencilSwiftKit", targets: ["StencilSwiftKit"])
8+
],
9+
dependencies: [
10+
.package(url: "https://github.com/stencilproject/Stencil.git", .upToNextMinor(from: "0.12.0"))
11+
],
12+
targets: [
13+
.target(
14+
name: "StencilSwiftKit",
15+
dependencies: [
16+
"Stencil"
17+
]
18+
),
19+
.testTarget(
20+
name: "StencilSwiftKitTests",
21+
dependencies: [
22+
"StencilSwiftKit"
23+
]
24+
)
25+
],
26+
swiftLanguageVersions: [4]
3027
)

Pods/Pods.xcodeproj/project.pbxproj

+86-86
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
## StencilSwiftTemplate
4747

48-
This framework also contains [a `StencilSwiftTemplate` class](https://github.com/SwiftGen/StencilSwiftKit/blob/master/Sources/StencilSwiftTemplate.swift#L10), which is a subclass of `Stencil.Template` dedicated to remove extra newlines when rendering the template.
48+
This framework also contains [a `StencilSwiftTemplate` class](https://github.com/SwiftGen/StencilSwiftKit/blob/master/Sources/StencilSwiftKit/StencilSwiftTemplate.swift#L10), which is a subclass of `Stencil.Template` dedicated to remove extra newlines when rendering the template.
4949

5050
Indeed, such extra newlines could otherwise be inserted in the generated output because you want your template to be well formatted, and that can end up with Stencil nodes like `{% for … %}` and `{% if … %}` be alone in some lines of your template and that would render into nothing by themselves, generating empty lines in the output.
5151

@@ -54,7 +54,7 @@ This template subclass aims to remove those lines generated by using a simple wo
5454

5555
## Stencil.Extension & swiftStencilEnvironment
5656

57-
This framework also contains [helper methods for `Stencil.Extension` and `Stencil.Environment`](https://github.com/SwiftGen/StencilSwiftKit/blob/master/Sources/Environment.swift), to easily register all the tags and filters listed above on an existing `Stencil.Extension`, as well as to easily get a `Stencil.Environment` preconfigured with both those tags & filters `Extension` and the `StencilSwiftTemplate`.
57+
This framework also contains [helper methods for `Stencil.Extension` and `Stencil.Environment`](https://github.com/SwiftGen/StencilSwiftKit/blob/master/Sources/StencilSwiftKit/Environment.swift), to easily register all the tags and filters listed above on an existing `Stencil.Extension`, as well as to easily get a `Stencil.Environment` preconfigured with both those tags & filters `Extension` and the `StencilSwiftTemplate`.
5858

5959
## Parameters
6060

Rakefile

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ CONFIGURATION = 'Debug'.freeze
1414
POD_NAME = 'StencilSwiftKit'.freeze
1515
MIN_XCODE_VERSION = 9.2
1616

17+
## [ Generate SPM files ] #####################################################
18+
19+
namespace :spm do
20+
desc 'Generate the tests manifest for SPM'
21+
task :generate_test_manifests do |task|
22+
File.delete("Tests/#{WORKSPACE}Tests/XCTestManifests.swift")
23+
Utils.run('swift test --generate-linuxmain', task, xcrun: true)
24+
end
25+
end
26+
1727
## [ Release a new version ] ##################################################
1828

1929
namespace :release do

Scripts/SwiftLint.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ SWIFTLINT="${PROJECT_DIR}/Pods/SwiftLint/swiftlint"
55
CONFIG="${PROJECT_DIR}/.swiftlint.yml"
66

77
# possible paths
8-
paths_sources="Sources"
9-
paths_tests="Tests"
8+
paths_sources="Sources/StencilSwiftKit"
9+
paths_tests="Tests/StencilSwiftKitTests"
1010

1111
# load selected group
1212
if [ $# -gt 0 ]; then
File renamed without changes.
File renamed without changes.

Sources/Filters+Strings.swift renamed to Sources/StencilSwiftKit/Filters+Strings.swift

+8
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,15 @@ extension Filters.Strings {
305305
/// - Throws: FilterError.invalidInputType if the value parameter isn't a string
306306
static func dirname(_ value: Any?) throws -> Any? {
307307
let string = try Filters.parseString(from: value)
308+
#if os(Linux)
309+
var result = NSString(string: string).deletingLastPathComponent
310+
if result.isEmpty {
311+
result = "."
312+
}
313+
return result
314+
#else
308315
return Path(string).parent().normalize().string
316+
#endif
309317
}
310318

311319
/// Removes newlines and other whitespace from a string. Takes an optional Mode argument:

Sources/Filters.swift renamed to Sources/StencilSwiftKit/Filters.swift

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ enum Filters {
2828
if let string = value as? String {
2929
return string
3030
}
31+
#if os(Linux)
32+
if let string = value as? NSString {
33+
return String(describing: string)
34+
}
35+
#endif
36+
3137
throw Error.invalidInputType
3238
}
3339

File renamed without changes.
File renamed without changes.
File renamed without changes.

Tests/LinuxMain.swift

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import XCTest
2+
3+
import StencilSwiftKitTests
4+
5+
var tests = [XCTestCaseEntry]()
6+
tests += StencilSwiftKitTests.__allTests()
7+
8+
XCTMain(tests)

0 commit comments

Comments
 (0)