This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

自定义构建配置架构

使用 EAS Build 进行自定义构建的配置选项参考。


为 EAS Build 创建自定义版本有助于自定义项目的构建过程。

🌐 Creating custom builds for EAS Build helps customize the build process for your project.

自定义构建的 YAML 语法

🌐 YAML syntax for custom builds

自定义构建配置文件存储在 .eas/build 目录路径中。它们使用 YAML 语法,并且必须具有 .yml 或 .yaml 文件扩展名。如果你是 YAML 新手或想了解更多语法信息,请参见 在 Y 分钟内学习 YAML。

🌐 Custom build config files are stored inside the .eas/build directory path. They use YAML syntax and must have a .yml or .yaml file extension. If you are new to YAML or want to learn more about the syntax, see Learn YAML in Y minutes.

build

用于描述自定义构建配置的定义。所有用于创建自定义构建的配置选项都在其下指定。

🌐 Defined to describe a custom build configuration. All config options to create a custom build are specified under it.

name

自定义构建的名称,用于在构建日志中识别它。EAS 构建使用此属性在仪表板中显示构建名称。

🌐 The name of your custom build that is used to identify it in the build logs. EAS Build uses this property to display the name of your build in the dashboard.

例如,构建名称是 Run tests:

🌐 For example, the build name is Run tests:

build: name: Run tests steps: - eas/checkout - run: name: Install dependencies command: npm install

steps

步骤用于描述一系列操作,可以是命令或函数调用的形式。当自定义构建在 EAS Build 上运行时,这些操作将会执行。你可以在构建配置中定义单个或多个步骤。然而,每次构建必须至少定义一个步骤。

🌐 Steps are used to describe a list of actions, either in the form of commands or function calls. These actions are executed when a custom build runs on EAS Build. You can define single or multiple steps in a build config. However, it is required to define at least one step per build.

每个步骤都配置有以下属性:

🌐 Each step is configured with the following properties:

steps[].run

run 键用于触发一组指令。例如,run 键用于通过 npm install 命令安装依赖:

🌐 The run key is used to trigger a set of instructions. For example, a run key is used to install dependencies using the npm install command:

build: name: Install npm dependencies steps: - eas/checkout - run: name: Install dependencies command: npm install

你也可以使用 steps[].run 来执行单行或多行的 Shell 命令:

🌐 You can also use steps[].run to execute single or multiline shell commands:

build: name: Run inline shell commands steps: - run: echo "Hello world" - run: | echo "Multiline" echo "bash commands"

使用单步

🌐 Use a single step

例如,带有以下 steps 的构建配置将打印 "Hello world":

🌐 For example, a build config with the following steps will print "Hello world":

build: name: Greeting steps: - run: echo "Hello world"

使用多个步骤

🌐 Use multiple steps

当定义多个 steps 时,它们会按顺序执行。例如,具有以下 steps 的构建配置将首先签出项目,安装 npm 依赖,然后运行命令以执行测试:

🌐 When multiple steps are defined, they are executed sequentially. For example, a build config with the following steps will first check out the project, install npm dependencies, and then run a command to run tests:

build: name: Run tests steps: - eas/checkout - run: name: Install dependencies command: npm install - run: name: Run tests command: | echo "Running tests..." npm test

与其他步骤共享环境变量

🌐 Sharing environment variables with other steps

在一个步骤的 command 中导出的环境变量(使用 export)不会自动暴露给其他步骤。要将环境变量共享给其他步骤,请使用 set-env 可执行文件。

🌐 Environment variables exported (using export) in one step's command are not automatically exposed to other steps. To share an environment variable with other steps, use the set-env executable.

set-env 期望被调用时传入两个参数:环境变量的名称和数值。例如,set-env NPM_TOKEN "abcdef" 将会将 $NPM_TOKEN 变量及其值 abcdef 暴露给其他步骤。

build: name: Shared environment variable example steps: - run: name: Set environment variables command: | set -x # Set variable ENV_TEST_LOCAL="present-only-in-current-shell-context" # Set and export variable export ENV_TEST_LOCAL_EXPORT="present-in-current-step" # Set shared variable set-env ENV_TEST_SET_ENV "present-in-following-steps" # Will print "ENV_TEST_LOCAL: present-only-in-current-shell-context" # because current shell has access to this local variable. echo "ENV_TEST_LOCAL: $ENV_TEST_LOCAL" # Will print "ENV_TEST_LOCAL_EXPORT: present-in-current-step" # because export also sets the local variable value. echo "ENV_TEST_LOCAL_EXPORT: $ENV_TEST_LOCAL_EXPORT" # Will "ENV_TEST_SET_ENV: " # because set-env does not set or export variables. echo "ENV_TEST_SET_ENV: $ENV_TEST_SET_ENV" # Will only print LOCALLY_EXPORTED_ENV, # because it is the only export-ed variable. env | grep ENV_TEST_ - run: name: Check variables values in next step command: | set -x # Will print "ENV_TEST_LOCAL: ", because ENV_TEST_LOCAL # is only a local variable in previous step. echo "ENV_TEST_LOCAL: $ENV_TEST_LOCAL" # Will print "ENV_TEST_LOCAL_EXPORT: " # because export does not share a variable to other steps. echo "ENV_TEST_LOCAL_EXPORT: $ENV_TEST_LOCAL_EXPORT" # Will print "ENV_TEST_SET_ENV: present-in-following-steps" # because set-env "exported" variable to other steps. echo "ENV_TEST_SET_ENV: $ENV_TEST_SET_ENV" # Will only print ENV_TEST_SET_ENV, # because set-env "exported" it to other steps. env | grep ENV_TEST_

steps[].run.name

构建日志中用于显示步骤名称的名称。

🌐 The name used in build logs to display the name of the step.

steps[].run.command

command 定义了在执行步骤时运行的自定义 Shell 命令。每个步骤必须定义一个命令。它可以是多行的 Shell 命令:

🌐 The command defines a custom shell command to run when a step is executed. It is required to define a command for each step. It can be a multiline shell command:

build: name: Run tests steps: - eas/checkout - run: name: Run tests command: | echo "Running tests..." npm test

steps[].run.working_directory

working_directory 用于从项目的根目录定义一个已存在的目录。在步骤中定义了一个已存在的路径后,使用它会更改该步骤的当前目录。例如,可以创建一个步骤来列出 assets 目录中的所有资源,该目录位于你的 Expo 项目中。working_directory 设置为 assets:

🌐 The working_directory is used to define an existing directory from the project's root directory. After an existing path is defined in a step, using it changes the current directory for that step. For example, a step is created to list all the assets inside the assets directory, which is a directory in your Expo project. The working_directory is set to assets:

build: name: Demo steps: - eas/checkout - run: name: List assets working_directory: assets command: ls -la

steps[].run.shell

用于定义步骤的默认可执行 shell。例如,将步骤的 shell 设置为 /bin/sh:

🌐 Used to define the default executable shell for a step. For example, the step's shell is set to /bin/sh:

build: name: Demo steps: - run: shell: /bin/sh command: | echo "Steps can use another shell" ps -p $$

steps[].run.inputs

输入值会提供给一个步骤。例如,你可以使用 input 来提供一个值:

🌐 Input values are provided to a step. For example, you can use input to provide a value:

build: name: Demo steps: - run: name: Say Hi inputs: name: Expo command: echo "Hi, ${ inputs.name }!"

steps[].run.outputs

在某个步骤中预期会有输出值。例如,一个步骤的输出值为 Hello world:

🌐 An output value is expected during a step. For example, a step has an output value of Hello world:

build: name: Demo steps: - run: name: Produce output outputs: [value] command: | echo "Producing output for another step" set-output value "Output from another step..."

steps[].run.outputs.required

输出值可以使用布尔值来表示该输出值是否是必需的。例如,一个函数可以没有必需的输出值:

🌐 An output value can use a boolean to indicate if the output value is required or not. For example, a function does not have a required output value:

build: name: Demo steps: - run: name: Produce another output id: id456 outputs: - required_param - name: optional_param required: false command: | echo "Producing more output" set-output required_param "abc 123 456"

steps[].run.id

为一个步骤定义 id 可以:

🌐 Defining an id for a step allows:

  • 多次调用产生一个或多个输出的同一函数
  • 使用从一个步骤到另一步骤的输出

调用同一个函数一次或多次

🌐 Call the same function one or more times

例如,以下函数生成一个随机数:

🌐 For example, the following function generates a random number:

functions: random: name: Generate random number outputs: [value] command: set-output value `random_number`

在构建配置中,我们使用 random 函数生成两个随机数并打印它们:

🌐 In a build config, let's use the random function to generate two random numbers and print them:

