server/priv/docs/zh_Hans/guides/integrations/continuous-integration.md
要在 持续集成 工作流程中运行 Tuist 命令,需要在 CI 环境中安装它。
身份验证是可选的,但如果要使用<LocalizedLink href="/guides/features/cache">缓存</LocalizedLink>等服务器端功能,则必须进行身份验证。
以下各节将举例说明如何在不同的 CI 平台上实现这一功能。
在GitHub 操作中,您可以使用<LocalizedLink href="/guides/server/authentication#oidc-tokens">OIDC 身份验证</LocalizedLink>进行安全的无秘身份验证:
代码组
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: brew install --formula [email protected]
- 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: brew install --formula [email protected]
- run: tuist setup cache
:::
[!NOTE] Oidc Setup
在使用 OIDC 身份验证之前,您需要 <LocalizedLink href="/guides/integrations/gitforge/github"> 将 GitHub 仓库</LocalizedLink>连接到 Tuist 项目。要使用 OIDC,需要
permissions: id-token: write。或者,你也可以使用带有TUIST_TOKENsecret 的 <LocalizedLink href="/guides/server/authentication#project-tokens">项目令牌</LocalizedLink>。
[!TIP] 我们建议在 Tuist 项目中使用
mise use --pin来固定跨环境的 Tuist 版本。该命令将创建一个.tool-versions文件,其中包含 Tuist 的版本。
在使用 Xcode 项目作为真实源的 Xcode Cloud
中,您需要添加一个
post-clone
脚本来安装 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
#!/bin/sh
brew install --formula [email protected]
tuist generate
:::
[!NOTE] Authentication
通过在 Xcode Cloud 工作流设置中设置
TUIST_TOKEN环境变量,使用 <LocalizedLink href="/guides/server/authentication#project-tokens"> 项目令牌</LocalizedLink>。
在 CircleCI 上,您可以使用 <LocalizedLink href="/guides/server/authentication#oidc-tokens">OIDC 身份验证</LocalizedLink>进行安全的无秘身份验证:
代码组
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
:::
[!NOTE] Authentication
在使用 OIDC 身份验证之前,您需要 <LocalizedLink href="/guides/integrations/gitforge/github"> 将 GitHub 仓库</LocalizedLink>连接到 Tuist 项目。CircleCI OIDC 令牌包含已连接的 GitHub 仓库,Tuist 会使用它来授权对项目的访问。或者,你也可以使用
TUIST_TOKEN环境变量来获取 <LocalizedLink href="/guides/server/authentication#project-tokens">项目令牌</LocalizedLink>。
在 Bitrise 上,您可以使用 <LocalizedLink href="/guides/server/authentication#oidc-tokens">OIDC 身份验证</LocalizedLink>进行安全的无秘身份验证:
代码组
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
:::
[!NOTE] Authentication
在使用 OIDC 身份验证之前,您需要 <LocalizedLink href="/guides/integrations/gitforge/github"> 将 GitHub 仓库</LocalizedLink>连接到 Tuist 项目。Bitrise OIDC 令牌包含已连接的 GitHub 仓库,Tuist 会使用它来授权对项目的访问。或者,你也可以使用
TUIST_TOKEN环境变量来获取 <LocalizedLink href="/guides/server/authentication#project-tokens">项目令牌</LocalizedLink>。
在 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: |
brew install --formula [email protected]
- name: Build
script: tuist setup cache
:::
[!NOTE] Authentication
创建 <LocalizedLink href="/guides/server/authentication#project-tokens"> 项目令牌</LocalizedLink>,并将其添加为秘密环境变量,命名为
TUIST_TOKEN。