Skip to content

Commit

Permalink
Merge branch 'master' into rebuild-playbook-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed May 16, 2024
2 parents 40109a7 + 01deab5 commit ac97e5c
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 45 deletions.
24 changes: 10 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Get SwiftPM cache
uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: .build
key: ${{ runner.os }}-1-spm-${{ hashFiles('Package.resolved') }}
restore-keys: ${{ runner.os }}-1-spm
path: Tools/bin
key: spm-${{ runner.os }}-${{env.DEVELOPER_DIR}}-${{ hashFiles('Tools/Package.swift') }}

- name: Validate lint
run: make lint

- name: Validate format
run: |
make format
if [ -n "$(git status --porcelain)" ]; then echo "Make sure that the code is formated by 'make format'."; exit 1; fi
make lint
env:
SPM_FORCE_BUILD: 1
if [ -n "$(git status --porcelain)" ]; then git diff && echo "Make sure that the code is formated by 'make format'."; exit 1; fi
- name: Validate example project
- name: Validate projects
run: |
make proj
if [ -n "$(git status --porcelain)" ]; then echo "Make sure that example project is formated by 'make proj'."; exit 1; fi
env:
SPM_FORCE_BUILD: 1
if [ -n "$(git status --porcelain)" ]; then git diff && echo "Make sure that projects are formated by 'make proj'."; exit 1; fi
test:
name: Test on macOS
Expand All @@ -52,7 +48,7 @@ jobs:
- name: Get npm cache
id: npm-cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-0-npm-${{ hashFiles('package-lock.json') }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ node_modules
## SwiftPM
.swiftpm
.build
bin

## Snapshot test
Snapshots
Expand Down
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
TOOL := PLAYBOOK_DEVELOPMENT=1 swift run -c release
GITHUB_RAW_CONTENT_PATH := https://raw.githubusercontent.com/playbook-ui/playbook-ios/master/
GITHUB_TREE_PATH := https://github.com/playbook-ui/playbook-ios/tree/master/
LIBS := "Playbook" "PlaybookUI" "PlaybookSnapshot"
TOOL = scripts/swift-run.sh
GITHUB_RAW_CONTENT_PATH = https://raw.githubusercontent.com/playbook-ui/playbook-ios/master/
GITHUB_TREE_PATH = https://github.com/playbook-ui/playbook-ios/tree/master/
LIBS = "Playbook" "PlaybookUI" "PlaybookSnapshot"
XCODE_GEN_RESOURCES = .build/checkouts/XcodeGen/SettingPresets

.PHONY: proj
proj:
$(TOOL) xcodegen
$(TOOL) xcodegen --spec Example/project.yml --project Example
SWIFT_PACKAGE_RESOURCES=$(XCODE_GEN_RESOURCES) $(TOOL) xcodegen
SWIFT_PACKAGE_RESOURCES=$(XCODE_GEN_RESOURCES) $(TOOL) xcodegen --spec Example/project.yml --project Example

.PHONY: format
format:
$(TOOL) swift-format format -i -p -r Sources Tests Example/SamplePlaybook Example/SampleSnapshot
$(TOOL) swift-format format -i -p -r Sources Tests Example/SamplePlaybook Example/SampleSnapshot Package.swift Tools/Package.swift

.PHONY: lint
lint:
Expand Down
12 changes: 1 addition & 11 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// swift-tools-version:5.9

import Foundation
import PackageDescription

let package = Package(
Expand All @@ -24,16 +23,7 @@ let package = Package(
.target(
name: "PlaybookUI",
dependencies: ["Playbook"]
)
),
],
swiftLanguageVersions: [.v5]
)

