Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: set up tuist #523

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,13 @@ jobs:
runs-on: macos-14-xlarge

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2

- name: Read env
run: cat .github/workflows/env.properties >> $GITHUB_ENV
- name: Run swiftformat
run: swiftformat --lint .

- name: Switch to Xcode ${{ env.xcode_version }}
run: sudo xcode-select -s /Applications/Xcode_${{ env.xcode_version }}.app

- name: Cache SPM build
uses: actions/cache@v2
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-

- name: Run SwiftFormat
run: |
swift run -c release swiftformat --lint .

- name: Report error
if: ${{ failure() }}
run: |
echo '::error::SwiftFormat linting failed. Run `Scripts/swiftformat` to format your code.'
- name: Report error
if: ${{ failure() }}
run: |
echo '::error::SwiftFormat linting failed. Run `Scripts/swiftformat` to format your code.'
53 changes: 19 additions & 34 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@ jobs:

runs-on: macos-14-xlarge

env:
TUIST_TEST_DEVICE: iPhone SE (3rd generation)
TUIST_TEST_PLATFORM: iOS

strategy:
fail-fast: false # Don’t fail-fast so that we get all snapshot test changes
matrix:
include:
- sdk: "15.4"
destination: platform=iOS Simulator,OS=15.4,name=iPhone SE (3rd generation)
simctl_runtime: "com.apple.CoreSimulator.SimRuntime.iOS-15-4"
installation_required: true

- sdk: "16.2"
destination: platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)
simctl_runtime: "com.apple.CoreSimulator.SimRuntime.iOS-16-2"
installation_required: true

- sdk: "17.2"
destination: platform=iOS Simulator,OS=17.2,name=iPhone SE (3rd generation)
simctl_runtime: "com.apple.CoreSimulator.SimRuntime.iOS-17-2"
# The iOS 17.2 SDK is pre-installed on the macOS 13 image.
# Attempting to install it will fail with an error.
installation_required: false

steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2

- name: Read env
run: cat .github/workflows/env.properties >> $GITHUB_ENV
Expand All @@ -46,9 +51,18 @@ jobs:
if: ${{ matrix.installation_required }}
run: sudo xcodes runtimes install "iOS ${{ matrix.sdk }}"

- name: Build & Test
- name: Ensure sim exists
run: |
xcodebuild -scheme "BlueprintUI-Package" -destination "${{ matrix.destination }}" build test
xcrun simctl create \
"${{ env.TUIST_TEST_DEVICE }}" \
"${{ env.TUIST_TEST_DEVICE }}" \
"${{ matrix.simctl_runtime }}"

- name: Install dependencies
run: tuist install --path SampleApp

- name: Build & Test
run: tuist test --path SampleApp --os ${{ matrix.sdk }} UnitTests

- name: Package snapshot changes
if: ${{ failure() }}
Expand All @@ -61,32 +75,3 @@ jobs:
with:
name: snapshot_changes_${{ matrix.sdk }}
path: snapshot_changes_${{ matrix.sdk }}.tar


cocoapods:
name: "CocoaPods"

runs-on: macos-14-xlarge

steps:
- uses: actions/checkout@v4

- name: Read env
run: cat .github/workflows/env.properties >> $GITHUB_ENV

- name: Switch to Xcode ${{ env.xcode_version }}
run: sudo xcode-select -s /Applications/Xcode_${{ env.xcode_version }}.app

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
# Uses version specified in .ruby_version
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Pod Install
run: |
bundle exec pod install --project-directory=SampleApp/

- name: Build & Test
run: |
xcodebuild -workspace SampleApp/SampleApp.xcworkspace -scheme "BlueprintUI-Unit-Tests" -destination "platform=iOS Simulator,OS=17.2,name=iPhone SE (3rd generation)"
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ Pods/
# .swiftpm/

.build/
BlueprintUI.xcodeproj/

# jazzy
.docs/

# User settings
.vscode/