build: name: Functions Demo steps: - random: id: random_1 - random: id: random_2 - run: name: Print random numbers inputs: random_1: ${ steps.random_1.value } random_2: ${ steps.random_2.value } command: | echo "${ inputs.random_1 }" echo "${ inputs.random_2 }"

使用从一个步骤到另一步骤的输出

🌐 Use output from one step to another

例如,以下构建配置演示了如何使用从一个步骤到另一个步骤的输出:

🌐 For example, the following build config demonstrates how to use output from one step to another:

build: name: Outputs demo steps: - run: name: Produce output id: id123 # <---- !!! outputs: [foo] command: | echo "Producing output for another step" set-output foo bar - run: name: Use output from another step inputs: foo: ${ steps.id123.foo } command: | echo "foo = \"${ inputs.foo }\""

functions

用于描述可在构建配置中使用的可重用函数。创建函数的所有配置选项通过以下属性指定:

🌐 Defined to describe a reusable function that can be used in a build config. All config options to create a function are specified with the following properties:

functions.[function_name]

[function_name] 是你定义的用于在 build.steps 中识别它的函数名称。例如,你可以定义一个名为 greetings 的函数:

🌐 The [function_name] is the name of a function that you define to identify it in the build.steps. For example, you can define a function with the name greetings:

functions: greetings: name: Say Hi!

functions.[function_name].name

在构建日志中用于显示函数名称的名称。例如,具有显示名称 Say Hi! 的函数:

🌐 The name that is used in build logs to display the name of the function. For example, a function with the display name Say Hi!:

functions: greetings: name: Say Hi!

functions.[function_name].inputs

输入值被提供给函数。

🌐 Input values are provided to a function.

inputs[].name

输入值的名称。它用作访问输入值的标识符,例如在 bash 命令插值中使用。

🌐 The name of the input value. It is used as an identifier to access the input value such as in bash command interpolation.

functions: greetings: name: Say Hi! inputs: - name: name default_value: Hello world command: echo "${ inputs.name }!"

inputs[].required

布尔值,用于指示输入值是否为必填。例如,一个函数可能没有必填值:

🌐 Boolean to indicate if the input value is required or not. For example, a function does not have a required value:

functions: greetings: name: Say Hi! inputs: - name: name required: false

inputs[].type

输入值的类型。它可以是 string、num 或 json。

🌐 The type of the input value. It can be either string, num or json.

函数调用中设置的输入值以及函数的 default_value 和 allowed_values 都会根据类型进行验证。

🌐 Input values set in the function call as well as default_value and allowed_values for the function are validated against the type.

默认输入 type 是 string。

🌐 The default input type is string.

例如,一个函数有一个类型为 string 的输入值:

🌐 For example, a function has an input value of type string:

functions: greetings: name: Say Hi! inputs: - name: name type: string - name: age type: num - name: other_data type: json

inputs[].default_value

你可以使用 default_value 提供一个默认输入。例如,一个函数的默认值为 Hello world:

🌐 You can use default_value to provide one default input. For example, a function has a default value of Hello world:

functions: greetings: name: Say Hi! inputs: - name: name default_value: Hello world

inputs[].allowed_values

你可以使用 allowed_values 来在数组中提供多个值。例如,某个函数有多个允许的值:

🌐 You can use allowed_values to provide multiple values in an array. For example, a function has multiple allowed values:

functions: greetings: name: Say Hi! inputs: - name: name default_value: Hello world allowed_values: [Hi, Hello, Hey] type: string

多个输入值

🌐 Multiple input values

可以向函数提供多个输入值。

🌐 Multiple input values can be provided to a function.

functions: greetings: name: Say Hi! inputs: - name: name default_value: Expo - name: greeting default_value: Hi allowed_values: [Hi, Hello] command: echo "${ inputs.greeting }, ${ inputs.name }!"

functions.[function_name].outputs

函数期望有一个输出值。例如,一个函数的输出值为 Hello world:

🌐 An output value is expected from a function. For example, a function has an output value of Hello world:

functions: greetings: name: Say Hi! outputs: [value] command: set-output value "Hello world"

outputs[].name

输出值的名称。它用作标识符,以便在另一步中访问该输出值:

🌐 The name of the output value. It is used as an identifier to access the output value in another step:

functions: greetings: name: Say Hi! outputs: - name: name

outputs[].required

布尔值,用于指示输出值是否为必需。例如,一个函数可能没有必需的输出值:

🌐 Boolean to indicate if the output value is required or not. For example, a function does not have a required output value:

functions: greetings: name: Say Hi! outputs: - name: value required: false

functions.[function_name].command

用于定义在执行函数时要运行的命令,如果你希望该函数是一个简单的 shell 脚本。每个函数必须定义一个 command 或 path 指向实现该函数的 JS/TS 模块。例如,命令 echo "Hello world" 用于打印一条消息:

🌐 Used to define the command to run when a function is executed, if you wish the function to be a simple shell script. Each function is required to define either a command or a path to JS/TS module implementing the function. For example, the command echo "Hello world" is used to print a message:

functions: greetings: name: Say Hi! command: echo "Hi!"

functions.[function_name].path

用于定义实现该函数的 JavaScript/TypeScript 模块的路径。每个函数必须定义 command 或 path 属性。例如,路径 ./greetings 用于执行在 greetings 模块中声明的 greetings 函数:

🌐 Used to define the path to a JavaScript/TypeScript module implementing the function. Each function is required to define either a command or a path property. For example, the path ./greetings is used to execute a greetings function declared in the greetings module:

functions: greetings: name: Say Hi! path: ./greetings

functions.[function_name].shell

用于定义执行函数步骤的默认可执行 shell。例如,步骤的 shell 设置为 /bin/sh:

🌐 Used to define the default executable shell for a step where a function is executed. For example, the step's shell is set to /bin/sh:

functions: greetings: name: Say Hi! shell: /bin/sh command: echo "Hi!"

functions.[function_name].supported_platforms

用于定义函数支持的平台。默认支持所有平台。允许的平台有:darwin、linux。

🌐 Used to define the supported platforms for a function. Defaults to all platforms. Allowed platforms: darwin, linux.

例如,该函数支持的平台是 darwin(macOS):

🌐 For example, the function's supported platform is darwin (macOS):

functions: greetings: name: Say Hi! supported_platforms: [darwin] command: echo "Hi!"

import

用于从其他配置文件导入函数的配置文件路径列表。导入的文件不能包含 build 部分。

🌐 A config file path list used to import functions from other config files. Imported files cannot have the build section.

例如,下面的构建配置导入了两个文件并调用了两个导入的函数——say_hi 和 say_bye。

🌐 For example, the following build config imports two files and calls two imported functions - say_hi and say_bye.

