測試
在 workflow 中執行你的測試套件,並了解 Macrunara 自家 Action 的品質保障方式。
在 Workflow 中執行測試
在 Macrunara Runner 上,把測試步驟加在構建之後:
jobs:
build:
runs-on: [macos, arm64, macrunara]
steps:
- uses: actions/checkout@v4
- uses: macrunara/setup-action@v1
with:
installation-id: ${{ secrets.MACRUNARA_INSTALLATION_ID }}
region: auto
- name: Build
run: xcodebuild -scheme MyApp -destination 'platform=macOS'
- name: Test
run: swift test
對於 Xcode 專案,使用 xcodebuild test 並指定目標裝置:
- name: Test
run: |
xcodebuild -scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
test
local-mac-runner-action 自身的品質保障
該 Action 內建零依賴的 bash 單元測試套件和 CI 驗證工作流程,其品質保障完全不依賴真實的 macOS Runner。
本地單元測試
tests/run_tests.sh 是一個零依賴的 bash 單元測試套件:在臨時目錄中放置 mock xcodebuild(記錄參數、產生假 .app / .ipa),涵蓋以下用例:
build.sh不傳project時不帶-project參數;build.sh傳project時正確攜帶-project路徑;build.sh的scheme/configuration/sdk參數正確傳遞;export-archive.sh無.xcarchive時略過匯出且退出碼為 0;export-archive.sh有.xcarchive時呼叫-exportArchive並產生 IPA;export-archive.sh在匯出失敗時不致命(輸出::warning::,退出碼仍為 0)。
本地執行(任何裝有 bash 的環境,無需 macOS):
cd github-app/local-mac-runner-action
bash tests/run_tests.sh
全部通過時退出碼為 0,末尾列印通過/失敗計數;任一斷言失敗則退出碼為 1。
CI 整合驗證
測試工作流程位於 .github/workflows/test.yml,在 ubuntu-latest 上依次執行三步:
- 語法校驗:用 js-yaml 解析
action.yml並檢查必需 inputs; - 單元測試:
bash tests/run_tests.sh(即上述單元測試套件); - 整合驗證:透過 mock
xcodebuild實際執行本 Action(Release/Debug 矩陣),驗證.app產物與匯出的.ipa。
全程無需真實 macOS Runner。