Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel testing for the package itself and the demo app #77

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 66 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,87 @@ jobs:
- uses: actions/checkout@v4
- name: Cache SPM build directory
uses: actions/cache@v3
env:
cache-name: swiftpm
with:
path: .build
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/Package.swift') }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-
${{ runner.os }}-${{ github.job }}-
${{ runner.os }}-
- name: Disable SwiftLint Plugin
run: sed -i -e 's/.*SwiftLint.*//g' Package.swift
- name: Test
run: ./scripts/test.sh
- name: Upload test results
if: ${{ matrix.xcode_version == fromJson(needs.generate-matrix.outputs.matrix).xcode_version[0] && (success() || failure()) }}
uses: actions/upload-artifact@v3
with:
name: BuildConfig.swift.xcresult
path: test_output/BuildConfig.swift.xcresult
test_demo:
name: Test demo app
needs: generate-matrix
runs-on: macOS-12
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer
steps:
- uses: actions/checkout@v4
- name: Cache SPM build directory
uses: actions/cache@v3
env:
cache-name: swiftpm
with:
path: |
.build
Demo/.build
Demo/Tools/.build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.swift') }}
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/Package.swift') }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-
${{ runner.os }}-${{ github.job }}-
${{ runner.os }}-
- name: Cache DerivedData
uses: actions/cache@v3
env:
cache-name: derived-data
with:
path: Demo/DerivedData
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/Package.swift') }}
restore-keys: |
${{ runner.os }}-spm-${{ env.cache-name }}-
${{ runner.os }}-spm-
${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-
${{ runner.os }}-${{ github.job }}-
${{ runner.os }}-
- name: Disable SwiftLint Plugin
run: sed -i -e 's/.*SwiftLint.*//g' Package.swift
- name: test via SwiftPM
run: set -o pipefail && swift test
- name: test via xcodebuild
run: |
set -o pipefail && \
xcrun --sdk macosx xcodebuild \
-enableCodeCoverage YES \
-scheme "$(xcrun --sdk macosx xcodebuild -list -json | jq -rc '.workspace.schemes[] | select(. | startswith("BuildConfig"))')" \
-destination "platform=macOS" \
-clonedSourcePackagesDirPath '.build/SourcePackages' \
-resultBundlePath 'test_output/BuildConfig.swift.xcresult' \
clean test | xcpretty
- name: test DemoApp
if: success() || failure()
run: |
set -o pipefail && \
xcrun --sdk macosx swift run --package-path Demo/Tools xcodegen --spec Demo/project.yml && \
PROJECT_PATH=$(find Demo -depth 1 -name '*.xcodeproj' | head -n 1) && \
xcrun --sdk macosx xcodebuild \
-skipPackagePluginValidation \
-enableCodeCoverage YES \
-project "${PROJECT_PATH}" \
-scheme "$(xcrun --sdk macosx xcodebuild -project "${PROJECT_PATH}" -list -json | jq -rc '.project.schemes[] | select(. | contains("Demo"))')" \
-destination 'platform=iOS Simulator,name=iPhone 14 Pro' \
-clonedSourcePackagesDirPath 'Demo/.build/SourcePackages' \
-resultBundlePath 'test_output/BuildConfigDemo.xcresult' \
clean test | xcpretty
- name: test
run: ./scripts/test_demo.sh
- name: upload test results
if: ${{ matrix.xcode_version == fromJson(needs.generate-matrix.outputs.matrix).xcode_version[0] && (success() || failure()) }}
uses: actions/upload-artifact@v3
with:
name: BuildConfigDemo.xcresult
path: test_output/BuildConfigDemo.xcresult
report:
name: Report
needs: [test, test_demo]
runs-on: macOS-12
if: ${{ (success() || failure()) }}
steps:
- uses: actions/download-artifact@v3
with:
path: test_output
- run: ls -la test_output
- uses: kishikawakatsumi/xcresulttool@v1
with:
path: |
test_output/BuildConfig.swift.xcresult
test_output/BuildConfigDemo.xcresult
show-passed-tests: false
show-code-coverage: false
if: ${{ matrix.xcode_version == fromJson(needs.generate-matrix.outputs.matrix).xcode_version[0] && (success() || failure()) }}
danger:
name: Danger
if: ${{ github.event_name == 'pull_request' }}
Expand Down
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
executable_name = buildconfigswift

.PHONY: clean build test release lint format
.SILENT:

.PHONY: clean build test release lint format demo_app_init demo_test demo

default: clean build

Expand All @@ -15,22 +17,24 @@ build:
swift build

test:
swift test
./scripts/test.sh

release:
@scripts/release.sh $(executable_name)
scripts/release.sh $(executable_name)

lint:
@swift run swiftlint
swift run swiftlint

format:
@swift run swiftlint --fix
swift run swiftlint --fix

demo_app_init:
@scripts/copy-lint-config.sh && \
scripts/copy-lint-config.sh && \
cd Demo && \
xcrun --sdk macosx swift run -c release --package-path Tools xcodegen

.PHONY: demo
demo: demo_app_init
@xed Demo/BuildConfigSwiftDemo.xcodeproj
xed Demo/BuildConfigSwiftDemo.xcodeproj

demo_test:
./scripts/test_demo.sh
21 changes: 21 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -o pipefail

XCRESULT_PATH='test_output/BuildConfig.swift.xcresult'

if [[ -e "$XCRESULT_PATH" ]]; then
rm -rf "$XCRESULT_PATH"
fi

SCHEME="$(xcrun --sdk macosx xcodebuild -list -json | jq -rc '.workspace.schemes[] | select(. | startswith("BuildConfig"))')"

echo "Scheme: $SCHEME"

xcrun --sdk macosx xcodebuild \
-enableCodeCoverage YES \
-scheme "${SCHEME}" \
-destination "platform=macOS" \
-clonedSourcePackagesDirPath '.build/SourcePackages' \
-resultBundlePath "$XCRESULT_PATH" \
clean test | xcpretty
30 changes: 30 additions & 0 deletions scripts/test_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

set -o pipefail

XCRESULT_PATH='test_output/BuildConfigDemo.xcresult'

if [[ -e "$XCRESULT_PATH" ]]; then
rm -rf "$XCRESULT_PATH"
fi

if [[ "$(find Demo -depth 1 -name '*.xcodeproj')" == '' ]]; then
$(dirname $0)/copy-lint-config.sh
xcrun --sdk macosx swift run --package-path Demo/Tools xcodegen --spec Demo/project.yml
fi

PROJECT_PATH=$(find Demo -depth 1 -name '*.xcodeproj' | head -n 1)
SCHEME="$(xcrun --sdk macosx xcodebuild -project "${PROJECT_PATH}" -list -json | jq -rc '.project.schemes[] | select(. | contains("Demo"))')"

echo "Scheme: $SCHEME"

xcrun --sdk macosx xcodebuild \
-skipPackagePluginValidation \
-enableCodeCoverage YES \
-project "${PROJECT_PATH}" \
-scheme "${SCHEME}" \
-destination 'platform=iOS Simulator,name=iPhone 14 Pro' \
-derivedDataPath 'Demo/DerivedData' \
-clonedSourcePackagesDirPath 'Demo/.build/SourcePackages' \
-resultBundlePath "$XCRESULT_PATH" \
clean test | xcpretty