build-and-test.yml
import: - common-functions.yml - another-file.yml build: steps: - say_hi - say_bye
common-functions.yml
functions: say_hi: name: Say Hi! command: echo "Hi!"
another-file.yml
functions: say_bye: name: Say bye :( command: echo "Bye!"

函数

🌐 Functions

内置 EAS 功能

🌐 Built-in EAS functions

EAS 提供了一组内置可重用函数,你可以在构建配置中使用这些函数,而无需定义函数定义。

🌐 EAS provides a set of built-in reusable functions that you can use in a build config without defining the function definition.

eas/build

封装整个 EAS Build 构建过程的一体化功能。它会根据你在 eas.json 中的构建配置文件设置确定最佳构建配置。

🌐 The all-in-one function that encapsulates the entire EAS Build build process. It resolves the best build configuration based on your build profile's settings from eas.json.

它非常适合那些希望完成构建而不必担心手动更改和配置构建过程的人。如果你有兴趣在构建过程之前或之后使用其他自定义步骤,并且不想更改构建过程本身,它也可以成为你自定义构建配置的一个很好的起点。

🌐 It's ideal for people who want to have the build done without worrying about altering and configuring the build process manually. It can be a great starting point for your custom build configuration if you are interested in using other custom steps before or after the build process and you don't want to change the build process itself.

example.yml
build: name: Run a build using a single command steps: - eas/build

为了更好地控制构建过程并根据你的需求进行自定义,请参阅以下由 eas/build 在后台运行的自定义函数和步骤。它们会根据你的构建配置文件的设置作为构建过程执行。

🌐 To have more control over the build process and customize it as per your requirements, see the following custom functions and steps that run in the background by eas/build. They are executed as a build process based on your build profile's configuration.

安卓

🌐 Android

当构建配置使用 withoutCredentials 时:

🌐 When a build configuration is using withoutCredentials:

当构建配置使用凭据时(适用于 internal 和 store 分发 构建):

🌐 When a build configuration uses credentials (for both internal and store distribution builds):

iOS

当构建配置使用 withoutCredentials 或 simulator 时:

🌐 When a build configuration is using withoutCredentials or simulator:

当构建配置使用凭据时(适用于 internal 和 store 分发 构建):

🌐 When a build configuration uses credentials (for both internal and store distribution builds):

你可以通过在 YAML 配置文件中使用以下步骤来替换 eas/build 命令调用:

🌐 You can replace the eas/build command call by using these steps in your YAML configuration file:

ios-simulator-build.yml

查看 `eas/build` 函数在我们示例仓库中对 iOS 模拟器构建背后执行的步骤。

ios-credentials-build.yml

查看在我们的示例仓库中,`eas/build` 函数在使用凭证进行 iOS 构建时后台执行的步骤。

android-build-without-credentials.yml

查看在我们的示例仓库中,`eas/build` 函数在没有凭据的情况下为 Android 构建执行的幕后步骤。

android-build-with-credentials.yml

查看 `eas/build` 函数在我们示例仓库中,使用凭证进行 Android 构建时后台执行的步骤。

已知的限制

🌐 Known limitations

  • 它不接受任何输入,已解析的构建过程将根据你在 eas.json 中的构建配置进行配置。
  • eas/build 生成的构建过程不可配置,你无法对其进行自定义。如果你需要自定义构建过程,请使用此函数在后台执行的一系列函数和步骤,并在 YAML 配置文件中手动配置它们,如上面的示例所示。

eas/maestro_test

安装 Maestro、准备测试环境(Android 模拟器或 iOS 模拟器)并测试应用的一体化功能。

🌐 All-in-one function that installs Maestro, prepares a testing environment (Android Emulator or iOS Simulator), and tests the app.

输入类型必填描述
flow_pathstring要运行的 Maestro flows 的路径(或多个路径,每个路径单独一行)。
app_pathstring要测试的模拟器/模拟器应用的路径(或正则表达式模式)。如果未提供,Android 默认为 android/app/build/outputs//*.apk**,iOS 默认为 ios/build/Build/Products/simulator/.app。
build-and-test.yml
build: name: Build and test steps: - eas/build - eas/maestro_test: inputs: flow_path: | maestro/sign_in.yml maestro/create_post.yml maestro/sign_out.yml
test-ios-simulator-app.yml
build: name: Build and test iOS simulator app steps: - eas/checkout - eas/maestro_test: app_path: ./fixtures/my_app.app inputs: flow_path: | maestro/sign_in.yml maestro/create_post.yml maestro/sign_out.yml
test-android-emulator-app.yml
build: name: Build and test Android emulator app steps: - eas/checkout - eas/maestro_test: app_path: ./fixtures/my_app.apk inputs: flow_path: | maestro/sign_in.yml maestro/create_post.yml maestro/sign_out.yml

在幕后,它使用:

🌐 Behind the scenes, it uses:

如果你需要自定义 Maestro 版本、运行特定的 Android 模拟器或 iOS 模拟器,或上传多个构建工件,你将需要自己编写这一系列步骤。

🌐 If you need to customize the Maestro version, run a specific Android Emulator or iOS Simulator, or upload multiple build artifacts you will need to write this series of steps yourself.

一个示例 Android 构建配置,包含展开的 eas/maestro_test
build-and-test-android-expanded.yml
build: name: Build and test (Android, expanded) steps: - eas/build - eas/install_maestro - eas/start_android_emulator: inputs: system_package_name: system-images;android-34;default;x86_64 - run: command: | # shopt -s globstar is necessary to add /**/ support shopt -s globstar # shopt -s nullglob is necessary not to try to install # SEARCH_PATH literally if there are no matching files. shopt -s nullglob SEARCH_PATH="android/app/build/outputs/**/*.apk" FILES_FOUND=false for APP_PATH in $SEARCH_PATH; do FILES_FOUND=true echo "Installing \\"$APP_PATH\\"" adb install "$APP_PATH" done if ! $FILES_FOUND; then echo "No files found matching \\"$SEARCH_PATH\\". Are you sure you've built an Emulator app?" exit 1 fi - run: command: | maestro test maestro/flow.yml - eas/upload_artifact: name: Upload test artifact if: ${ always() } inputs: type: build-artifact path: ${ eas.env.HOME }/.maestro/tests
一个示例 iOS 构建配置,其中 eas/maestro_test 已展开
build-and-test-ios-expanded.yml
build: name: Build and test (iOS, expanded) steps: - eas/build - eas/install_maestro - eas/start_ios_simulator - run: command: | # shopt -s nullglob is necessary not to try to install # SEARCH_PATH literally if there are no matching files. shopt -s nullglob SEARCH_PATH="ios/build/Build/Products/*simulator/*.app" FILES_FOUND=false for APP_PATH in $SEARCH_PATH; do FILES_FOUND=true echo "Installing \\"$APP_PATH\\"" xcrun simctl install booted "$APP_PATH" done if ! $FILES_FOUND; then echo "No files found matching \\"$SEARCH_PATH\\". Are you sure you've built a Simulator app?" exit 1 fi - run: command: | maestro test maestro/flow.yml - eas/upload_artifact: name: Upload test artifact if: ${ always() } inputs: type: build-artifact path: ${ eas.env.HOME }/.maestro/tests
eas/maestro_test 源代码

在 GitHub 上查看 eas/maestro_test 函数的源代码。

eas/checkout

签出你的项目源文件。

🌐 Checks out your project source files.

upload.yml
build: name: List files steps: - eas/checkout - run: name: List assets run: ls assets

对于使用基于 Git 的项目源的构建,该步骤默认使用构建记录的提交。使用 ref 可以签出不同的分支、标签或提交:

🌐 For builds with Git-based project sources, the step uses the build's recorded commit by default. Use ref to check out a different branch, tag, or commit:

example.yml
build: name: Check out a specific ref steps: - eas/checkout: inputs: ref: feature/add-icon - eas/build

ref 接受:

  • 一个分支,可以是像 feature/add-icon 这样的裸名称,也可以是像 refs/heads/feature/add-icon 这样的限定引用。仓库最终会在该分支上。
  • 一个标签,作为像 refs/tags/v1.2.3 这样的限定引用。仓库最终处于分离的 HEAD 上。
  • 一个完整的提交 SHA。仓库最终会处于分离的 HEAD 状态。

ref 输入仅在你的项目源来自 Git 仓库时有效,例如通过 GitHub 集成触发的构建。本地构建和上传的项目压缩包不支持它。将此步骤放在 eas/build 之前,后者会在内部检出项目。

🌐 The ref input only works when your project sources come from a Git repository, for example, a build triggered through the GitHub integration. Local builds and uploaded project tarballs do not support it. Place the step before eas/build, which checks out the project internally.

属性类型是否必填描述
refstring要检出的 Git 分支、标签或完整提交 SHA。默认为触发构建或工作流任务的引用。
eas/结帐源代码

在 GitHub 上查看 eas/checkout 功能的源代码。

eas/use_npm_token

配置 Node 包管理器(bun、npm、pnpm 或 Yarn)以用于私有包,发布到 npm 或私有注册表。

🌐 Configures Node package managers (bun, npm, pnpm, or Yarn) for use with private packages, published either to npm or a private registry.

在你的项目密钥中设置 NPM_TOKEN,此功能将通过创建带有令牌的 .npmrc 来配置构建环境。

🌐 Set NPM_TOKEN in your project's secrets, and this function will configure the build environment by creating .npmrc with the token.

example.yml
build: name: Install private npm modules steps: - eas/checkout - eas/use_npm_token - run: name: Install dependencies run: npm install # <---- Can now install private packages
eas/use_npm_token 源代码

在 GitHub 上查看 eas/use_npm_token 函数的源代码。

eas/install_node_modules

根据你的项目检测到的包管理器(bun、npm、pnpm 或 Yarn)安装 node_modules。适用于多仓库项目。

🌐 Installs node_modules using the package manager (bun, npm, pnpm, or Yarn) detected based on your project. Works with monorepos.

example.yml
build: name: Install node modules steps: - eas/checkout - eas/install_node_modules
eas/install_node_modules 源代码

在 GitHub 上查看 eas/install_node_modules 函数的源代码。

eas/restore_build_cache

从指定的密钥恢复先前保存的构建缓存。这对于通过重用缓存的工件(如已编译的依赖、构建工具或其他中间构建输出)来加快构建速度非常有用。

🌐 Restores a previously saved build cache from a specified key. This is useful for speeding up builds by reusing cached artifacts like compiled dependencies, build tools, or other intermediate build outputs.

example.yml
build: name: Build with cache steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/restore_build_cache: inputs: key: cache-${{ hashFiles('package-lock.json') }} restore_keys: cache path: /path/to/cache
example.yml
build: name: Build with cache steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/restore_build_cache: inputs: key: cache-${{ hashFiles('package-lock.json') }} path: /path/to/cache
属性类型必填描述
name-在可重用函数中显示在构建日志里的步骤名称。默认值为 Restore build cache。
inputs.keystring要恢复的缓存键。你可以使用像 ${{ hashFiles('package-lock.json') }} 这样的表达式根据文件哈希创建动态键。
inputs.restore_keysstring如果找不到精确的键,可以使用的备用键或前缀。如提供,缓存系统会查找以该前缀开头的任何缓存条目。
inputs.pathstring缓存应恢复到的路径。这个路径应与保存缓存时使用的路径一致。
eas/restore_build_cache 源代码

在 GitHub 上查看 eas/restore_build_cache 函数的源代码。

eas/save_build_cache

将构建缓存保存到指定的键。这允许你保留构建产物、已编译的依赖或其他可在后续构建中重复使用的中间输出,从而加快构建过程。

🌐 Saves a build cache to a specified key. This allows you to persist build artifacts, compiled dependencies, or other intermediate outputs that can be reused in subsequent builds to speed up the build process.

example.yml
build: name: Build with cache steps: - eas/checkout - eas/restore_build_cache: inputs: key: cache-${{ hashFiles('package-lock.json') }} path: /path/to/cache - eas/install_node_modules - eas/prebuild - eas/run_gradle - eas/save_build_cache: inputs: key: cache-${{ hashFiles('package-lock.json') }} path: /path/to/cache
属性类型是否必填描述
name-可复用函数中步骤的名称,会显示在构建日志中。默认值为 Save build cache。
inputs.keystring用于保存缓存的缓存键。你可以使用像 ${{ hashFiles('package-lock.json') }} 这样的表达式,根据文件哈希创建动态键。这个键应该与恢复缓存时使用的键匹配。
inputs.pathstring应该缓存的目录或文件的路径。这个路径应该与恢复缓存时使用的路径匹配。
eas/save_build_cache 源代码

在 GitHub 上查看 eas/save_build_cache 函数的源代码。

eas/resolve_build_config

解析并打印构建配置。如果构建是由 GitHub 集成触发的,它将更新当前的 job 和 metadata 上下文值。应在安装依赖后调用此方法,因为配置可能会受到配置插件的影响。

🌐 Resolves and prints the build configuration. If the build has been triggered by the GitHub integration, it will update the current job and metadata context values. It should be called after installing the dependencies because the config may be influenced by config plugins.

此函数由 eas/build 函数组自动执行。

🌐 This function is automatically executed by the eas/build function group.

eas/resolve_build_config 源代码

在 GitHub 上查看 eas/resolve_build_config 函数的源代码。

eas/get_credentials_for_build_triggered_by_github_integration

eas/resolve_apple_team_id_from_credentials

根据在 inputs.credentials 中提供的构建凭据解析 Apple 团队 ID 值。解析得到的 Apple 团队 ID 会存储在 outputs.apple_team_id 输出值中。

🌐 Resolves the Apple team ID value based on build credentials provided in the inputs.credentials. The resolved Apple team ID is stored in the outputs.apple_team_id output value.

example.yml
build: name: Run prebuild script steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id }
属性类型必填描述
namestring在可重用函数中显示在构建日志里的步骤名称。默认是 Resolve Apple team ID from credentials。
inputs.credentialsjson用于 iOS 构建的应用凭证。默认是 ${ eas.job.secrets.buildCredentials }。需要符合 iOS 的 ${ eas.job.secrets.buildCredentials } 格式。
eas/resolve_apple_team_id_from_credentials 源代码

