Skip to content

Commit

Permalink
Restructure tool installation
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed May 16, 2024
1 parent 798f686 commit b1e7620
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 32 deletions.
23 changes: 9 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }}
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"),
])
}
149 changes: 149 additions & 0 deletions Tools/Package.resolved
Original file line number Diff line number Diff line change
@@ -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
}
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 b1e7620

Please sign in to comment.