Fixing Swift Testing in Xcode and Migrating to Matrix #162
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: BushelKit | |
on: | |
push: | |
branches-ignore: | |
- '*WIP' | |
env: | |
PACKAGE_NAME: BushelKit | |
jobs: | |
build-ubuntu: | |
name: Build on Ubuntu | |
env: | |
SWIFT_VER: 6.0 | |
if: "!contains(github.event.head_commit.message, 'ci skip')" | |
runs-on: ubuntu-latest | |
container: | |
image: swift:6.0-noble | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache swift package modules | |
id: cache-spm-linux | |
uses: actions/cache@v4 | |
env: | |
cache-name: cache-spm | |
with: | |
path: .build | |
key: ${{ runner.os }}-${{ env.cache-name }}-${{ matrix.swift-version }}-${{ hashFiles('Package.resolved') }} | |
restore-keys: | | |
${{ runner.os }}-${{ env.cache-name }}-${{ matrix.swift-version }}- | |
${{ runner.os }}-${{ env.cache-name }}- | |
- name: Test | |
run: swift test --enable-code-coverage | |
- uses: sersoft-gmbh/swift-coverage-action@v4 | |
id: coverage-files | |
with: | |
fail-on-empty-output: true | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
fail_ci_if_error: true | |
flags: swift-${{ matrix.swift-version }},ubuntu | |
verbose: true | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: ${{ join(fromJSON(steps.coverage-files.outputs.files), ',') }} | |
build-macos: | |
name: Build on macOS | |
env: | |
PACKAGE_NAME: BushelKit | |
runs-on: ${{ matrix.runs-on }} | |
if: "!contains(github.event.head_commit.message, 'ci skip')" | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# SPM Build Matrix | |
- runs-on: macos-15 | |
xcode: "/Applications/Xcode_16.1.app" | |
- runs-on: macos-15 | |
xcode: "/Applications/Xcode_16.2.app" | |
# iOS Build Matrix | |
- type: ios | |
runs-on: macos-15 | |
xcode: "/Applications/Xcode_16.1.app" | |
deviceName: "iPhone 16" | |
osVersion: "18.1" | |
- type: ios | |
runs-on: macos-15 | |
xcode: "/Applications/Xcode_16.2.app" | |
deviceName: "iPhone 16 Pro" | |
osVersion: "18.2" | |
# watchOS Build Matrix | |
- type: watchos | |
runs-on: macos-15 | |
xcode: "/Applications/Xcode_16.1.app" | |
deviceName: "Apple Watch Ultra 2 (49mm)" | |
osVersion: "11.1" | |
- type: watchos | |
runs-on: macos-15 | |
xcode: "/Applications/Xcode_16.2.app" | |
deviceName: "Apple Watch Ultra 2 (49mm)" | |
osVersion: "11.2" | |
- type: visionos | |
runs-on: macos-15 | |
xcode: "/Applications/Xcode_16.2.app" | |
deviceName: "Apple Vision Pro" | |
osVersion: "2.1" | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Xcode Name | |
run: echo "XCODE_NAME=$(basename -- ${{ matrix.xcode }} | sed 's/\.[^.]*$//' | cut -d'_' -f2)" >> $GITHUB_ENV | |
- name: Setup Xcode | |
run: sudo xcode-select -s ${{ matrix.xcode }}/Contents/Developer | |
# SPM Cache Step | |
- name: Cache swift package modules | |
id: cache-spm-macos | |
uses: actions/cache@v4 | |
env: | |
cache-name: cache-spm | |
with: | |
path: .build | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Package.resolved') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Build SPM | |
if: "!matrix.type" | |
run: swift build | |
- name: Run Swift Package tests | |
if: "!matrix.type" | |
run: swift test -v --enable-code-coverage | |
- name: Enable Swift Testing | |
if: matrix.type | |
run: | | |
mkdir -p ~/Library/org.swift.swiftpm/security/ | |
cp macros.json ~/Library/org.swift.swiftpm/security/ | |
# Common iOS/watchOS Test Steps | |
- name: Run Device Tests | |
if: matrix.type | |
run: > | |
xcodebuild test | |
-scheme ${{ env.PACKAGE_NAME }}-Package | |
-sdk ${{ matrix.type == 'ios' && 'iphonesimulator' || 'watchsimulator' }} | |
-destination 'platform=${{ matrix.type == 'ios' && 'iOS Simulator' || 'watchOS Simulator' }},name=${{ matrix.deviceName }},OS=${{ matrix.osVersion }}' | |
-enableCodeCoverage YES | |
build test | |
# Common Coverage Steps | |
- name: Process Coverage | |
uses: sersoft-gmbh/swift-coverage-action@v4 | |
with: | |
fail-on-empty-output: true | |
- name: Upload Coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
flags: ${{ matrix.type && format('{0}{1}', matrix.type, matrix.osVersion) || 'spm' }} | |
build-docc: | |
name: Build DocC | |
needs: [build-macos, build-ubuntu] | |
runs-on: ubuntu-latest | |
container: | |
image: swift:6.0-noble | |
volumes: | |
- ${{ github.workspace }}:/workspace | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache swift package modules | |
id: cache-spm-linux | |
uses: actions/cache@v4 | |
env: | |
cache-name: cache-spm | |
with: | |
path: .build | |
key: ${{ runner.os }}-${{ env.cache-name }}-${{ matrix.swift-version }}-${{ hashFiles('Package.resolved') }} | |
restore-keys: | | |
${{ runner.os }}-${{ env.cache-name }}-${{ matrix.swift-version }}- | |
${{ runner.os }}-${{ env.cache-name }}- | |
- name: Build DocC | |
run: swift package generate-documentation --platform "name=macos,version=15.1" --transform-for-static-hosting --hosting-base-path "swift-docc" --disable-indexing --enable-experimental-combined-documentation | |
- name: Package DocArchive | |
if: github.ref == 'refs/heads/main' | |
working-directory: .build/plugins/Swift-DocC/outputs | |
run: tar -cf BushelKit.doccarchive.tar BushelKit.doccarchive | |
- name: Upload a Build Artifact | |
uses: actions/upload-artifact@v4 | |
if: github.ref == 'refs/heads/main' | |
with: | |
overwrite: true | |
path: /workspace/.build/plugins/Swift-DocC/outputs/BushelKit.doccarchive.tar | |
retention-days: 30 | |
- uses: peter-evans/repository-dispatch@v3 | |
if: github.ref == 'refs/heads/main' | |
with: | |
token: ${{ secrets.PAT_TOKEN }} | |
repository: brightdigit/BushelDocs | |
event-type: docc-update | |
client-payload: '{"run_id": "${{ github.run_id }}"}' |