在 GitHub 上查看 eas/resolve_apple_team_id_from_credentials 函数的源代码。

eas/prebuild

使用包管理器(bun、npm、pnpm 或 Yarn)运行 expo prebuild 命令,根据你的项目自动检测适合的命令,以匹配你的构建类型和构建环境。

🌐 Runs the expo prebuild command using the package manager (bun, npm, pnpm, or Yarn) detected based on your project with the command best suited for your build type and build environment.

example.yml
build: name: Run prebuild script steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id }
example.yml
build: name: Run prebuild script steps: - eas/checkout - eas/install_node_modules - eas/prebuild
属性类型描述
cleanboolean可选属性,定义函数在运行命令时是否应使用 --clean 标志。默认值为 false。
apple_team_idstring可选属性,定义在进行预构建时应使用的 Apple 团队 ID。对于使用凭据的 iOS 构建,应指定该值。
eas/预构建源代码

在 GitHub 上查看 eas/prebuild 函数的源代码。

eas/configure_eas_update

配置构建的运行时版本和发布通道。

🌐 Configures runtime version and release channel for your build.

example.yml
build: name: Configure EAS Update steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update
example.yml
build: name: Configure EAS Update steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update: inputs: runtime_version: 1.0.0 channel: mychannel
属性类型是否必填描述
name-可重用函数中步骤的名称,会显示在构建日志中。默认值为 Configure EAS Update。
inputs.runtime_versionstring构建时应配置的运行时版本。默认值为 ${ eas.job.version.runtimeVersion } 或原生定义的运行时版本。
inputs.channelstring构建时应配置的渠道。默认值为 ${ eas.job.updates.channel }。
eas/configure_eas_update 源代码

在 GitHub 上查看 eas/configure_eas_update 函数的源代码。

eas/inject_android_credentials

在构建器上使用凭据配置 Android 密钥库,并使用这些凭据将应用签名配置注入到 Gradle 配置中。

🌐 Configures Android keystore with credentials on the builder and injects app signing config using these credentials into gradle config.

example.yml
build: name: Android credentials steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/inject_android_credentials
属性类型必填描述
name-可重用函数中步骤的名称,会显示在构建日志中。默认为 Inject Android credentials。
inputs.credentialsjson你的 Android 构建应用凭证。默认为 ${ eas.job.secrets.buildCredentials }。需要符合 Android 的 ${ eas.job.secrets.buildCredentials } 架构。
eas/inject_android_credentials 源代码

在 GitHub 上查看 eas/inject_android_credentials 函数的源代码。

eas/configure_ios_credentials

在构建器上配置 iOS 凭证。通过为目标分配配置文件来修改 Xcode 项目的配置。

🌐 Configures iOS credentials on the builder. Modifies the configuration of the Xcode project by assigning provisioning profiles to the targets.

example.yml
build: name: iOS credentials steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - eas/configure_ios_credentials
属性类型必填描述
name-可重用函数中该步骤的名称,会显示在构建日志中。默认值为 Configure iOS credentials。
inputs.build_configurationstringXcode 项目的构建配置。默认值为 ${ eas.job.buildConfiguration },如果未指定,则在开发客户端中解析为 Debug,在其他构建中解析为 Release。
inputs.credentialsjson你的 iOS 构建所需的应用凭据。默认值为 ${ eas.job.secrets.buildCredentials }。需要符合 iOS 的 ${ eas.job.secrets.buildCredentials } 规范。
eas/configure_ios_credentials 源代码

在 GitHub 上查看 eas/configure_ios_credentials 函数的源代码。

eas/configure_android_version

配置你的 Android 应用的版本。它用于在使用远程应用版本管理时设置版本。

🌐 Configures the version of your Android app. It's used to set a version when using remote app version management.

使用此功能不是强制的,如果不使用,将使用预构建阶段生成的本地代码版本。

🌐 It's not mandatory to use this function, if it's not used the version from native code generated during the prebuild phase will be used.

example.yml
build: name: Configure Android version steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/configure_android_version
example.yml
build: name: Configure Android version steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/configure_android_version: inputs: version_code: '123' version_name: '1.0.0'
属性类型必填描述
name-可重用函数中步骤的名称,会显示在构建日志中。默认值为 Configure Android version。
inputs.version_codestring你的 Android 构建的 versionCode。默认值为 ${ eas.job.version.versionCode }。
inputs.version_namestring你的 Android 构建的 versionName。默认值为 ${ eas.job.version.versionName }。
eas/configure_android_version 源代码

在 GitHub 上查看 eas/configure_android_version 函数的源代码。

eas/configure_ios_version

配置你的 iOS 应用的版本。它用于在使用 远程应用版本管理 时设置版本。

🌐 Configures the version of your iOS app. It's used to set a version when using remote app version management.

使用此功能不是强制的,如果不使用,将使用预构建阶段生成的本地代码版本。

🌐 It's not mandatory to use this function, if it's not used the version from native code generated during the prebuild phase will be used.

