Skip to content

Commit

Permalink
Setup CI (#1)
Browse files Browse the repository at this point in the history
* Setup CI

* Add compiler checks

* Bump watchOS version

* Fix build

* Placeholder docs

* Bump tvOS

* Fix build

* Fix

* Update snapshots

* Specify Xcode version

* Cleanup

* Update snapshots

* Disable tests
  • Loading branch information
raymondjavaxx committed Aug 4, 2023
1 parent e0f1290 commit 11613c3
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 30 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build
on:
push:
branches:
- 'main'
paths:
- '.github/workflows/build.yml'
- '**.swift'
pull_request:
paths:
- '.github/workflows/build.yml'
- '**.swift'
concurrency:
group: build-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-macos:
name: Build macOS
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.3.1'
- name: Run tests
run: swift test -v
build-other-platforms:
runs-on: macos-13
name: Build ${{ matrix.destination.name }}
strategy:
matrix:
destination:
-
name: iOS
value: "platform=iOS Simulator,name=iPhone 14,OS=latest"
-
name: tvOS
value: "platform=tvOS Simulator,name=Apple TV,OS=latest"
-
name: watchOS
value: "platform=watchOS Simulator,name=Apple Watch Series 8 (41mm),OS=latest"
steps:
- uses: actions/checkout@v3
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.3.1'
- name: Build
run: |-
set -o pipefail && NSUnbufferedIO=YES xcodebuild clean build \
-scheme SmoothGradient \
-destination '${{ matrix.destination.value }}' \
| xcpretty
# - name: Run tests
# run: |-
# set -o pipefail && NSUnbufferedIO=YES xcodebuild test \
# -scheme SmoothGradient \
# -destination '${{ matrix.destination.value }}' \
# -sdk iphonesimulator \
# | xcpretty
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint
on:
pull_request:
paths:
- '.github/workflows/lint.yml'
- '.swiftlint.yml'
- '**/*.swift'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: SwiftLint
uses: norio-nomura/[email protected]
with:
args: --strict
- name: SPM
run: swift package dump-package
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ opt_in_rules:
- identical_operands
- implicit_return
- implicitly_unwrapped_optional
- missing_docs
# - missing_docs
- number_separator
- operator_usage_whitespace
- overridden_super_call
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ let package = Package(
.iOS(.v15),
.macOS(.v11),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v6)
.tvOS(.v14),
.watchOS(.v7)
],
products: [
.library(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmoothGradient/CubicBezierCurve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension CubicBezierCurve {

// MARK: - Preview

@available(macOS 12.0, *)
@available(iOS 13.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct CubicBezierCurve_Previews: PreviewProvider {
static var previews: some View {
Canvas(opaque: true) { context, size in
Expand Down
2 changes: 2 additions & 0 deletions Sources/SmoothGradient/Curve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ protocol Curve {
func value(at progress: Double) -> Double
}

#if compiler(>=5.9)
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
extension UnitCurve: Curve {}
#endif
67 changes: 44 additions & 23 deletions Sources/SmoothGradient/Gradient+Smooth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ import SwiftUI

// MARK: - iOS 17

#if compiler(>=5.9)
extension Gradient {
// Creates a gradient with the given easing function.
//
// - Parameters:
// - from: The start color.
// - to: The end color.
// - curve: The easing function to use.
// - steps: The number of steps to use when generating the gradient. Defaults to 16.
// - Returns: A gradient.
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
public static func smooth(
from: Color,
Expand All @@ -28,6 +37,14 @@ extension Gradient {
)
}

// Creates a gradient with the given easing function.
//
// - Parameters:
// - from: The start color.
// - to: The end color.
// - curve: The easing function to use.
// - steps: The number of steps to use when generating the gradient. Defaults to 16.
// - Returns: A gradient.
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
public static func smooth(
from: Stop,
Expand All @@ -43,10 +60,19 @@ extension Gradient {
)
}
}
#endif

// MARK: - Pre iOS 17

extension Gradient {
// Creates a gradient with the given easing function.
//
// - Parameters:
// - from: The start color.
// - to: The end color.
// - curve: The easing function to use.
// - steps: The number of steps to use when generating the gradient. Defaults to 16.
// - Returns: A gradient.
@available(iOS, introduced: 13.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)")
@available(macOS, introduced: 10.15, deprecated: 14.0, renamed: "smooth(from:to:curve:steps:)")
@available(tvOS, introduced: 13.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)")
Expand All @@ -66,6 +92,14 @@ extension Gradient {
)
}

// Creates a gradient with the given easing function.
//
// - Parameters:
// - from: The start color.
// - to: The end color.
// - curve: The easing function to use.
// - steps: The number of steps to use when generating the gradient. Defaults to 16.
// - Returns: A gradient.
@available(iOS, introduced: 13.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)")
@available(macOS, introduced: 10.15, deprecated: 14.0, renamed: "smooth(from:to:curve:steps:)")
@available(tvOS, introduced: 13.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)")
Expand Down Expand Up @@ -119,29 +153,16 @@ extension Gradient {
struct Gradient_Previews: PreviewProvider {
static var previews: some View {
VStack {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
LinearGradient(
gradient: .smooth(
from: .black,
to: .black.opacity(0),
curve: .easeInOut
),
startPoint: .top,
endPoint: .bottom
)
.frame(height: 200)
} else {
LinearGradient(
gradient: .smooth(
from: .black,
to: .black.opacity(0),
easing: .easeInOut
),
startPoint: .top,
endPoint: .bottom
)
.frame(height: 200)
}
LinearGradient(
gradient: .smooth(
from: .black,
to: .black.opacity(0),
easing: .easeInOut
),
startPoint: .top,
endPoint: .bottom
)
.frame(height: 200)
Spacer()
}
.background(Color.white, alignment: .center)
Expand Down
2 changes: 2 additions & 0 deletions Sources/SmoothGradient/SmoothLinearGradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import SwiftUI

#if compiler(>=5.9)
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
public struct SmoothLinearGradient: ShapeStyle, View {
let from: Gradient.Stop
Expand Down Expand Up @@ -86,3 +87,4 @@ struct SmoothLinearGradient_Previews: PreviewProvider {
.previewDisplayName("Stops")
}
}
#endif
7 changes: 5 additions & 2 deletions Tests/SmoothGradientTests/GradientSmoothTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SwiftUI
import SnapshotTesting
import SmoothGradient

#if os(iOS) || os(tvOS)
#if os(iOS)
final class GradientSmoothTests: XCTestCase {
func test_easing_easeInOut() throws {
verify(
Expand Down Expand Up @@ -46,6 +46,7 @@ final class GradientSmoothTests: XCTestCase {

@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
extension GradientSmoothTests {
#if compiler(>=5.9)
func test_curve_easeInOut() throws {
verify(
.smooth(from: .black, to: .black.opacity(0), curve: .easeInOut)
Expand Down Expand Up @@ -73,6 +74,7 @@ extension GradientSmoothTests {
)
)
}
#endif
}

extension GradientSmoothTests {
Expand All @@ -83,8 +85,9 @@ extension GradientSmoothTests {
line: UInt = #line
) {
let rectangle = Rectangle()
.foregroundColor(.clear)
.frame(width: 256, height: 256)
.foregroundStyle(
.background(
LinearGradient(
gradient: gradient,
startPoint: .top,
Expand Down
4 changes: 3 additions & 1 deletion Tests/SmoothGradientTests/SmoothLinearGradientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import SwiftUI
import SnapshotTesting
import SmoothGradient

#if os(iOS) || os(tvOS)
#if compiler(>=5.9)
#if os(iOS)
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
final class SmoothLinearGradientTests: XCTestCase {
func test_horizontal() {
Expand Down Expand Up @@ -64,3 +65,4 @@ extension SmoothLinearGradientTests {
}
}
#endif
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 11613c3

Please sign in to comment.