我有兴趣使用 GitHub Actions 在 CI 上运行我的 Swift 项目的构建
我使用以下
ci.yml
:
Build:
runs-on: macOS-latest
steps:
- name: Install Swift
uses: slashmo/[email protected]
with:
version: 5.7
- name: Checkout
uses: actions/checkout@v1
- name: Build
uses: sersoft-gmbh/xcodebuild-action@v2
with:
project: <Project>.xcodeproj
scheme: <Scheme>
destination: "platform=iOS Simulator,name=iPhone 14 Pro Max"
action: build
我在这里面临一个问题:
xcodebuild: error: Could not resolve package dependencies:
package at '/Users/runner/work/path/to/my/package' is using Swift tools version 5.7.0 but the installed version is 5.5.0
我想使用
swift-tools-version
等于 5.7.0
,而不是较低的
请帮我安装我需要的版本
看来我成功了。我在我的工作流程中添加了此步骤:
- name: Select Xcode
run: sudo xcode-select -s "/Applications/Xcode_14.0.1.app"
然后指定模拟器环境:
env:
destination: 'platform=iOS Simulator,name=iPhone 14 Pro,OS=16.0'
目前 macos-14 在 Github 机器上可用。因此,以下操作是有效的并且对我有用;
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
name: Swift
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: macos-14
steps:
- uses: actions/checkout@v3
- name: List Xcode installations
run: sudo ls -1 /Applications | grep "Xcode"
- name: Select Xcode 15.2
run: sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v