example.yml
build: name: Configure iOS version steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - eas/configure_eas_update - eas/configure_ios_credentials - eas/configure_ios_version
example.yml
build: name: Configure iOS version steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - eas/configure_eas_update - eas/configure_ios_credentials - eas/configure_ios_version: inputs: build_number: '123' app_version: '1.0.0'
属性类型必填描述
name-在可重用函数中显示在构建日志里的步骤名称。默认值为 Configure iOS version。
inputs.build_numberstring你 iOS 构建的构建号 (CFBundleVersion)。默认值为 ${ eas.job.version.buildNumber }。
inputs.app_versionstring你 iOS 构建的应用版本 (CFBundleShortVersionString)。默认值为 ${ eas.job.version.appVersion }。
inputs.build_configurationstringXcode 项目的构建配置。默认值为 ${ eas.job.buildConfiguration },如果未指定,则对于开发客户端解析为 Debug,对于其他构建解析为 Release。
inputs.credentialsjson你 iOS 构建的应用凭据。默认值为 ${ eas.job.secrets.buildCredentials }。需要符合 iOS 的 ${ eas.job.secrets.buildCredentials } 格式。
eas/configure_ios_version 源代码

在 GitHub 上查看 eas/configure_ios_version 函数的源代码。

eas/run_gradle

运行 Gradle 命令来构建 Android 应用。

🌐 Runs a Gradle command to build an Android app.

example.yml
build: name: Build Android app steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/run_gradle
example.yml
build: name: Build Android app steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/run_gradle: inputs: command: :app:bundleRelease
属性类型必填描述
name-在可复用函数中显示在构建日志里的步骤名称。默认值是 Run gradle。
inputs.commandstring用于构建 Android 应用的 Gradle 命令。如果未指定,则会根据构建配置和 ${ eas.job } 对象的内容来决定。
eas/run_gradle 源代码

在 GitHub 上查看 eas/run_gradle 函数的源代码。

eas/generate_gymfile_from_template

生成一个 Gymfile,用于从模板使用 Fastlane 构建 iOS 应用。

🌐 Generates a Gymfile used to build the iOS app using Fastlane from a template.

传递凭证时使用的默认模板:

🌐 Default template used when credentials are passed:

Gymfile
suppress_xcode_output(true) clean(<%- CLEAN %>) scheme("<%- SCHEME %>") <% if (BUILD_CONFIGURATION) { %> configuration("<%- BUILD_CONFIGURATION %>") <% } %> export_options({ method: "<%- EXPORT_METHOD %>", provisioningProfiles: {<% _.forEach(PROFILES, function(profile) { %> "<%- profile.BUNDLE_ID %>" => "<%- profile.UUID %>",<% }); %> }<% if (ICLOUD_CONTAINER_ENVIRONMENT) { %>, iCloudContainerEnvironment: "<%- ICLOUD_CONTAINER_ENVIRONMENT %>" <% } %> }) export_xcargs "OTHER_CODE_SIGN_FLAGS=\\"--keychain <%- KEYCHAIN_PATH %>\\"" disable_xcpretty(true) buildlog_path("<%- LOGS_DIRECTORY %>") output_directory("<%- OUTPUT_DIRECTORY %>")

当未传递凭证时使用的默认模板(模拟器构建):

🌐 Default template used when credentials are not passed (simulator build):

Gymfile
suppress_xcode_output(true) clean(<%- CLEAN %>) scheme("<%- SCHEME %>") <% if (BUILD_CONFIGURATION) { %> configuration("<%- BUILD_CONFIGURATION %>") <% } %> derived_data_path("<%- DERIVED_DATA_PATH %>") skip_package_ipa(true) skip_archive(true) destination("<%- SCHEME_SIMULATOR_DESTINATION %>") disable_xcpretty(true) buildlog_path("<%- LOGS_DIRECTORY %>")

CLEAN、SCHEME、BUILD_CONFIGURATION、EXPORT_METHOD、PROFILES、ICLOUD_CONTAINER_ENVIRONMENT、KEYCHAIN_PATH、LOGS_DIRECTORY、OUTPUT_DIRECTORY、DERIVED_DATA_PATH 和 SCHEME_SIMULATOR_DESTINATION 的值会根据输入和 EAS Build 的默认内部配置提供给模板。

example.yml
build: name: Generate Gymfile template steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - eas/configure_eas_update - eas/configure_ios_credentials - eas/generate_gymfile_from_template: inputs: credentials: ${ eas.job.secrets.buildCredentials }
example.yml
build: name: Generate Gymfile template steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/generate_gymfile_from_template

不过,你也可以在模板中使用其他自定义属性,通过在 inputs.template 中指定你的自定义模板,并在 inputs.extra 对象中提供自定义属性的值。

🌐 However, you can also use other custom properties in the template, by specifying your custom template in inputs.template and providing the values for the custom properties in the inputs.extra object.

example.yml
build: name: Generate Gymfile template steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - eas/configure_eas_update - eas/configure_ios_credentials - eas/generate_gymfile_from_template: inputs: credentials: ${ eas.job.secrets.buildCredentials } extra: MY_VALUE: my value template: | suppress_xcode_output(true) clean(<%- CLEAN %>) scheme("<%- SCHEME %>") <% if (BUILD_CONFIGURATION) { %> configuration("<%- BUILD_CONFIGURATION %>") <% } %> export_options({ method: "<%- EXPORT_METHOD %>", provisioningProfiles: {<% _.forEach(PROFILES, function(profile) { %> "<%- profile.BUNDLE_ID %>" => "<%- profile.UUID %>",<% }); %> }<% if (ICLOUD_CONTAINER_ENVIRONMENT) { %>, iCloudContainerEnvironment: "<%- ICLOUD_CONTAINER_ENVIRONMENT %>" <% } %> }) export_xcargs "OTHER_CODE_SIGN_FLAGS=\"--keychain <%- KEYCHAIN_PATH %>\"" disable_xcpretty(true) buildlog_path("<%- LOGS_DIRECTORY %>") output_directory("<%- OUTPUT_DIRECTORY %>") sth_else("<%- MY_VALUE %>")
属性类型必填描述
name-在可重用函数中显示在构建日志中的步骤名称。默认为 Generate Gymfile from template。
inputs.templatestring应该使用的 Gymfile 模板。如果未指定,将根据是否指定了 inputs.credentials 值,从两个默认模板中选择一个使用。
inputs.credentialsjson用于你的 iOS 构建的应用凭证。如果指定,将 KEYCHAIN_PATH、EXPORT_METHOD 和 PROFILES 的值提供给模板。
inputs.build_configurationstringXcode 项目的构建配置。默认是 ${ eas.job.buildConfiguration },如果未指定,对于开发客户端会解析为 Debug,对于其他构建则解析为 Release。对应 BUILD_CONFIGURATION 模板值。
inputs.schemestring应该用于构建的 Xcode 项目方案。默认是 ${ eas.job.scheme },如果未指定,则会解析为 Xcode 项目中找到的第一个方案。对应 SCHEME 模板值。
inputs.cleanboolean是否在构建前清理 Xcode 项目。默认为 true。对应 CLEAN 模板变量。
inputs.extrajson应提供给模板的额外值。
eas/generate_gymfile_from_template 源代码

在 GitHub 上查看 eas/generate_gymfile_from_template 函数的源代码。

eas/run_fastlane

在 ios 项目目录中对位于 Gymfile 的 fastlane gym 命令运行,以构建 iOS 应用。

🌐 Runs fastlane gym command against the Gymfile located in the ios project directory to build the iOS app.

example.yml
build: name: Build iOS app steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - eas/configure_eas_update - eas/configure_ios_credentials - eas/generate_gymfile_from_template: inputs: credentials: ${ eas.job.secrets.buildCredentials } - eas/run_fastlane
example.yml
build: name: Build iOS app steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/generate_gymfile_from_template - eas/run_fastlane
eas/run_fastlane 源代码

在 GitHub 上查看 eas/run_fastlane 函数的源代码。

eas/find_and_upload_build_artifacts

自动从默认位置使用 buildArtifactPaths 配置查找并上传应用归档、额外的构建产物和 Xcode 日志。将找到的产物上传到 EAS 服务器。

🌐 Automatically finds and uploads application archive, additional build artifacts, and Xcode logs from the default locations and using the buildArtifactPaths configuration. Uploads found artifacts to the EAS servers.

example.yml
build: name: Build iOS app steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: clean: false apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - eas/configure_eas_update - eas/configure_ios_credentials - eas/generate_gymfile_from_template: inputs: credentials: ${ eas.job.secrets.buildCredentials } - eas/run_fastlane - eas/find_and_upload_build_artifacts
example.yml
build: name: Build iOS app steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/generate_gymfile_from_template - eas/run_fastlane - eas/find_and_upload_build_artifacts
example.yml
build: name: Build Android app steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/run_gradle - eas/find_and_upload_build_artifacts
eas/find_and_upload_build_artifacts 源代码

