From b1e7620ae5638fd2d1344ec52350b70a6b863406 Mon Sep 17 00:00:00 2001 From: ra1028 Date: Thu, 16 May 2024 16:03:41 +0900 Subject: [PATCH 1/3] Restructure tool installation --- .github/workflows/test.yml | 23 +++--- .gitignore | 1 + Makefile | 15 ++-- Package.swift | 12 +-- Tools/Package.resolved | 149 +++++++++++++++++++++++++++++++++++++ Tools/Package.swift | 11 +++ scripts/swift-run.sh | 40 ++++++++++ 7 files changed, 219 insertions(+), 32 deletions(-) create mode 100644 Tools/Package.resolved create mode 100644 Tools/Package.swift create mode 100755 scripts/swift-run.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 643239a..862ad38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,27 +16,22 @@ 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 +47,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/Tools/Package.resolved b/Tools/Package.resolved new file mode 100644 index 0000000..91073dd --- /dev/null +++ b/Tools/Package.resolved @@ -0,0 +1,149 @@ +{ + "pins" : [ + { + "identity" : "aexml", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tadija/AEXML.git", + "state" : { + "revision" : "38f7d00b23ecd891e1ee656fa6aeebd6ba04ecc3", + "version" : "4.6.1" + } + }, + { + "identity" : "graphviz", + "kind" : "remoteSourceControl", + "location" : "https://github.com/SwiftDocOrg/GraphViz.git", + "state" : { + "revision" : "70bebcf4597b9ce33e19816d6bbd4ba9b7bdf038", + "version" : "0.2.0" + } + }, + { + "identity" : "jsonutilities", + "kind" : "remoteSourceControl", + "location" : "https://github.com/yonaskolb/JSONUtilities.git", + "state" : { + "revision" : "128d2ffc22467f69569ef8ff971683e2393191a0", + "version" : "4.2.0" + } + }, + { + "identity" : "pathkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kylef/PathKit.git", + "state" : { + "revision" : "3bfd2737b700b9a36565a8c94f4ad2b050a5e574", + "version" : "1.0.1" + } + }, + { + "identity" : "rainbow", + "kind" : "remoteSourceControl", + "location" : "https://github.com/onevcat/Rainbow.git", + "state" : { + "revision" : "e0dada9cd44e3fa7ec3b867e49a8ddbf543e3df3", + "version" : "4.0.1" + } + }, + { + "identity" : "spectre", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kylef/Spectre.git", + "state" : { + "revision" : "26cc5e9ae0947092c7139ef7ba612e34646086c7", + "version" : "0.10.1" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser.git", + "state" : { + "revision" : "46989693916f56d1186bd59ac15124caef896560", + "version" : "1.3.1" + } + }, + { + "identity" : "swift-cmark", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-cmark.git", + "state" : { + "revision" : "f218e5d7691f78b55bfa39b367763f4612486c35", + "version" : "0.3.0" + } + }, + { + "identity" : "swift-format", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-format.git", + "state" : { + "revision" : "83248b4fa37919f78ffbd4650946759bcc54c2b5", + "version" : "509.0.0" + } + }, + { + "identity" : "swift-markdown", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-markdown.git", + "state" : { + "revision" : "e4f95e2dc23097a1a9a1dfdfe3fe3ee44de77378", + "version" : "0.3.0" + } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax.git", + "state" : { + "revision" : "64889f0c732f210a935a0ad7cda38f77f876262d", + "version" : "509.1.1" + } + }, + { + "identity" : "swiftcli", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jakeheis/SwiftCLI.git", + "state" : { + "revision" : "2e949055d9797c1a6bddcda0e58dada16cc8e970", + "version" : "6.0.3" + } + }, + { + "identity" : "version", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mxcl/Version", + "state" : { + "revision" : "1fe824b80d89201652e7eca7c9252269a1d85e25", + "version" : "2.0.1" + } + }, + { + "identity" : "xcodegen", + "kind" : "remoteSourceControl", + "location" : "https://github.com/yonaskolb/XcodeGen.git", + "state" : { + "revision" : "9816466703aede482c7436fddc6535684a7a9168", + "version" : "2.40.1" + } + }, + { + "identity" : "xcodeproj", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tuist/XcodeProj.git", + "state" : { + "revision" : "6e60fb55271c80f83a186c9b1b4982fd991cfc0a", + "version" : "8.13.0" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76", + "version" : "5.1.2" + } + } + ], + "version" : 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 From 468ab7017afab8c7e07a7c977be605aa2226cfea Mon Sep 17 00:00:00 2001 From: ra1028 Date: Thu, 16 May 2024 16:06:18 +0900 Subject: [PATCH 2/3] Remove root Package.resolved --- Package.resolved | 149 ----------------------------------------------- 1 file changed, 149 deletions(-) delete mode 100644 Package.resolved diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index 575e93e..0000000 --- a/Package.resolved +++ /dev/null @@ -1,149 +0,0 @@ -{ - "pins" : [ - { - "identity" : "aexml", - "kind" : "remoteSourceControl", - "location" : "https://github.com/tadija/AEXML.git", - "state" : { - "revision" : "38f7d00b23ecd891e1ee656fa6aeebd6ba04ecc3", - "version" : "4.6.1" - } - }, - { - "identity" : "graphviz", - "kind" : "remoteSourceControl", - "location" : "https://github.com/SwiftDocOrg/GraphViz.git", - "state" : { - "revision" : "70bebcf4597b9ce33e19816d6bbd4ba9b7bdf038", - "version" : "0.2.0" - } - }, - { - "identity" : "jsonutilities", - "kind" : "remoteSourceControl", - "location" : "https://github.com/yonaskolb/JSONUtilities.git", - "state" : { - "revision" : "128d2ffc22467f69569ef8ff971683e2393191a0", - "version" : "4.2.0" - } - }, - { - "identity" : "pathkit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/kylef/PathKit.git", - "state" : { - "revision" : "3bfd2737b700b9a36565a8c94f4ad2b050a5e574", - "version" : "1.0.1" - } - }, - { - "identity" : "rainbow", - "kind" : "remoteSourceControl", - "location" : "https://github.com/onevcat/Rainbow.git", - "state" : { - "revision" : "626c3d4b6b55354b4af3aa309f998fae9b31a3d9", - "version" : "3.2.0" - } - }, - { - "identity" : "spectre", - "kind" : "remoteSourceControl", - "location" : "https://github.com/kylef/Spectre.git", - "state" : { - "revision" : "26cc5e9ae0947092c7139ef7ba612e34646086c7", - "version" : "0.10.1" - } - }, - { - "identity" : "swift-argument-parser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser.git", - "state" : { - "revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41", - "version" : "1.3.0" - } - }, - { - "identity" : "swift-cmark", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-cmark.git", - "state" : { - "revision" : "f218e5d7691f78b55bfa39b367763f4612486c35", - "version" : "0.3.0" - } - }, - { - "identity" : "swift-format", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-format.git", - "state" : { - "revision" : "83248b4fa37919f78ffbd4650946759bcc54c2b5", - "version" : "509.0.0" - } - }, - { - "identity" : "swift-markdown", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-markdown.git", - "state" : { - "revision" : "e4f95e2dc23097a1a9a1dfdfe3fe3ee44de77378", - "version" : "0.3.0" - } - }, - { - "identity" : "swift-syntax", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-syntax", - "state" : { - "revision" : "64889f0c732f210a935a0ad7cda38f77f876262d", - "version" : "509.1.1" - } - }, - { - "identity" : "swiftcli", - "kind" : "remoteSourceControl", - "location" : "https://github.com/jakeheis/SwiftCLI.git", - "state" : { - "revision" : "2e949055d9797c1a6bddcda0e58dada16cc8e970", - "version" : "6.0.3" - } - }, - { - "identity" : "version", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mxcl/Version", - "state" : { - "revision" : "1fe824b80d89201652e7eca7c9252269a1d85e25", - "version" : "2.0.1" - } - }, - { - "identity" : "xcodegen", - "kind" : "remoteSourceControl", - "location" : "https://github.com/yonaskolb/XcodeGen.git", - "state" : { - "revision" : "87a275fb0852bb231550e66473804de57063c957", - "version" : "2.38.0" - } - }, - { - "identity" : "xcodeproj", - "kind" : "remoteSourceControl", - "location" : "https://github.com/tuist/XcodeProj.git", - "state" : { - "revision" : "3797181813ee963fe305d939232bc576d23ddbb0", - "version" : "8.15.0" - } - }, - { - "identity" : "yams", - "kind" : "remoteSourceControl", - "location" : "https://github.com/jpsim/Yams.git", - "state" : { - "revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3", - "version" : "5.0.6" - } - } - ], - "version" : 2 -} From 75b1d915f03bc82f22b8d89deedefd79f8f5f880 Mon Sep 17 00:00:00 2001 From: ra1028 Date: Thu, 16 May 2024 16:09:48 +0900 Subject: [PATCH 3/3] Fix actions config --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 862ad38..6a9134f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,7 @@ jobs: - name: Validate lint run: make lint + - name: Validate format run: | make format @@ -47,7 +48,7 @@ jobs: - name: Get npm cache id: npm-cache - uses: actions/cache@@v4 + uses: actions/cache@v4 with: path: node_modules key: ${{ runner.os }}-0-npm-${{ hashFiles('package-lock.json') }}