Skip to content

Commit

Permalink
Merge pull request #90 from janderit/LinuxCompatibility
Browse files Browse the repository at this point in the history
Linux testing on CI
  • Loading branch information
djbe authored Aug 29, 2018
2 parents 2aa6ff1 + 22ead52 commit bb70145
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 127 deletions.
39 changes: 31 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defaults:
- &default-config
- &macos-config
parallelism: 1
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
Expand All @@ -8,6 +8,14 @@ defaults:
macos:
xcode: "9.3.0"
shell: /bin/bash --login -eo pipefail
- &linux-config
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
BUNDLE_PATH: vendor/bundle
docker:
- image: norionomura/jazzy:swift-4.1.3
shell: /bin/bash --login -eo pipefail
- &prepare-storage
run:
name: Create directories for artifacts and reports
Expand Down Expand Up @@ -41,7 +49,7 @@ defaults:
version: 2
jobs:
lint:
<<: *default-config
<<: *macos-config
steps:
- *prepare-storage
- checkout
Expand All @@ -57,7 +65,7 @@ jobs:
- *store-artifacts

xcode-build-and-test:
<<: *default-config
<<: *macos-config
steps:
- *prepare-storage
- checkout
Expand All @@ -72,8 +80,21 @@ jobs:
- *fetch-xcode-logs
- *store-artifacts

spm-build-and-test:
<<: *default-config
spm-linux-build-and-test:
<<: *linux-config
steps:
- *prepare-storage
- checkout
- *restore-gems
- *install-gems
- *store-gems
- run:
name: Run all tests
command: bundle exec rake spm:test
- *store-artifacts

spm-mac-build-and-test:
<<: *macos-config
steps:
- *prepare-storage
- checkout
Expand All @@ -86,7 +107,7 @@ jobs:
- *store-artifacts

check-deploy:
<<: *default-config
<<: *macos-config
steps:
- *prepare-storage
- checkout
Expand All @@ -107,10 +128,12 @@ workflows:
lint-buildandtest-checkdeploy:
jobs:
- lint
- spm-build-and-test
- spm-linux-build-and-test
- spm-mac-build-and-test
- xcode-build-and-test
- check-deploy:
requires:
- lint
- spm-build-and-test
- spm-linux-build-and-test
- spm-mac-build-and-test
- xcode-build-and-test
4 changes: 4 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ line_length:
nesting:
type_level:
warning: 2

# Exclude generated files
excluded:
- XCTestManifests.swift
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
### Breaking Changes

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

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

## 2.5.0

Expand Down
47 changes: 22 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@
import PackageDescription

let package = Package(
name: "StencilSwiftKit",
products: [
.library(name: "StencilSwiftKit", targets: ["StencilSwiftKit"])
],
dependencies: [
.package(url: "https://github.com/stencilproject/Stencil.git", .upToNextMinor(from: "0.12.0"))
],
targets: [
.target(
name: "StencilSwiftKit",
dependencies: [
"Stencil"
],
path: "",
sources: ["Sources"]
),
.testTarget(
name: "StencilSwiftKitTests",
dependencies: [
"StencilSwiftKit"
],
path: "Tests"
)
],
swiftLanguageVersions: [4]
name: "StencilSwiftKit",
products: [
.library(name: "StencilSwiftKit", targets: ["StencilSwiftKit"])
],
dependencies: [
.package(url: "https://github.com/stencilproject/Stencil.git", .upToNextMinor(from: "0.12.0"))
],
targets: [
.target(
name: "StencilSwiftKit",
dependencies: [
"Stencil"
]
),
.testTarget(
name: "StencilSwiftKitTests",
dependencies: [
"StencilSwiftKit"
]
)
],
swiftLanguageVersions: [4]
)
172 changes: 86 additions & 86 deletions Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

## StencilSwiftTemplate

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

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.

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

## Stencil.Extension & swiftStencilEnvironment

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`.
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`.

## Parameters

Expand Down
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ CONFIGURATION = 'Debug'.freeze
POD_NAME = 'StencilSwiftKit'.freeze
MIN_XCODE_VERSION = 9.2

## [ Generate SPM files ] #####################################################

namespace :spm do
desc 'Generate the tests manifest for SPM'
task :generate_test_manifests do |task|
File.delete("Tests/#{WORKSPACE}Tests/XCTestManifests.swift")
Utils.run('swift test --generate-linuxmain', task, xcrun: true)
end
end

## [ Release a new version ] ##################################################

namespace :release do
Expand Down
4 changes: 2 additions & 2 deletions Scripts/SwiftLint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ SWIFTLINT="${PROJECT_DIR}/Pods/SwiftLint/swiftlint"
CONFIG="${PROJECT_DIR}/.swiftlint.yml"

# possible paths
paths_sources="Sources"
paths_tests="Tests"
paths_sources="Sources/StencilSwiftKit"
paths_tests="Tests/StencilSwiftKitTests"

# load selected group
if [ $# -gt 0 ]; then
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,15 @@ extension Filters.Strings {
/// - Throws: FilterError.invalidInputType if the value parameter isn't a string
static func dirname(_ value: Any?) throws -> Any? {
let string = try Filters.parseString(from: value)
#if os(Linux)
var result = NSString(string: string).deletingLastPathComponent
if result.isEmpty {
result = "."
}
return result
#else
return Path(string).parent().normalize().string
#endif
}

/// Removes newlines and other whitespace from a string. Takes an optional Mode argument:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ enum Filters {
if let string = value as? String {
return string
}
#if os(Linux)
if let string = value as? NSString {
return String(describing: string)
}
#endif

throw Error.invalidInputType
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import XCTest

import StencilSwiftKitTests

var tests = [XCTestCaseEntry]()
tests += StencilSwiftKitTests.__allTests()

XCTMain(tests)
Loading

0 comments on commit bb70145

Please sign in to comment.