在 GitHub 上查看 eas/find_and_upload_build_artifacts 函数的源代码。

eas/upload_embedded_bundle

上传构建生成的应用中的嵌入打包包。EAS 更新然后可以将你稍后发布到同一通道的更新作为补丁来提供。

🌐 Uploads the embedded bundle from the app that the build produced. EAS Update can then serve updates that you publish later to the same channel as patches against it.

eas/build 会在启用上传时为你运行这一步。当你的配置使用单独的步骤构建应用而不是 eas/build 时,你需要自己添加它。把它放在构建应用那一步之后运行,比如 eas/run_gradle 或 eas/run_fastlane。

example.yml
build: name: Build Android app steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/run_gradle - eas/find_and_upload_build_artifacts - eas/upload_embedded_bundle

与 eas/build 不同,这一步不会检查 SDK 版本或 EAS_UPDATE_UPLOAD_EMBEDDED_BUNDLE 和 EAS_UPDATE_EXPERIMENTAL_UPLOAD_EMBEDDED_BUNDLE 环境变量。在这些情况下,它会跳过上传:

🌐 Unlike eas/build, the step does not check the SDK version or the EAS_UPDATE_UPLOAD_EMBEDDED_BUNDLE and EAS_UPDATE_EXPERIMENTAL_UPLOAD_EMBEDDED_BUNDLE environment variables. It skips the upload in these cases:

  • 你的项目中没有配置 EAS 更新。
  • 这个版本是开发版本。
  • 这个构建是一个 iOS 模拟器构建。

这一步会在你的构建配置文件中 applicationArchivePath 设置的位置找到应用。如果没有这个属性,这一步会在默认的构建输出目录中查找。然后,这一步会把 bundle 上传到同一配置文件中的 channel 设置,而不是上传到 eas/configure_eas_update 的 channel 输入。

🌐 The step finds the app at the applicationArchivePath set in your build profile. Without that property, the step looks in the default build output directory. The step uploads the bundle to the channel set in the same profile, not to the channel input of eas/configure_eas_update.

当上传失败时,这一步会导致构建失败。例如,当构建配置文件没有 channel 或者这一步找不到应用时,它就会失败。当 eas/build 运行这一步时,上传失败只会记录一个警告。要在你自己的配置中记录失败并继续构建,请将 ignore_error 设置为 true:

🌐 The step fails the build when the upload fails. For example, it fails when the build profile has no channel or when the step cannot find the app. When eas/build runs the step, an upload failure only logs a warning. To log the failure and continue the build in your own config, set ignore_error to true:

example.yml
build: name: Build Android app steps: # ... - eas/find_and_upload_build_artifacts - eas/upload_embedded_bundle: inputs: ignore_error: true
属性类型必填描述
name-可重用函数中显示在构建日志中的步骤名称。默认为 Upload embedded bundle。
inputs.ignore_errorboolean当 true 时,步骤会记录上传失败,但不会导致构建失败。默认为 false。
eas/upload_embedded_bundle 源代码

在 GitHub 上查看 eas/upload_embedded_bundle 函数的源代码。

eas/upload_artifact

将作业工作区中的文件作为附件上传到运行的工件中。上传的工件会出现在运行的 Artifacts 部分,并可以在后续作业中通过 eas/download_artifact 检索。

🌐 Uploads files from the job's workspace as an artifact attached to the run. Uploaded artifacts appear in the run's Artifacts section and can be retrieved in a later job with eas/download_artifact.

upload.yml
build: name: Upload artifacts steps: - eas/checkout # - ... - eas/upload_artifact: name: Upload application archive inputs: path: fixtures/app-debug.apk - eas/upload_artifact: name: Upload artifacts inputs: type: build-artifact path: | assets/*.jpg assets/*.png
属性类型是否必填描述
pathstring要上传的路径或以换行分隔的路径列表。支持 * 及其他 glob 模式。
typestring构件类型。在自定义任务中使用 other(通用构件)。当任务没有构建平台时默认为 other,构建任务中默认为 application-archive。构建范围的值 application-archive 和 build-artifact 仅在构建任务中有效。
namestring构件名称,用于在 eas/download_artifact 中引用它。
metadatajson附加到通用(other)构件的任意元数据。
ignore_errorboolean当 true 时,上传失败会记录,但不会导致步骤失败。默认值为 false。
输出

🌐 Outputs

属性类型描述
artifact_id字符串已上传工件的 ID。可以传递给 eas/download_artifact。
eas/upload_artifact 源代码

在 GitHub 上查看 eas/upload_artifact 函数的源代码。

eas/install_maestro

确保已安装 Maestro 移动端 UI 测试框架及其所有依赖。

🌐 Makes sure Maestro, the mobile UI testing framework, is installed along with all its dependencies.

build-and-test.yml
build: name: Build and test steps: - eas/build # ... simulator/emulator setup - eas/install_maestro: inputs: maestro_version: 1.35.0 - run: command: maestro test flows/signin.yml - eas/upload_artifact: name: Upload Maestro artifacts inputs: type: build-artifact path: ${ eas.env.HOME }/.maestro/tests
输入类型必填描述
maestro_versionstring要安装的 Maestro 版本(例如 1.35.0)。如果未提供,install_maestro 会安装最新版本。
eas/install_maestro 源代码

在 GitHub 上查看 eas/install_maestro 函数的源代码。

eas/start_android_emulator

启动一个 Android 模拟器,你可以用它来测试你的应用。仅在运行 Android 构建时可用。

🌐 Starts an Android Emulator you can use to test your apps on. Only available when running a build for Android.

build-and-test.yml
build: name: Build and test steps: - eas/build - eas/start_android_emulator: inputs: system_image_package: system-images;android-30;default;x86_64 # ... Maestro setup and tests
输入类型是否必填描述
device_namestring创建设备的名称。如果启动多个模拟器,可以自定义。
system_image_packagestring模拟器使用的 Android 包路径。例如,system-images;android-30;default;x86_64。
要获取可用系统镜像的列表,在本地计算机上运行 sdkmanager --list。虚拟机运行在 x86_64 架构上,所以始终选择 x86_64 包变体。sdkmanager 工具 来自 Android SDK 命令行工具。
eas/start_android_emulator 源代码

在 GitHub 上查看 eas/start_android_emulator 函数的源代码。

eas/start_ios_simulator

启动一个可以用来测试应用的 iOS 模拟器。仅在运行 iOS 构建时可用。

🌐 Starts an iOS Simulator you can use to test your apps on. Only available when running a build for iOS.

build-and-test.yml
build: name: Build and test steps: - eas/build - eas/start_ios_simulator # ... Maestro setup and tests
输入类型必填描述
device_identifierstring你想启动的模拟器的名称或 UDID。例如 iPhone [XY] Pro、AEF997BB-222C-4379-89BA-D21070B1D787。
注意: 每个镜像可用的模拟器不同。如果你更换镜像,某个名字对应的模拟器可能无法使用。例如,Xcode 14 镜像会有 iPhone 14 模拟器,而 Xcode 15 镜像会有 iPhone 15 模拟器。一般来说,我们建议不要提供这个输入。更多信息请参见 runner images。
eas/start_ios_simulator 源代码

在 GitHub 上查看 eas/start_ios_simulator 函数的源代码。

eas/send_slack_message

向配置的 Slack webhook URL 发送指定消息,然后它会将消息发布到相关的 Slack 通道。消息可以以纯文本形式指定,也可以以 Slack Block Kit 消息形式指定。

🌐 Sends a specified message to a configured Slack webhook URL, which then posts it in the related Slack channel. The message can be specified as plaintext or as a Slack Block Kit message.

你可以在消息中引用构建作业属性并使用其他步骤的输出进行动态评估。例如,'Build URL: ${ eas.job.expoBuildUrl }'、Build finished with status: ${ steps.run_fastlane.status_text }、Build failed with error: ${ steps.run_gradle.error_text }。

🌐 You can reference build job properties and use other steps outputs in the message for dynamic evaluation. For example, 'Build URL: ${ eas.job.expoBuildUrl }', Build finished with status: ${ steps.run_fastlane.status_text }, Build failed with error: ${ steps.run_gradle.error_text }.

