diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 643239a..6a9134f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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') }} diff --git a/.gitignore b/.gitignore index 953464c..e8b4a1e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ node_modules ## SwiftPM .swiftpm .build +bin ## Snapshot test Snapshots diff --git a/Makefile b/Makefile index c43853f..d5b3349 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/Package.swift b/Package.swift index aadc96e..b219fb9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,6 +1,5 @@ // swift-tools-version:5.9 -import Foundation import PackageDescription let package = Package( @@ -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"), - ]) -} diff --git a/Package.resolved b/Tools/Package.resolved similarity index 87% rename from Package.resolved rename to Tools/Package.resolved index 575e93e..91073dd 100644 --- a/Package.resolved +++ b/Tools/Package.resolved @@ -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" } }, { @@ -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" } }, { @@ -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" @@ -122,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/yonaskolb/XcodeGen.git", "state" : { - "revision" : "87a275fb0852bb231550e66473804de57063c957", - "version" : "2.38.0" + "revision" : "9816466703aede482c7436fddc6535684a7a9168", + "version" : "2.40.1" } }, { @@ -131,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tuist/XcodeProj.git", "state" : { - "revision" : "3797181813ee963fe305d939232bc576d23ddbb0", - "version" : "8.15.0" + "revision" : "6e60fb55271c80f83a186c9b1b4982fd991cfc0a", + "version" : "8.13.0" } }, { @@ -140,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/jpsim/Yams.git", "state" : { - "revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3", - "version" : "5.0.6" + "revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76", + "version" : "5.1.2" } } ], diff --git a/Tools/Package.swift b/Tools/Package.swift new file mode 100644 index 0000000..bd1f86c --- /dev/null +++ b/Tools/Package.swift @@ -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"), + ] +) diff --git a/scripts/swift-run.sh b/scripts/swift-run.sh new file mode 100755 index 0000000..0bf8a53 --- /dev/null +++ b/scripts/swift-run.sh @@ -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