了解如何从 CI 环境(例如 GitHub Action 等)触发应用的 EAS 构建。
本文档概述了如何从 CI 环境(例如 GitHub Actions、Travis CI 等)触发应用的 EAS 构建。
¥This document outlines how to trigger builds on EAS for your app from a CI environment such as GitHub Actions, Travis CI, and more.
在 CI 上使用 EAS 进行构建之前,我们需要安装并配置 eas-cli
。然后,我们可以使用 eas build
命令触发新的构建。
¥Before building with EAS on CI, we need to install and configure eas-cli
. Then, we can trigger new builds with the eas build
command.
¥Prerequisites
¥Run a successful build from your local machine
要从 CI 环境触发 EAS 构建,我们首先需要为 EAS 构建配置应用,并从本地计算机为我们希望在 CI 上支持的每个平台成功运行构建。
¥To trigger EAS builds from a CI environment, we first need to configure our app for EAS Build and successfully run a build from our local machine for each platform that we'd like to support on CI.
如果你之前已经成功运行过 eas build -p [all|android|ios]
,那么你可以继续。
¥If you have run eas build -p [all|android|ios]
successfully before, then you can continue.
如果你尚未执行此操作,请参阅 创建你的第一个版本 指南,并在准备好后返回此处。
¥If you haven't done this yet, see Create your first build guide and return here when you're ready.
¥Configure your app for CI
¥Provide a personal access token to authenticate with your Expo account on CI
接下来,我们需要确保我们可以在 CI 上验证自己作为应用所有者的身份。这可以通过在 CI 设置的 EXPO_TOKEN
环境变量中存储个人访问令牌来实现。
¥Next, we need to ensure that we can authenticate ourselves on CI as the owner of the app. This is possible by storing a personal access token in the EXPO_TOKEN
environment variable in the CI settings.
请参阅 个人访问令牌 了解如何创建访问令牌。
¥See personal access tokens to learn how to create access tokens.
¥(Optional) Provide an ASC API Token for your Apple Team
如果你的 iOS 凭据需要修复,我们将需要一个 ASC API 密钥来在 CI 中向 Apple 进行身份验证。一种常见的情况是你的配置文件需要重新签名。
¥In the event your iOS credentials need to be repaired, we will need an ASC API key to authenticate ourselves to Apple in CI. A common case is when your provisioning profile needs to be re-signed.
你将需要创建一个 API 密钥。接下来,你需要收集有关你的 苹果团队 的信息。
¥You will need to create an API Key. Next, you will need to gather information about your Apple Team.
使用你收集到的信息,通过环境变量将其传递到构建命令中。你将需要通过以下内容:
¥Using the information you've gathered, pass it into the build command through environment variables. You will need to pass the following:
EXPO_ASC_API_KEY_PATH
:ASC API 密钥 .p8 文件的路径。例如,/path/to/key/AuthKey_SFB993FB5F.p8。
¥EXPO_ASC_API_KEY_PATH
: The path to your ASC API Key .p8 file. For example, /path/to/key/AuthKey_SFB993FB5F.p8.
EXPO_ASC_KEY_ID
:你的 ASC API 密钥的密钥 ID。例如,SFB993FB5F
。
¥EXPO_ASC_KEY_ID
: The key ID of your ASC API Key. For example, SFB993FB5F
.
EXPO_ASC_ISSUER_ID
:你的 ASC API 密钥的颁发者 ID。例如,f9675cff-f45d-4116-bd2c-2372142cee09
。
¥EXPO_ASC_ISSUER_ID
: The issuer ID of your ASC API Key. For example, f9675cff-f45d-4116-bd2c-2372142cee09
.
EXPO_APPLE_TEAM_ID
:你的 Apple 团队 ID。例如,77KQ969CHE
。
¥EXPO_APPLE_TEAM_ID
: Your Apple Team ID. For example, 77KQ969CHE
.
EXPO_APPLE_TEAM_TYPE
:你的 Apple 团队类型。有效类型为 IN_HOUSE
、COMPANY_OR_ORGANIZATION
或 INDIVIDUAL
。
¥EXPO_APPLE_TEAM_TYPE
: Your Apple Team Type. Valid types are IN_HOUSE
, COMPANY_OR_ORGANIZATION
, or INDIVIDUAL
.
¥Trigger new builds
现在我们已经通过 Expo CLI 进行了身份验证,我们可以创建构建步骤。
¥Now that we're authenticated with Expo CLI, we can create the build step.
为了触发新的构建,我们将此脚本添加到我们的配置中:
¥To trigger new builds, we will add this script to our configuration:
-
npx eas-cli build --platform all --non-interactive --no-wait
这将触发 EAS 的新构建。将打印一个 URL,链接到 EAS 仪表板中的构建进度。
¥This will trigger a new build on EAS. A URL will be printed, linking to the build's progress in the EAS dashboard.
一旦触发构建,--no-wait
标志就会退出该步骤。EAS 执行构建时,你无需支付 CI 执行时间的费用。但是,仅当触发 EAS 构建成功时,你的 CI 才会报告构建作业正在通过。
在项目存储库根目录的 .travis.yml 中添加以下代码片段。
¥Add the following code snippet in .travis.yml at the root of your project repository.
language: node_js
node_js:
- node
- lts/*
cache:
directories:
- ~/.npm
before_script:
- npm install -g npm@latest
jobs:
include:
- stage: build
node_js: lts/*
script:
- npm ci
- npx eas-cli build --platform all --non-interactive --no-wait
在项目存储库根目录的 .gitlab-ci.yml 中添加以下代码片段。
¥Add the following code snippet in .gitlab-ci.yml at the root of your project repository.
image: node:alpine
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .npm
# or with yarn:
#- .yarn
stages:
- build
before_script:
- npm ci --cache .npm
# or with yarn:
#- yarn install --cache-folder .yarn
eas-build:
stage: build
script:
- apk add --no-cache bash
- npx eas-cli build --platform all --non-interactive --no-wait
在项目存储库根目录的 bitbucket-pipelines.yml 中添加以下代码片段。
¥Add the following code snippet in bitbucket-pipelines.yml at the root of your project repository.
image: node:alpine
definitions:
caches:
npm: ~/.npm
pipelines:
default:
- step:
name: Build app
deployment: test
caches:
- npm
script:
- apk add --no-cache bash
- npm ci
- npx eas-cli build --platform all --non-interactive --no-wait
在项目存储库根目录下的 circleci/config.yml 中添加以下代码片段。
¥Add the following code snippet in circleci/config.yml at the root of your project repository.
version: 2.1
executors:
default:
docker:
- image: cimg/node:lts
working_directory: ~/my-app
jobs:
eas_build:
executor: default
steps:
- checkout
- run:
name: Install dependencies
command: npm ci
- run:
name: Trigger build
command: npx eas-cli build --platform all --non-interactive --no-wait
workflows:
build_app:
jobs:
- eas_build:
filters:
branches:
only: master
在项目存储库根目录的 .github/workflows/eas-build.yml 中添加以下代码片段。
¥Add the following code snippet in .github/workflows/eas-build.yml at the root of your project repository.
name: EAS Build
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build:
name: Install and build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: npm
- name: Setup Expo and EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: Install dependencies
run: npm ci
- name: Build on EAS
run: eas build --platform all --non-interactive --no-wait