# Tuist
/Derived
/*.xcodeproj
/*.xcworkspace
/SampleApp/Derived
/SampleApp/*.xcodeproj
/SampleApp/*.xcworkspace
14 changes: 10 additions & 4 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ if [[ $(git rev-parse -q --verify MERGE_HEAD) ]]; then
exit 0
fi

git diff --diff-filter=d --staged --name-only | grep -e ".swift$" | while read file; do
swift run -c release swiftformat "${file}";
git add "$file";
done
ROOT="$(git rev-parse --show-toplevel)"
SWIFT_FORMAT="mise x -- swiftformat"
GIT_FORMAT_STAGED="$ROOT/Scripts/git-format-staged"
CONFIG="${ROOT}/.swiftformat"

$SWIFT_FORMAT --version 1>/dev/null 2>&1
if [ $? -eq 0 ]
then
$GIT_FORMAT_STAGED --formatter "$SWIFT_FORMAT stdin --config "$CONFIG" --stdinpath '{}'" "*.swift"
fi
7 changes: 7 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tools]
tuist = "4.23.0"
swiftformat = "0.54.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It'd be much easier to review this (and compare with other Mise migrations) if we stuck to the existing Swiftformat version and reverted the formatting changes.

Or if we are going to bump it let's go to the latest.


[settings]
# do not try to read versions from .nvmrc, .ruby-version, etc.
legacy_version_file = false
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public struct TextAttributeContainer {
public subscript<Key>(key: Key.Type) -> Key.Value? where Key: AttributedTextKey {
get {
if let value = storage[key.name] as? Key.Value {
return value
value
} else {
return nil
nil
}
}
set {
Expand Down
8 changes: 4 additions & 4 deletions BlueprintUI/Sources/BlueprintView/BlueprintView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ public final class BlueprintView: UIView {

func constraint() -> SizeConstraint {
if bounds.width == 0 {
return .unconstrained
.unconstrained
} else {
return .init(width: bounds.width)
.init(width: bounds.width)
}
}

Expand Down Expand Up @@ -517,9 +517,9 @@ public final class BlueprintView: UIView {
self.automaticallyInheritsEnvironmentFromContainingBlueprintViews,
let inherited = self.inheritedBlueprintEnvironment
{
return inherited
inherited
} else {
return .empty
.empty
}
}()

Expand Down
12 changes: 6 additions & 6 deletions BlueprintUI/Sources/BlueprintView/ElementPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public struct ElementPreview: View {
// MARK: View

public var body: some View {
ForEach(self.previewTypes, id: \.identifier) { previewType in
ForEach(previewTypes, id: \.identifier) { previewType in
previewType.previewView(
with: self.name,
for: self.provider()
with: name,
for: provider()
)
}
}
Expand Down Expand Up @@ -180,9 +180,9 @@ extension ElementPreview {

public var identifier: AnyHashable {
switch self {
case .device(let device): return device.rawValue
case .fixed(let width, let height): return "(\(width), \(height))"
case .thatFits(let padding): return "thatFits (\(padding)"
case .device(let device): device.rawValue
case .fixed(let width, let height): "(\(width), \(height))"
case .thatFits(let padding): "thatFits (\(padding)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion BlueprintUI/Sources/Environment/AdaptedEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct AdaptedEnvironment: Element {
ElementContent(
child: wrapped,
environment: { env in
for adapter in self.adapters.reversed() {
for adapter in adapters.reversed() {
adapter(&env)
}
}
Expand Down
6 changes: 3 additions & 3 deletions BlueprintUI/Sources/Environment/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ extension UIView {
/// If no views in the superview hierarchy are managed by Blueprint, this property returns nil.
var inheritedBlueprintEnvironment: Environment? {
if let environment = nativeViewNodeBlueprintEnvironment {
return environment
environment
} else if let superview = superview {
return superview.inheritedBlueprintEnvironment
superview.inheritedBlueprintEnvironment
} else {
return nil
nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion BlueprintUI/Sources/Environment/EnvironmentReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct EnvironmentReader: Element {

public var content: ElementContent {
ElementContent { _, environment in
self.elementRepresentation(environment)
elementRepresentation(environment)
}
}

Expand Down
2 changes: 1 addition & 1 deletion BlueprintUI/Sources/Focus/FocusState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ extension FocusState {
},
onBlur: { [weak self] in
if let self = self, self.value == value {
self.value = self.defaultValue
self.value = defaultValue
}
}
)
Expand Down
4 changes: 2 additions & 2 deletions BlueprintUI/Sources/Internal/ElementIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ struct ElementIdentifier: Hashable, CustomStringConvertible {

var description: String {
if let key = key {
return "\(elementType).\(key).\(count)"
"\(elementType).\(key).\(count)"
} else {
return "\(elementType).\(count)"
"\(elementType).\(count)"
}
}

Expand Down
4 changes: 2 additions & 2 deletions BlueprintUI/Sources/Internal/LayoutResultNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ extension Element {
func layout(frame: CGRect, environment: Environment, layoutMode: LayoutMode) -> LayoutResultNode {
switch layoutMode {
case .legacy:
return legacyLayout(
legacyLayout(
layoutAttributes: LayoutAttributes(frame: frame),
environment: environment
)

case .caffeinated(let options):
return caffeinatedLayout(
caffeinatedLayout(
frame: frame,
environment: environment,
node: LayoutTreeNode(
Expand Down
4 changes: 2 additions & 2 deletions BlueprintUI/Sources/Layout/Column.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public struct Column: StackElement {
var stackAlignment: StackLayout.Alignment {
switch self {
case .fill:
return .fill
.fill
case let .align(to: alignment):
return .align(to: alignment.id)
.align(to: alignment.id)
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions BlueprintUI/Sources/Layout/Conditionals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ extension Element {
then: (Self) -> Element
) -> Element {
if isTrue {
return then(self)
then(self)
} else {
return self
self
}
}

Expand All @@ -43,9 +43,9 @@ extension Element {
else: (Self) -> Element
) -> Element {
if isTrue {
return then(self)
then(self)
} else {
return `else`(self)
`else`(self)
}
}

Expand All @@ -66,9 +66,9 @@ extension Element {
then: (Value, Self) -> Element
) -> Element {
if let value = value {
return then(value, self)
then(value, self)
} else {
return self
self
}
}

Expand All @@ -92,9 +92,9 @@ extension Element {
else: (Self) -> Element
) -> Element {
if let value = value {
return then(value, self)
then(value, self)
} else {
return `else`(self)
`else`(self)
}
}

Expand Down
Loading
Loading