Skip to content

Fix test workflow

Fix test workflow #127

Workflow file for this run

name: Test
on:
pull_request:
paths:
- '**.swift'
- '**.h'
- '**.m'
- '.github/workflows/test.yml'
- '.github/matrix.json'
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
generate-matrix:
name: Generate matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
latest-xcode-version: ${{ steps.set-matrix.outputs.latest-xcode-version }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: |
echo "matrix=$(cat .github/matrix.json | jq -c .)" >> $GITHUB_OUTPUT
echo "latest-xcode-version=$(cat .github/matrix.json | jq -rc '.xcode_version | max')" >> $GITHUB_OUTPUT
xcodebuild:
name: via xcodebuild
needs: generate-matrix
runs-on: macOS-latest
strategy:
fail-fast: false
matrix:
destination:
- 'platform=macOS'
- 'platform=macOS,variant=Mac Catalyst'
- 'platform=iOS Simulator,name=iPhone 11 Pro'
- 'platform=tvOS Simulator,name=Apple TV'
- 'platform=watchOS Simulator,name=Apple Watch Series 5 (40mm)'
xcode_version: ${{ fromJson(needs.generate-matrix.outputs.matrix).xcode_version }}
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer
steps:
- uses: actions/checkout@v4
- name: Run Test
id: test
run: |
platform=$(echo '${{ matrix.destination }}' | sed -E 's/platform=([^,]*)(,name=.*)?/\1/g' | tr ' ' '_')
echo "platform=$platform" >> $GITHUB_OUTPUT
defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
xcrun xcodebuild \
-enableCodeCoverage=YES \
-scheme MockUserDefaults \
-destination '${{ matrix.destination }}' \
-resultBundlePath "test_output/test_result.xcresult" \
test | xcpretty
- name: Upload test result
if: ${{ matrix.xcode_version == needs.generate-matrix.outputs.latest-xcode-version }}
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.xcode_version }}-${{ steps.test.outputs.platform }}
path: test_output
if-no-files-found: error
retention-days: 1
xcodebuild_result:
name: Export xcodebuild test result
needs: xcodebuild
runs-on: macOS-latest
steps:
- uses: actions/download-artifact@v3
with:
path: test_output
- name: Merge xcresult files
run: xcrun xcresulttool merge test_output/**/*.xcresult --output-path test_output/TestResults.xcresult
- uses: kishikawakatsumi/xcresulttool@v1
if: success() || failure()
with:
path: test_output/TestResults.xcresult
show-passed-tests: false
show-code-coverage: false
upload-bundles: true
swift_pm:
name: via SwiftPM
needs: generate-matrix
runs-on: macOS-latest
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: Run Test
run: swift test