if ProcessInfo.processInfo.environment["PLAYBOOK_DEVELOPMENT"] != nil {
package.dependencies.append(contentsOf: [
.package(url: "https://github.com/apple/swift-format.git", exact: "509.0.0"),
.package(url: "https://github.com/yonaskolb/XcodeGen.git", exact: "2.38.0"),
// XcodeGen fails to build with newer version of XcodeProj
.package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.15.0"),
])
}
26 changes: 25 additions & 1 deletion Sources/Playbook/SnapshotSupport/SnapshotSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,31 @@ private extension SnapshotSupport {
let actions: UIGraphicsDrawingActions = { context in
withoutAnimation {
if isEmbedInKeyWindow {
snapshotView.drawHierarchy(in: snapshotView.bounds, afterScreenUpdates: true)
let nativeScale = UIScreen.main.nativeScale
let size = snapshotView.bounds.size
let nativeScaledSize = CGSize(
width: size.width * nativeScale,
height: size.height * nativeScale
)
let sizeLimit: CGFloat = 8192
let limitedScale = max(nativeScaledSize.width / sizeLimit, nativeScaledSize.height / sizeLimit)

if limitedScale > 1 {
// `UIView.drawHierarchy` seems to have an internal hard-coded limit size of 8192x8192,
// and specifying a size beyond that resulting in an empty image is drawn.
let limitedRect = CGRect(
x: .zero,
y: .zero,
width: size.width / limitedScale,
height: size.height / limitedScale
)
context.cgContext.scaleBy(x: limitedScale, y: limitedScale)
snapshotView.drawHierarchy(in: limitedRect, afterScreenUpdates: true)
}
else {
snapshotView.drawHierarchy(in: snapshotView.bounds, afterScreenUpdates: true)
}

snapshotView.removeFromSuperview()
}
else {
Expand Down
8 changes: 7 additions & 1 deletion Tests/ExtraScenarios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import SwiftUI

enum ExtraScenarios: ScenarioProvider {
static func addScenarios(into playbook: Playbook) {
playbook.addScenarios(of: "Extra") {
Scenario("Over internal size limitation 8192x8192", layout: .fixed(width: 10000, height: 10000)) {
Color.red.edgesIgnoringSafeArea(.all)
}
}

playbook.addScenarios(of: "Normalizable\u{7FFFF}\u{1D} \n.:/") {
Scenario("Normalizable\u{7FFFF}\u{1D} \n.:/", layout: .fixed(length: 300)) {
Color(.systemBlue).edgesIgnoringSafeArea(.all)
Color.blue.edgesIgnoringSafeArea(.all)
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions Package.resolved → Tools/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Rainbow.git",
"state" : {
"revision" : "626c3d4b6b55354b4af3aa309f998fae9b31a3d9",
"version" : "3.2.0"
"revision" : "e0dada9cd44e3fa7ec3b867e49a8ddbf543e3df3",
"version" : "4.0.1"
}
},
{
Expand All @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
}
},
{
Expand Down Expand Up @@ -93,7 +93,7 @@
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
Expand Down Expand Up @@ -122,26 +122,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/yonaskolb/XcodeGen.git",
"state" : {
"revision" : "87a275fb0852bb231550e66473804de57063c957",
"version" : "2.38.0"
"revision" : "9816466703aede482c7436fddc6535684a7a9168",
"version" : "2.40.1"
}
},
{
"identity" : "xcodeproj",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/XcodeProj.git",
"state" : {
"revision" : "3797181813ee963fe305d939232bc576d23ddbb0",
"version" : "8.15.0"
"revision" : "6e60fb55271c80f83a186c9b1b4982fd991cfc0a",
"version" : "8.13.0"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3",
"version" : "5.0.6"
"revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76",
"version" : "5.1.2"
}
}
],
Expand Down
11 changes: 11 additions & 0 deletions Tools/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "dev-tools",
dependencies: [
.package(url: "https://github.com/apple/swift-format.git", exact: "509.0.0"),
.package(url: "https://github.com/yonaskolb/XcodeGen.git", exact: "2.40.1"),
]
)
40 changes: 40 additions & 0 deletions scripts/swift-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -eu

function swift_build() {
swift build -c release --package-path Tools $@
}

PACKAGE=$1
ARGS=${@:2}
BASE_DIR="Tools"
PACKAGE_SWIFT="$BASE_DIR/Package.swift"
BIN_DIR="$BASE_DIR/bin"
BIN="$BIN_DIR/$PACKAGE"
CHECKSUM_FILE="$BIN.checksum"

pushd "$(cd $(dirname $0)/.. && pwd)" &>/dev/null

swift_version="$(swift --version 2>/dev/null | head -n 1)"
swift_version_hash=$(echo $swift_version | md5 -q)
package_hash=$(md5 -q $PACKAGE_SWIFT)
checksum=$(echo $swift_version_hash $package_hash | md5 -q)

echo "CHECKSUM: $checksum"

if [[ ! -f $BIN || $checksum != $(cat $CHECKSUM_FILE 2>/dev/null) ]]; then
echo "Building..."
swift_build --product $PACKAGE
mkdir -p $BIN_DIR
mv -f $(swift_build --show-bin-path)/$PACKAGE $BIN

if [[ -e ${SWIFT_PACKAGE_RESOURCES:-} ]]; then
echo "Copying $SWIFT_PACKAGE_RESOURCES..."
cp -Rf $SWIFT_PACKAGE_RESOURCES $BIN_DIR
fi

echo "$checksum" >"$CHECKSUM_FILE"
fi

$BIN $ARGS

0 comments on commit ac97e5c

Please sign in to comment.