持續整合 (CI)
若要在你的 持續整合 工作流程中執行 Tuist 指令,你需要在 CI 環境中安裝它。
驗證為可選項目,但若你想使用伺服器端功能(例如 快取),則為必要項目。
以下章節提供在不同 CI 平台上進行設定的範例。
範例#
GitHub Actions#
在 GitHub Actions 上,你可以使用 OIDC 驗證 來進行安全且無需機密的驗證:
name: Build Application
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
- run: tuist auth login
- run: tuist setup cache
name: Build Application
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: tuist auth login
- run: tuist setup cache
name: Build Application
on:
pull_request:
branches:
- main
push:
branches:
- main
env:
TUIST_TOKEN: ${{ secrets.TUIST_TOKEN }}
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
- run: tuist setup cache
name: Build Application
on:
pull_request:
branches:
- main
push:
branches:
- main
env:
TUIST_TOKEN: ${{ secrets.TUIST_TOKEN }}
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: tuist setup cache
在使用 OIDC 驗證之前,你需要將 你的 GitHub 儲存庫 連線至你的 Tuist 專案。permissions: id-token: write 為 OIDC 運作所必需。或者,你也可以使用帶有 TUIST_TOKEN 機密的 帳戶權杖。
我們建議在你的 Tuist 專案中使用 mise use --pin,以固定跨環境的 Tuist 版本。該指令會建立包含 Tuist 版本的 .tool-versions 檔案。
Xcode Cloud#
在 Xcode Cloud(以 Xcode 專案為單一真相來源)中,你需要新增一個 複製後 腳本來安裝 Tuist 並執行你需要的指令,例如 tuist generate:
#!/bin/sh
# Mise installation taken from https://mise.jdx.dev/continuous-integration.html#xcode-cloud
curl https://mise.run | sh # Install Mise
export PATH="$HOME/.local/bin:$PATH"
mise install # Installs the version from .mise.toml
# Runs the version of Tuist indicated in the .mise.toml file {#runs-the-version-of-tuist-indicated-in-the-misetoml-file}
mise exec -- tuist install --path ../ # `--path` needed as this is run from within the `ci_scripts` directory
mise exec -- tuist generate -p ../ --no-open # `-p` needed as this is run from within the `ci_scripts` directory
透過在 Xcode Cloud 工作流程設定中設定 TUIST_TOKEN 環境變數,來使用 帳戶權杖。
CircleCI#
在 CircleCI 上,你可以使用 OIDC 驗證 來進行安全且無需機密的驗證:
version: 2.1
jobs:
build:
macos:
xcode: "15.0.1"
steps:
- checkout
- run:
name: Install Mise
command: |
curl https://mise.jdx.dev/install.sh | sh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> $BASH_ENV
- run:
name: Install Tuist
command: mise install
- run:
name: Authenticate
command: mise exec -- tuist auth login
- run:
name: Build
command: mise exec -- tuist setup cache
version: 2.1
jobs:
build:
macos:
xcode: "15.0.1"
environment:
TUIST_TOKEN: $TUIST_TOKEN
steps:
- checkout
- run:
name: Install Mise
command: |
curl https://mise.jdx.dev/install.sh | sh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> $BASH_ENV
- run:
name: Install Tuist
command: mise install
- run:
name: Build
command: mise exec -- tuist setup cache
在使用 OIDC 驗證之前,你需要將 你的 GitHub 儲存庫 連線至你的 Tuist 專案。CircleCI OIDC 權杖包含你已連線的 GitHub 儲存庫,Tuist 會使用它來授權對你專案的存取。或者,你也可以使用帶有 TUIST_TOKEN 環境變數的 帳戶權杖。
Bitrise#
在 Bitrise 上,你可以使用 OIDC 驗證 來進行安全且無需機密的驗證:
workflows:
build:
steps:
- git-clone@8: {}
- script@1:
title: Install Mise
inputs:
- content: |
curl https://mise.jdx.dev/install.sh | sh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
- script@1:
title: Install Tuist
inputs:
- content: mise install
- get-identity-token@0:
inputs:
- audience: tuist
- script@1:
title: Authenticate
inputs:
- content: mise exec -- tuist auth login
- script@1:
title: Build
inputs:
- content: mise exec -- tuist setup cache
workflows:
build:
steps:
- git-clone@8: {}
- script@1:
title: Install Mise
inputs:
- content: |
curl https://mise.jdx.dev/install.sh | sh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
- script@1:
title: Install Tuist
inputs:
- content: mise install
- script@1:
title: Build
inputs:
- content: mise exec -- tuist setup cache
在使用 OIDC 驗證之前,你需要將 你的 GitHub 儲存庫 連線至你的 Tuist 專案。Bitrise OIDC 權杖包含你已連線的 GitHub 儲存庫,Tuist 會使用它來授權對你專案的存取。或者,你也可以使用帶有 TUIST_TOKEN 環境變數的 帳戶權杖。
Codemagic#
在 Codemagic 中,你可以在工作流程中新增一個步驟來安裝 Tuist:
workflows:
build:
name: Build
max_build_duration: 30
environment:
xcode: 15.0.1
vars:
TUIST_TOKEN: ${{ secrets.TUIST_TOKEN }}
scripts:
- name: Install Mise
script: |
curl https://mise.jdx.dev/install.sh | sh
mise install # Installs the version from .mise.toml
- name: Build
script: mise exec -- tuist setup cache
workflows:
build:
name: Build
max_build_duration: 30
environment:
xcode: 15.0.1
vars:
TUIST_TOKEN: ${{ secrets.TUIST_TOKEN }}
scripts:
- name: Install Tuist
script: |
- name: Build
script: tuist setup cache
建立一個 帳戶權杖,並將其新增為名為 TUIST_TOKEN 的機密環境變數。
Appcircle#
在 Appcircle 中,你可以使用內建的 Tuist Install 和 Tuist Commands 工作流程步驟,或在 Git Clone 步驟之後新增一個 自訂腳本 步驟來自行安裝 Tuist:
cd $AC_REPOSITORY_DIR
curl https://mise.jdx.dev/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
mise install
mise exec -- tuist setup cache
cd $AC_REPOSITORY_DIR
tuist setup cache
Tuist Install 步驟會使用 Homebrew 安裝 Tuist 並執行 tuist generate。設定 Tuist Version 輸入以固定版本,然後新增 Tuist Commands 步驟以執行如 tuist test 或 tuist build 等指令。
執行報告#
當 Tuist 上傳執行紀錄時,其儀表板網址會列印至日誌中。若要無需解析日誌即可取得這些網址(例如在工作失敗時將測試報告連結發布至 Slack,或將執行紀錄饋送至你自己的工具鏈),請將 --run-report-path(或設定 TUIST_RUN_REPORT_PATH)傳遞給 tuist test、tuist xcodebuild test 或 tuist xcodebuild build。Tuist 會在上傳執行紀錄後,將 JSON 報告寫入該路徑:
{
"runId": "0193f8c1-...",
"status": "success",
"runURL": "https://tuist.dev/acme/app/runs/0193f8c1-...",
"testRunURL": "https://tuist.dev/acme/app/tests/test-runs/...",
"buildRunURL": "https://tuist.dev/acme/app/builds/build-runs/...",
"testRuns": [
{
"scheme": "App",
"succeeded": true,
"totalTests": 42,
"skippedTests": 0,
"ranTests": 42,
"failedTestNames": [],
"ranTestModules": 3,
"skippedTestModules": 5
}
],
"buildRuns": [
{ "scheme": "App", "succeeded": true, "durationInSeconds": 12.3 }
]
}
| 欄位 | 類型 | 說明 |
|---|---|---|
runId | 字串 | 執行的唯一識別碼。 |
status | 字串 | "success" 或 "failure"。 |
runURL | 字串 | 該執行的儀表板網址。一律存在。 |
testRunURL | 字串? | 測試執行的儀表板網址,當指令執行測試時會出現。 |
buildRunURL | 字串? | 建置執行的儀表板網址,當指令進行建置時會出現。 |
testRuns | 陣列 | 各 Scheme 的測試結果:scheme、succeeded、totalTests、skippedTests、ranTests、failedTestNames、ranTestModules 和 skippedTestModules。測試計數為測試案例數量,而 skippedTests 則計算結果套件回報為已跳過的案例。skippedTestModules 計算被 選擇性測試 跳過的測試模組數量,若未套用選擇性測試或該執行為測試分片,則會省略此欄位。 |
buildRuns | 陣列 | 各 Scheme 的建置結果:scheme、succeeded、durationInSeconds。 |
testRunURL 與 buildRunURL 相互獨立:同時進行建置與測試的指令會寫入兩者,但日誌無法做到這一點——日誌每次執行僅列印一個網址。
報告僅針對上傳至伺服器的執行紀錄寫入,這需要驗證並在 CI 上自動發生。路徑會在每次執行開始時清除,因此若某次執行未產生報告,不會留下任何內容,而非保留先前執行留下的過時報告。
在 GitLab CI 中,常見用法是透過 dotenv 報告 將網址揭露給後續工作:
test:
script:
- tuist test --run-report-path tuist-run.json
- echo "TUIST_TEST_RUN_URL=$(jq -r '.testRunURL // empty' tuist-run.json)" >> run.env
artifacts:
reports:
dotenv: run.env