From 17110ed857a39d636aeacb6f3253e2d56e6209bf Mon Sep 17 00:00:00 2001 From: maximkrouk Date: Sat, 28 Sep 2024 17:11:06 +0200 Subject: [PATCH] feat(CI): Update workflow --- .../InterceptionMacrosPluginTests.xcscheme | 25 +++ .../InterceptionMacrosTests.xcscheme | 25 +++ .../xcschemes/InterceptionTests.xcscheme | 25 +++ .github/workflows/ci.yml | 131 +++++++++++++-- .gitmodules | 3 + .../InterceptionMacrosPluginTests.xcscheme | 25 +++ .../InterceptionMacrosTests.xcscheme | 25 +++ .../xcschemes/InterceptionTests.xcscheme | 25 +++ Makefile | 153 +++++++++++------- swift-package-action | 1 + 10 files changed, 365 insertions(+), 73 deletions(-) create mode 100644 .gitmodules create mode 160000 swift-package-action diff --git a/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme b/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme index afa6afe..58ec1da 100644 --- a/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme +++ b/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme @@ -5,6 +5,22 @@ + + + + + + + + + + diff --git a/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme b/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme index e44ab3f..7dce191 100644 --- a/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme +++ b/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme @@ -5,6 +5,22 @@ + + + + + + + + + + diff --git a/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionTests.xcscheme b/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionTests.xcscheme index 2c211d8..11769fd 100644 --- a/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionTests.xcscheme +++ b/.github/package.xcworkspace/xcshareddata/xcschemes/InterceptionTests.xcscheme @@ -5,6 +5,22 @@ + + + + + + + + + + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2cc0f43..d711c29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,28 +7,135 @@ on: pull_request: branches: - '*' + workflow_dispatch: concurrency: group: ci-${{ github.ref }} cancel-in-progress: true jobs: - library-swift-latest: - name: Library + test-library: + name: test-library if: | !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[ci skip test]') && !contains(github.event.head_commit.message, '[ci skip library-swift-latest]') - runs-on: macos-13 - timeout-minutes: 30 + runs-on: macos-14 strategy: + fail-fast: false matrix: - config: - - debug - - release + platform: [iOS, macOS, tvOS, watchOS, macCatalyst] + xcode: ['15.4', '16.1'] + config: [Debug] + command: [test] + scheme: [Interception] steps: - - uses: actions/checkout@v4 - - name: Select Xcode 15.2 - run: sudo xcode-select -s /Applications/Xcode_15.2.app - - name: Run test - run: make test + - uses: actions/checkout@v4 + with: + submodules: true + - name: Select Xcode ${{ matrix.xcode }} + run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app + - name: Cache derived data + uses: actions/cache@v3 + with: + path: | + ~/.derivedData + key: | + deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}-${{ hashFiles('**/Sources/**/*.swift', '**/Tests/**/*.swift') }} + restore-keys: | + deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}- + - name: Set IgnoreFileSystemDeviceInodeChanges flag + run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES + - name: Update mtime for incremental builds + uses: chetan/git-restore-mtime-action@v2 + - name: test-library (${{ matrix.config }}) + uses: capturecontext/swift-package-action@1.0 + with: + command: xcodebuild + subcommand: ${{ matrix.command }} + platform: ${{ matrix.platform }} + scheme: ${{ matrix.scheme }} + config: ${{ matrix.config }} + test-library-macros: + name: test-library-macros + if: | + !contains(github.event.head_commit.message, '[ci skip]') && + !contains(github.event.head_commit.message, '[ci skip test]') && + !contains(github.event.head_commit.message, '[ci skip library-swift-latest]') + runs-on: macos-14 + strategy: + fail-fast: false + matrix: + platform: [iOS, macOS, tvOS, watchOS, macCatalyst] + xcode: ['15.4', '16.1'] + config: [Debug] + command: [test] + scheme: [Interception] + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Select Xcode ${{ matrix.xcode }} + run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app + - name: Cache derived data + uses: actions/cache@v3 + with: + path: | + ~/.derivedData + key: | + deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}-${{ hashFiles('**/Sources/**/*.swift', '**/Tests/**/*.swift') }} + restore-keys: | + deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}- + - name: Set IgnoreFileSystemDeviceInodeChanges flag + run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES + - name: Update mtime for incremental builds + uses: chetan/git-restore-mtime-action@v2 + - name: test-library-macros (${{ matrix.config }}) + uses: capturecontext/swift-package-action@1.0 + with: + command: xcodebuild-macros + subcommand: ${{ matrix.command }} + platform: ${{ matrix.platform }} + scheme: ${{ matrix.scheme }} + config: ${{ matrix.config }} + test-library-macros-plugin: + name: test-library-macros-plugin + if: | + !contains(github.event.head_commit.message, '[ci skip]') && + !contains(github.event.head_commit.message, '[ci skip test]') && + !contains(github.event.head_commit.message, '[ci skip library-swift-latest]') + runs-on: macos-14 + strategy: + matrix: + platform: [macOS] + xcode: ['16.1'] + command: [test] + config: [Debug] + scheme: [Interception] + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Select Xcode ${{ matrix.xcode }} + run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app + - name: Cache derived data + uses: actions/cache@v3 + with: + path: | + ~/.derivedData + key: | + deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}-${{ hashFiles('**/Sources/**/*.swift', '**/Tests/**/*.swift') }} + restore-keys: | + deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}- + - name: Set IgnoreFileSystemDeviceInodeChanges flag + run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES + - name: Update mtime for incremental builds + uses: chetan/git-restore-mtime-action@v2 + - name: test-library-macros-plugin (${{ matrix.config }}) + uses: capturecontext/swift-package-action@1.0 + with: + command: xcodebuild-macros-plugin + subcommand: ${{ matrix.command }} + platform: ${{ matrix.platform }} + scheme: ${{ matrix.scheme }} + config: ${{ matrix.config }} diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b698629 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "swift-package-action"] + path = swift-package-action + url = git@github.com:capturecontext/swift-package-action.git diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme index afa6afe..58ec1da 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosPluginTests.xcscheme @@ -5,6 +5,22 @@ + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme index e44ab3f..7dce191 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionMacrosTests.xcscheme @@ -5,6 +5,22 @@ + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme index 2c211d8..11769fd 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme @@ -5,6 +5,22 @@ + + + + + + + + + + diff --git a/Makefile b/Makefile index ae59f68..0bbf7af 100644 --- a/Makefile +++ b/Makefile @@ -1,71 +1,102 @@ -CONFIG = debug -PLATFORM_IOS = iOS Simulator,id=$(call udid_for,iOS 17.2,iPhone \d\+ Pro [^M]) -PLATFORM_MACOS = macOS -PLATFORM_MAC_CATALYST = macOS,variant=Mac Catalyst -PLATFORM_TVOS = tvOS Simulator,id=$(call udid_for,tvOS 17,TV) -PLATFORM_WATCHOS = watchOS Simulator,id=$(call udid_for,watchOS 10,Watch) +default: + $(error Missing command) + @exit 1 -default: test-all +%: + $(error Unknown command: $@) + @exit 1 + +TEST_RUNNER_CI ?= $(CI) +MAKEFILE_PATH ?= ./swift-package-action/Makefile + +SCHEME ?= Interception +PLATFORM ?= iOS +CONFIG ?= Debug + +DERIVED_DATA=./DerivedData + +BOLD=\033[1m +RESET=\033[0m test-all: - $(MAKE) test + $(MAKE) test-library + $(MAKE) test-library-macros $(MAKE) test-docs -test: - $(MAKE) CONFIG=debug test-library - $(MAKE) CONFIG=debug test-library-macros - $(MAKE) test-macros - test-library: - for platform in "$(PLATFORM_IOS)" "$(PLATFORM_MACOS)" "$(PLATFORM_MAC_CATALYST)" "$(PLATFORM_TVOS)" "$(PLATFORM_WATCHOS)"; do \ - echo "\nTesting library on $$platform\n" && \ - (xcodebuild test \ - -skipMacroValidation \ - -configuration $(CONFIG) \ - -workspace .github/package.xcworkspace \ - -scheme InterceptionTests \ - -destination platform="$$platform" | xcpretty && exit 0 \ - ) \ - || exit 1; \ - done; + @make loop-platforms \ + -f $(MAKEFILE_PATH) \ + PLATFORMS=iOS,macOS,macCatalyst,watchOS,tvOS \ + GOAL=xcodebuild \ + COMMAND=test \ + SCHEME=$(SCHEME) \ + CONFIG=$(CONFIG) \ + DERIVED_DATA=$(DERIVED_DATA) test-library-macros: - for platform in "$(PLATFORM_IOS)" "$(PLATFORM_MACOS)" "$(PLATFORM_MAC_CATALYST)" "$(PLATFORM_TVOS)" "$(PLATFORM_WATCHOS)"; do \ - echo "\nTesting library-macros on $$platform\n" && \ - (xcodebuild test \ - -skipMacroValidation \ - -configuration $(CONFIG) \ - -workspace .github/package.xcworkspace \ - -scheme InterceptionMacrosTests \ - -destination platform="$$platform" | xcpretty && exit 0 \ - ) \ - || exit 1; \ - done; - -test-macros: - echo "\nTesting macros\n" && \ - (xcodebuild test \ - -skipMacroValidation \ - -configuration $(CONFIG) \ - -workspace .github/package.xcworkspace \ - -scheme InterceptionMacrosPluginTests \ - -destination platform=macOS | xcpretty && exit 0 \ - ) \ - || exit 1; - -DOC_WARNINGS = $(shell xcodebuild clean docbuild \ - -scheme Interception \ - -destination platform="$(PLATFORM_IOS)" \ - -quiet \ - 2>&1 \ - | grep "couldn't be resolved to known documentation" \ - | sed 's|$(PWD)|.|g' \ - | tr '\n' '\1') + @make loop-platforms \ + -f $(MAKEFILE_PATH) \ + PLATFORMS=iOS,macOS,macCatalyst,watchOS,tvOS \ + GOAL=xcodebuild-macros \ + COMMAND=test \ + SCHEME=$(SCHEME) \ + CONFIG=$(CONFIG) \ + DERIVED_DATA=$(DERIVED_DATA) + $(MAKE) xcodebuild-macros-plugin COMMAND=test PLATFORM=macOS + +xcodebuild: + @make xcodebuild \ + -f $(MAKEFILE_PATH) \ + COMMAND=$(COMMAND) \ + DERIVED_DATA=$(DERIVED_DATA) \ + CONFIG=$(CONFIG) \ + SCHEME=$(SCHEME) \ + PLATFORM=$(PLATFORM) + +xcodebuild-macros: + @make xcodebuild-macros \ + -f $(MAKEFILE_PATH) \ + COMMAND=$(COMMAND) \ + DERIVED_DATA=$(DERIVED_DATA) \ + CONFIG=$(CONFIG) \ + SCHEME=$(SCHEME) \ + PLATFORM=$(PLATFORM) + +xcodebuild-macros-plugin: + @make xcodebuild-macros-plugin \ + -f $(MAKEFILE_PATH) \ + COMMAND=$(COMMAND) \ + DERIVED_DATA=$(DERIVED_DATA) \ + CONFIG=$(CONFIG) \ + SCHEME=$(SCHEME) \ + PLATFORM=$(PLATFORM) + +build-for-library-evolution: + @make build-for-library-evolution \ + -f $(MAKEFILE_PATH) \ + SCHEME=$(SCHEME) + test-docs: - @test "$(DOC_WARNINGS)" = "" \ - || (echo "xcodebuild docbuild failed:\n\n$(DOC_WARNINGS)" | tr '\1' '\n' \ - && exit 1) + @make test-docs \ + -f $(MAKEFILE_PATH) \ + SCHEME=$(SCHEME) \ + PLATFORM=$(PLATFORM) + +test-example: + @make test-example \ + -f $(MAKEFILE_PATH) \ + DERIVED_DATA=$(DERIVED_DATA) \ + SCHEME=$(SCHEME) \ + PLATFORM=$(PLATFORM) + +test-integration: + @make test-integration \ + -f $(MAKEFILE_PATH) \ + SCHEME=Integration \ + PLATFORM=$(PLATFORM) + +benchmark: + @make benchmark -f $(MAKEFILE_PATH) -define udid_for -$(shell xcrun simctl list devices available '$(1)' | grep '$(2)' | sort -r | head -1 | awk -F '[()]' '{ print $$(NF-3) }') -endef +format: + @make format -f $(MAKEFILE_PATH) diff --git a/swift-package-action b/swift-package-action new file mode 160000 index 0000000..3e8c454 --- /dev/null +++ b/swift-package-action @@ -0,0 +1 @@ +Subproject commit 3e8c4544ca15761cfb48faa5855f02bd6584116f