send-slack-message.yml
build: name: Slack your team from custom build steps: - eas/send_slack_message: name: Send Slack message to a given webhook URL inputs: message: 'This is a message to plain input URL' slack_hook_url: 'https://hooks.slack.com/services/[rest_of_hook_url]' - eas/send_slack_message: name: Send Slack message to a default webhook URL from SLACK_HOOK_URL secret inputs: message: 'This is a test message to default URL from SLACK_HOOK_URL secret' - eas/send_slack_message: name: Send Slack message to a webhook URL from specified secret inputs: message: 'This is a test message to a URL from specified secret' slack_hook_url: ${ eas.env.ANOTHER_SLACK_HOOK_URL } - eas/build - eas/send_slack_message: if: ${ always() } name: Send Slack message when the build finishes (Android) inputs: message: | This is a test message when Android build finishes Status: `${ steps.run_gradle.status_text }` Link: `${ eas.job.expoBuildUrl }` - eas/send_slack_message: if: ${ always() } name: Send Slack message when the build finishes (iOS) inputs: message: | This is a test message when iOS build finishes Status: `${ steps.run_fastlane.status_text }` Link: `${ eas.job.expoBuildUrl }` - eas/send_slack_message: if: ${ failure() } name: Send Slack message when the build fails (Android) inputs: message: | This is a test message when Android build fails Error: `${ steps.run_gradle.error_text }` - eas/send_slack_message: if: ${ failure() } name: Send Slack message when the build fails (iOS) inputs: message: | This is a test message when iOS build fails Error: `${ steps.run_fastlane.error_text }` - eas/send_slack_message: if: ${ success() } name: Send Slack message when the build succeeds inputs: message: | This is a test message when build succeeds - eas/send_slack_message: if: ${ always() } name: Send Slack message with Slack Block Kit layout inputs: payload: blocks: - type: section text: type: mrkdwn text: |- Hello, Sir Developer *Your build has finished!* - type: divider - type: section text: type: mrkdwn text: |- *${ eas.env.EAS_BUILD_ID }* *Status:* `${ steps.run_gradle.status_text }` *Link:* `${ eas.job.expoBuildUrl }` accessory: type: image image_url: [your_image_url] alt_text: alt text for image - type: divider - type: actions elements: - type: button text: type: plain_text text: 'Do a thing :rocket:' emoji: true value: a_thing - type: button text: type: plain_text text: 'Do another thing :x:' emoji: true value: another_thing
属性类型描述
messagestring你想要发送的消息文本。例如,'This is the content of the message'。

注意: 需要提供 message 或 payload 中的一个,但不能同时提供。
payloadjson你想要发送的消息内容,使用 Slack Block Kit 布局定义。

注意: 需要提供 message 或 payload 中的一个,但不能同时提供。
slack_hook_urlstring先前配置的 Slack Webhook URL,它将把你的消息发送到指定通道。使用 EAS 环境变量 提供,例如 slack_hook_url: ${{ env.ANOTHER_SLACK_HOOK_URL }},或设置 SLACK_HOOK_URL 环境变量,作为默认的 webhook URL(在这种情况下,无需提供 slack_hook_url 属性)。
eas/send_slack_message 源代码

在 GitHub 上查看 eas/send_slack_message 函数的源代码。

以下函数可将你的构建连接到 PostHog。运行 eas integrations:posthog:connect 来关联一个 PostHog 项目并设置这些函数读取的环境变量。eas/posthog_capture_event 使用你的公共项目 API 密钥,而其他函数使用带有各自权限范围的 PostHog 个人 API 密钥。有关设置,请参阅 使用 PostHog,有关完整工作流程,请参阅 EAS 工作流程的 PostHog 使用示例。

🌐 The following functions connect your build to PostHog. Run eas integrations:posthog:connect to link a PostHog project and set the environment variables these functions read. eas/posthog_capture_event uses your public project API key, while the other functions use a PostHog personal API key with the scopes noted for each one. For setup, see Using PostHog, and for complete workflows, see PostHog recipes for EAS Workflows.

eas/posthog_capture_event

向 PostHog 发送一个分析事件。用它来标记你的构建、发布以及 PostHog 时间线上的其他重要节点。

🌐 Sends an analytics event to PostHog. Use it to mark builds, releases, and other milestones on your PostHog timeline.

当你不提供 distinct_id 时,事件会以匿名方式发送,并且不会创建 PostHog 的 用户档案。

🌐 When you do not provide a distinct_id, the event is sent anonymously and does not create a PostHog person profile.

posthog-capture-event.yml
build: name: Build and mark the release in PostHog steps: - eas/build - eas/posthog_capture_event: name: Capture a PostHog event inputs: event: store_build_finished properties: platform: ios profile: production
属性类型必填描述
eventstring要发送的事件名称。
distinct_idstring归属该事件的人。省略时,事件以匿名方式发送,并且不会创建人员档案。
propertiesjson需要附加到事件的属性。
api_keystringPostHog 项目 API 密钥。默认使用 eas integrations:posthog:connect 设置的 EXPO_PUBLIC_POSTHOG_API_KEY 环境变量,如果没有设置则使用 POSTHOG_API_KEY。
hoststringPostHog 主机。默认使用 EXPO_PUBLIC_POSTHOG_HOST 环境变量,或 https://us.posthog.com。
ignore_errorboolean当 true 时,发送事件失败会被记录,但不会导致步骤失败。默认值为 false。
eas/posthog_capture_event 源代码

在 GitHub 上查看 eas/posthog_capture_event 函数的源代码。

eas/posthog_flag_rollout

启用、禁用或推出一个 PostHog 功能标志。该函数通过键查找标志,然后更新它。至少提供 active、rollout_percentage 或 payload 中的一个。

🌐 Enables, disables, or rolls out a PostHog feature flag. The function looks up the flag by key and then updates it. Provide at least one of active, rollout_percentage, or payload.

posthog-flag-rollout.yml
build: name: Roll out a PostHog feature flag steps: - eas/posthog_flag_rollout: name: Roll out the flag to 25 percent inputs: flag: new-checkout rollout_percentage: 25
属性类型必填描述
flag字符串要更新的功能标志的键。
active布尔型标志是否启用。
rollout_percentage数字将该标志推出给用户的百分比,以从 0 到 100 的整数表示。该函数将其应用于标志的通用发布条件,并保留其他条件。当标志没有通用条件时,该函数将其应用于第一个条件。
payloadjson要附加到标志的有效负载。
variant字符串用于多变量标志的变体键,用于存储 payload。默认使用标志的 true 负载。
api_key字符串PostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要 feature_flag:read 和 feature_flag:write 权限范围。
project_id字符串PostHog 项目 ID。默认使用 POSTHOG_CLI_PROJECT_ID 环境变量。
ignore_error布尔值当 true、网络错误、缺少标志或意外响应被记录但不会导致步骤失败时。默认为 false。权限错误或无效输入(例如超出范围的 rollout_percentage)总是会导致步骤失败。
eas/posthog_flag_rollout 源代码

在 GitHub 上查看 eas/posthog_flag_rollout 函数的源代码。

eas/posthog_wait_for_metric

暂停直到 HogQL 查询返回一个满足比较的数字。可以用它来根据某个指标做判断,比如等到最近几分钟的错误数量保持较低。这个函数每隔 interval_seconds 运行一次查询,直到比较为真或 timeout_seconds 时间过去。

🌐 Pauses until a HogQL query returns a number that satisfies a comparison. Use it to gate on a metric, such as holding until the error count over the last few minutes stays low. The function runs the query every interval_seconds until the comparison is true or timeout_seconds elapses.

posthog-wait-for-metric.yml
build: name: Gate on the error count steps: - eas/posthog_wait_for_metric: name: Wait for the error count to stay low inputs: query: SELECT count() FROM events WHERE event = '$exception' AND timestamp > now() - INTERVAL 15 MINUTE operator: lt threshold: 10
属性类型必填描述
querystring一个 HogQL 查询。第一行的第一列必须是一个数字
operatorstring比较运算符。可以是 lt、lte、gt、gte 或 eq。当 value <operator> threshold 为真时,步骤会清除
thresholdnumber用来与查询结果进行比较的值
timeout_secondsnumber最大等待时间,单位秒。默认为 600
interval_secondsnumber检查间隔时间,单位秒。默认为 30
api_keystringPostHog 个人 API 密钥。默认为环境变量 POSTHOG_CLI_API_KEY。需要 query:read 权限
project_idstringPostHog 项目 ID。默认为环境变量 POSTHOG_CLI_PROJECT_ID
输出

🌐 Outputs

属性类型描述
value字符串满足比较的度量值。
eas/posthog_wait_for_metric 源代码

在 GitHub 上查看 eas/posthog_wait_for_metric 函数的源代码。

eas/posthog_wait_for_query

暂停,直到 HogQL 查询返回 true。当条件在查询中更容易表达时使用。对于带有明确阈值的数值比较,请改用 eas/posthog_wait_for_metric。当第一行第一列为 true 或非零数字时,该步骤会清除。

🌐 Pauses until a HogQL query returns true. Use it when the condition is easier to express in the query itself. For a numeric comparison with an explicit threshold, use eas/posthog_wait_for_metric instead. The step clears when the first column of the first row is true or a nonzero number.

posthog-wait-for-query.yml
build: name: Wait for a smoke test event steps: - eas/posthog_wait_for_query: name: Wait for the smoke test to pass inputs: query: SELECT count() > 0 FROM events WHERE event = 'smoke_test_passed' AND timestamp > now() - INTERVAL 30 MINUTE
属性类型必填描述
querystring一个 HogQL 查询。当第一行第一列是 true 或非零数字时,该步骤会被清除。
timeout_secondsnumber最大等待时间,单位为秒。默认值为 600。
interval_secondsnumber检查间隔时间,单位为秒。默认值为 30。
api_keystringPostHog 个人人 API 密钥。默认使用 POSTHOG_CLI_API_KEY 环境变量。需要 query:read 权限范围。
project_idstringPostHog 项目 ID。默认使用 POSTHOG_CLI_PROJECT_ID 环境变量。
eas/posthog_wait_for_query 源代码

在 GitHub 上查看 eas/posthog_wait_for_query 函数的源代码。

eas/posthog_annotation

在项目时间线上创建一个 PostHog 注释。注释会显示在你的 PostHog 图表上,这样它们就可以用来在受影响的指标旁标记构建、发布和其他里程碑。

🌐 Creates a PostHog annotation on the project timeline. Annotations show up on your PostHog charts, which makes them useful for marking builds, releases, and other milestones next to the metrics they affect.

posthog-annotation.yml
build: name: Annotate the release in PostHog steps: - eas/posthog_annotation: name: Create a PostHog annotation inputs: content: Published a production build
属性类型是否必填描述
content字符串注释文本。
date_marker字符串注释关联的 ISO 8601 时间戳。默认是当前时间。
api_key字符串PostHog 个人 API 密钥。默认使用 POSTHOG_CLI_API_KEY 环境变量。需要 annotation:write 权限。
project_id字符串PostHog 项目 ID。默认使用 POSTHOG_CLI_PROJECT_ID 环境变量。
ignore_error布尔值当 true 时,网络错误或意外响应会被记录,但不会导致步骤失败。默认是 false。权限错误总是会导致步骤失败。
eas/posthog_annotation 源代码

在 GitHub 上查看 eas/posthog_annotation 函数的源代码。

eas/posthog_upload_sourcemaps

将 JavaScript 源映射上传到 PostHog,以便 PostHog 在错误跟踪中符号化堆栈跟踪。在生成 bundle 的步骤之后,在同一个任务中运行它,这样 bundle 和源映射就会保存在磁盘上。使用 npx expo export --source-maps 导出,并根据源映射指南配置 PostHog 的 Metro 配置,这样 bundle 就会包含与其源映射匹配的 chunk ID。

🌐 Uploads JavaScript source maps to PostHog so that PostHog symbolicates stack traces in error tracking. Run it after the step that produces your bundle, in the same job, so the bundle and source maps are available on disk. Export with npx expo export --source-maps, and configure the PostHog Metro config from the Source maps guide so bundles carry the chunk IDs that match them to their source maps.

posthog-upload-sourcemaps.yml
build: name: Export and upload source maps steps: - eas/checkout - eas/install_node_modules - run: name: Export the bundle and source maps command: npx expo export --source-maps --platform ios - eas/posthog_upload_sourcemaps: name: Upload source maps to PostHog inputs: directory: dist
属性类型是否必填描述
directory字符串包含打包包和源映射的目录,相对于工作目录。默认值为 dist。
api_key字符串PostHog 个人 API 密钥。默认使用 POSTHOG_CLI_API_KEY 环境变量。需要源映射上传权限。
project_id字符串PostHog 项目 ID。默认使用 POSTHOG_CLI_PROJECT_ID 环境变量。
ignore_error布尔值当 true 时,上传失败会记录日志但不会导致步骤失败。默认值为 false。
eas/posthog_upload_sourcemaps 源代码

在 GitHub 上查看 eas/posthog_upload_sourcemaps 函数的源代码。

使用内置的 EAS 功能构建应用

🌐 Using built-in EAS functions to build an app

使用内置的 EAS 功能,你可以为不同的构建类型重新创建默认的 EAS 构建过程。

🌐 Using the built-in EAS functions you can recreate the default EAS Build process for different build types.

例如,要触发一个为 Android 创建内部分发构建并为 iOS 创建模拟器构建的构建,你可以使用以下配置:

🌐 For example, to trigger a build that creates internal distribution build for Android and a simulator build for iOS you can use the following configuration:

eas.json
{ %%placeholder-start%%... %%placeholder-end%% "build": { %%placeholder-start%%... %%placeholder-end%% "developmentBuild": { "distribution": "internal", "android": { "config": "development-build-android.yml" }, "ios": { "simulator": true, "config": "development-build-ios.yml" } } %%placeholder-start%%... %%placeholder-end%% } %%placeholder-start%%... %%placeholder-end%% }
.eas/build/development-build-android.yml
build: name: Simple internal distribution Android build steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/inject_android_credentials - eas/run_gradle - eas/find_and_upload_build_artifacts
.eas/build/development-build-ios.yml
build: name: Simple simulator iOS build steps: - eas/checkout - eas/install_node_modules - eas/prebuild - run: name: Install pods working_directory: ./ios command: pod install - eas/generate_gymfile_from_template - eas/run_fastlane - eas/find_and_upload_build_artifacts

要为 Android 创建 Google Play 商店版本并为 iOS 创建 Apple App Store 版本,你可以使用以下配置:

🌐 To create a Google Play Store build for Android and an Apple App Store build for iOS you can use the following configuration:

eas.json
{ %%placeholder-start%%... %%placeholder-end%% "build": { %%placeholder-start%%... %%placeholder-end%% "productionBuild": { "android": { "config": "production-build-android.yml" }, "ios": { "config": "production-build-ios.yml" } } %%placeholder-start%%... %%placeholder-end%% } %%placeholder-start%%... %%placeholder-end%% }
.eas/build/production-build-android.yml
build: name: Customized Android Play Store build example steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/inject_android_credentials - eas/run_gradle - eas/find_and_upload_build_artifacts
.eas/build/production-build-ios.yml
build: name: Customized iOS App Store build example steps: - eas/checkout - eas/install_node_modules - eas/resolve_apple_team_id_from_credentials: id: resolve_apple_team_id_from_credentials - eas/prebuild: inputs: apple_team_id: ${ steps.resolve_apple_team_id_from_credentials.apple_team_id } - run: name: Install pods working_directory: ./ios command: pod install - eas/configure_ios_credentials - eas/generate_gymfile_from_template: inputs: credentials: ${ eas.job.secrets.buildCredentials } - eas/run_fastlane - eas/find_and_upload_build_artifacts

查看 示例仓库 以获取更详细的示例:

🌐 Check out the example repository for more detailed examples:

自定义构建示例存储库

一个自定义 EAS 构建示例,其中包含自定义构建的示例,如设置函数、使用环境变量、上传工件等。

在 build 中使用可重用函数

🌐 Use a reusable function in a build

例如,一个自定义构建配置包含以下可重用函数,其中包含一个用于打印回显消息的命令。

🌐 For example, a custom build config with the following reusable function contains a single command to print a message that is echoed.

functions: greetings: - name: name default_value: Hello world inputs: [value] command: echo "${ inputs.name }, { inputs.value }"

上述函数可以在 build 中如下使用:

🌐 The above function can be used in a build as follows:

build: name: Functions Demo steps: - greetings: inputs: value: Expo

在 build 中覆盖值

🌐 Override values in a build

你可以覆盖以下属性的值:

🌐 You can override values for the following properties:

  • working_directory
  • name
  • shell

例如,一个名为 list_files 的可重用函数:

🌐 For example, a reusable function called list_files:

functions: list_files: name: List files command: ls -la

当在构建配置中调用 list_files 时,它会列出项目根目录中的所有文件:

🌐 When list_files is called in a build config, it lists all files in the root directory of a project:

build: name: List files steps: - eas/checkout - list_files

你可以使用 working_directory 属性来覆盖函数调用的行为,通过指定目录的路径来列出不同目录中的文件:

🌐 You can use the working_directory property to override the behavior in the function call to list the files in a different directory by specifying the path to that directory:

build: name: List files steps: - eas/checkout - list_files: working_directory: /a/b/c