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

自定义构建配置 schema

编辑页面

EAS Build 自定义构建的配置选项参考。


为 EAS Build 创建自定义构建有助于为你的项目定制构建流程。

用于自定义构建的 YAML 语法

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

build

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

name

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

例如,构建名称为 Run tests

build: name: Run tests steps: - eas/checkout - run: name: 安装依赖 command: npm install

steps

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

每个步骤都使用以下属性进行配置:

steps[].run

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

build: name: 安装 npm 依赖 steps: - eas/checkout - run: name: 安装依赖 command: npm install

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

build: name: 运行内联 shell 命令 steps: - run: echo "Hello world" - run: | echo "Multiline" echo "bash commands"

使用单个步骤

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

build: name: 问候 steps: - run: echo "Hello world"

使用多个步骤

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

build: name: 运行测试 steps: - eas/checkout - run: name: 安装依赖 command: npm install - run: name: 运行测试 command: | echo "Running tests..." npm test

与其他步骤共享环境变量

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

set-env 需要接收两个参数:环境变量名和值。例如,set-env NPM_TOKEN "abcdef" 会将值为 abcdef$NPM_TOKEN 变量暴露给其他步骤。

build: name: 共享环境变量示例 steps: - run: name: 设置环境变量 command: | set -x # 设置变量 ENV_TEST_LOCAL="仅存在于当前 shell 上下文中" # 设置并导出变量 export ENV_TEST_LOCAL_EXPORT="存在于当前步骤中" # 设置共享变量 set-env ENV_TEST_SET_ENV "存在于后续步骤中" # 将打印 "ENV_TEST_LOCAL: 仅存在于当前 shell 上下文中" # 因为当前 shell 可以访问这个本地变量。 echo "ENV_TEST_LOCAL: $ENV_TEST_LOCAL" # 将打印 "ENV_TEST_LOCAL_EXPORT: 存在于当前步骤中" # 因为 export 也会设置本地变量值。 echo "ENV_TEST_LOCAL_EXPORT: $ENV_TEST_LOCAL_EXPORT" # 将打印 "ENV_TEST_SET_ENV: " # 因为 set-env 不会设置或导出变量。 echo "ENV_TEST_SET_ENV: $ENV_TEST_SET_ENV" # 只会打印 LOCALLY_EXPORTED_ENV, # 因为它是唯一被导出的变量。 env | grep ENV_TEST_ - run: name: 在下一步中检查变量值 command: | set -x # 将打印 "ENV_TEST_LOCAL: ",因为 ENV_TEST_LOCAL # 只是前一步中的本地变量。 echo "ENV_TEST_LOCAL: $ENV_TEST_LOCAL" # 将打印 "ENV_TEST_LOCAL_EXPORT: " # 因为 export 不会将变量共享给其他步骤。 echo "ENV_TEST_LOCAL_EXPORT: $ENV_TEST_LOCAL_EXPORT" # 将打印 "ENV_TEST_SET_ENV: 存在于后续步骤中" # 因为 set-env 已将变量“导出”给其他步骤。 echo "ENV_TEST_SET_ENV: $ENV_TEST_SET_ENV" # 只会打印 ENV_TEST_SET_ENV, # 因为 set-env 已将它“导出”给其他步骤。 env | grep ENV_TEST_

steps[].run.name

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

steps[].run.command

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

build: name: 运行测试 steps: - eas/checkout - run: name: 运行测试 command: | echo "Running tests..." npm test

steps[].run.working_directory

working_directory 用于定义项目根目录下的一个现有目录。在步骤中定义了现有路径后,使用它会改变该步骤的当前目录。例如,创建一个步骤来列出 assets 目录中的所有资源文件,该目录是你的 Expo 项目中的一个目录。working_directory 被设置为 assets

build: name: 演示 steps: - eas/checkout - run: name: 列出资源文件 working_directory: assets command: ls -la

steps[].run.shell

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

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

steps[].run.inputs

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

build: name: 演示 steps: - run: name: 打招呼 inputs: name: Expo command: echo "Hi, ${ inputs.name }!"

steps[].run.outputs

步骤执行期间会产生一个输出值。例如,一个步骤的输出值为 Hello world

build: name: 演示 steps: - run: name: 生成输出 outputs: [value] command: | echo "Producing output for another step" set-output value "来自另一个步骤的输出..."

steps[].run.outputs.required

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

build: name: 演示 steps: - run: name: 生成另一个输出 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 允许:

  • 多次调用产生一个或多个输出的同一个函数
  • 将一个步骤的输出用于另一个步骤

多次调用同一个函数

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

functions: random: name: 生成随机数 outputs: [value] command: set-output value `random_number`

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

build: name: 函数演示 steps: - random: id: random_1 - random: id: random_2 - run: name: 打印随机数 inputs: random_1: ${ steps.random_1.value } random_2: ${ steps.random_2.value } command: | echo "${ inputs.random_1 }" echo "${ inputs.random_2 }"

将一个步骤的输出用于另一个步骤

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

build: name: 输出演示 steps: - run: name: 生成输出 id: id123 # <---- !!! outputs: [foo] command: | echo "Producing output for another step" set-output foo bar - run: name: 使用另一个步骤的输出 inputs: foo: ${ steps.id123.foo } command: | echo "foo = \"${ inputs.foo }\""

functions

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

functions.[function_name]

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

functions: greetings: name: 你好!

functions.[function_name].name

用于构建日志中显示函数名称的名称。例如,一个显示名称为 你好! 的函数:

functions: greetings: name: 你好!

functions.[function_name].inputs

输入值会提供给一个函数。

inputs[].name

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

functions: greetings: name: 说你好! inputs: - name: name default_value: 你好,世界 command: echo "${ inputs.name }!"

inputs[].required

布尔值,表示输入值是否必填。例如,一个函数没有必填值:

functions: greetings: name: 说你好! inputs: - name: name required: false

inputs[].type

输入值的类型。它可以是 stringnumjson

在函数调用中设置的输入值,以及函数的 default_valueallowed_values 都会根据该类型进行验证。

默认的输入 typestring

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

functions: greetings: name: 说你好! inputs: - name: name type: string - name: age type: num - name: other_data type: json

inputs[].default_value

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

functions: greetings: name: 说你好! inputs: - name: name default_value: 你好,世界

inputs[].allowed_values

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

functions: greetings: name: 说你好! inputs: - name: name default_value: 你好,世界 allowed_values: [Hi, Hello, Hey] type: string

多个输入值

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

functions: greetings: name: 说你好! 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

functions: greetings: name: 说你好! outputs: [value] command: set-output value "Hello world"

outputs[].name

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

functions: greetings: name: 说你好! outputs: - name: name

outputs[].required

布尔值,表示输出值是否必填。例如,一个函数没有必填的输出值:

functions: greetings: name: 说你好! outputs: - name: value required: false

functions.[function_name].command

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

functions: greetings: name: 说你好! command: echo "你好!"

functions.[function_name].path

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

functions: greetings: name: 说你好! path: ./greetings

functions.[function_name].shell

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

functions: greetings: name: 说你好! shell: /bin/sh command: echo "你好!"

functions.[function_name].supported_platforms

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

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

functions: greetings: name: 说你好! supported_platforms: [darwin] command: echo "你好!"

import

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

例如,下面的构建配置导入了两个文件,并调用了两个导入的函数——say_hisay_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: 说你好! command: echo "你好!"
another-file.yml
functions: say_bye: name: 说再见 :( command: echo "再见!"

函数

内置 EAS 函数

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

eas/build

一个集成式函数,封装整个 EAS Build 的构建流程。它会根据你的构建配置文件 eas.json 中的构建配置来解析出最佳构建方案。

对于那些希望无需手动调整和配置构建流程就能完成构建的人来说,它非常理想。如果你希望在构建前后添加其他自定义步骤,但又不想改变构建流程本身,它也可以作为自定义构建配置的良好起点。

example.yml
build: name: 使用单个命令运行构建 steps: - eas/build

如果你希望对构建流程有更多控制,并根据需求进行自定义,可以查看下面这些由 eas/build 在后台执行的自定义函数和步骤。它们会根据你的构建配置作为构建流程执行。

Android

当构建配置使用 withoutCredentials 时:

当构建配置使用凭据时(适用于 internalstore distribution 构建):

iOS

当构建配置使用 withoutCredentialssimulator 时:

当构建配置使用凭据时(适用于 internalstore distribution 构建):

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

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 构建中幕后执行的步骤。

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

eas/maestro_test

一个集成式函数,用于安装 Maestro、准备测试环境(Android Emulator 或 iOS Simulator),并测试应用。

InputTypeRequiredDescription
flow_pathstringPath (or multiple paths, each in a separate line) to Maestro flows to run.
app_pathstringPath (or regex pattern) to the emulator/simulator app that should be tested. If not provided, it defaults to android/app/build/outputs/**/*.apk for Android and to ios/build/Build/Products/*simulator/*.app for iOS.
build-and-test.yml
build: name: 构建并测试 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: 构建并测试 iOS 模拟器应用 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: 构建并测试 Android 模拟器应用 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

其幕后会使用:

如果你需要自定义 Maestro 版本、运行特定的 Android Emulator 或 iOS Simulator,或者上传多个构建产物,就需要自行编写这组步骤。

`eas/maestro_test` 展开后的 Android 构建配置示例
build-and-test-android-expanded.yml
build: name: 构建并测试(Android,展开后) 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 是添加 /**/ 支持所必需的 shopt -s globstar # shopt -s nullglob 是为了避免在没有匹配文件时 # 直接尝试安装 SEARCH_PATH 字面值。 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: 上传测试产物 if: ${ always() } inputs: type: build-artifact path: ${ eas.env.HOME }/.maestro/tests
`eas/maestro_test` 展开后的 iOS 构建配置示例
build-and-test-ios-expanded.yml
build: name: 构建并测试(iOS,展开后) steps: - eas/build - eas/install_maestro - eas/start_ios_simulator - run: command: | # shopt -s nullglob 是为了避免在没有匹配文件时 # 直接尝试安装 SEARCH_PATH 字面值。 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: 上传测试产物 if: ${ always() } inputs: type: build-artifact path: ${ eas.env.HOME }/.maestro/tests
eas/maestro_test 源代码

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

eas/checkout

检出你的项目源文件。

upload.yml
build: name: 列出文件 steps: - eas/checkout - run: name: 列出 assets run: ls assets

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 accepts:

  • A branch, as a bare name such as feature/add-icon or a qualified ref such as refs/heads/feature/add-icon. The repository ends up on that branch.
  • A tag, as a qualified ref such as refs/tags/v1.2.3. The repository ends up on a detached HEAD.
  • A full commit SHA. The repository ends up on a detached HEAD.

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。默认为触发构建或工作流任务的 ref。
eas/checkout 源代码

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

eas/use_npm_token

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

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: 安装私有 npm 模块 steps: - eas/checkout - eas/use_npm_token - run: name: 安装依赖 run: npm install # <---- 现在可以安装私有包了
eas/use_npm_token 源代码

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

eas/install_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: 安装 node 模块 steps: - eas/checkout - eas/install_node_modules
eas/install_node_modules 源代码

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

eas/restore_build_cache

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

example.yml
build: name: 使用缓存构建 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: 使用缓存构建 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/restore_build_cache: inputs: key: cache-${{ hashFiles('package-lock.json') }} path: /path/to/cache
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Restore build cache.
inputs.keystringThe cache key to restore. You can use expressions like ${{ hashFiles('package-lock.json') }} to create dynamic keys based on file hashes.
inputs.restore_keysstringA fallback key or prefix to use if the exact key is not found. If provided, the cache system will look for any cache entry that starts with this prefix.
inputs.pathstringThe path where the cache should be restored. This should match the path used when saving the cache.
eas/restore_build_cache 源代码

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

eas/save_build_cache

将构建缓存保存到指定的 key。这使你能够持久化构建产物、编译后的依赖或其他中间输出,以便在后续构建中复用,从而加快构建流程。

example.yml
build: name: 使用缓存构建 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
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Save build cache.
inputs.keystringThe cache key to save the cache under. You can use expressions like ${{ hashFiles('package-lock.json') }} to create dynamic keys based on file hashes. This should match the key used when restoring the cache.
inputs.pathstringThe path to the directory or files that should be cached. This should match the path used when restoring the cache.
eas/save_build_cache 源代码

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

eas/resolve_build_config

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

该函数会被 eas/build 函数组自动执行。

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 team ID 值。解析得到的 Apple team ID 会存储在 outputs.apple_team_id 输出值中。

example.yml
build: name: 运行 prebuild 脚本 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 }
PropertyTypeRequiredDescription
namestringThe name of the step in the reusable function that shows in the build logs. Defaults to Resolve Apple team ID from credentials.
inputs.credentialsjsonThe app credentials for your iOS build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for iOS.
eas/resolve_apple_team_id_from_credentials 源代码

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

eas/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: 运行 prebuild 脚本 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: 运行 prebuild 脚本 steps: - eas/checkout - eas/install_node_modules - eas/prebuild
属性类型描述
cleanboolean可选属性,用于定义函数运行命令时是否应使用 --clean 标志。默认为 false。
apple_team_idstring可选属性,用于定义执行预构建时应使用的 Apple 团队 ID。使用凭据进行 iOS 构建时必须指定此属性。
eas/prebuild 源代码

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

eas/configure_eas_update

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

example.yml
build: name: 配置 EAS Update steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update
example.yml
build: name: 配置 EAS Update steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update: inputs: runtime_version: 1.0.0 channel: mychannel
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Configure EAS Update.
inputs.runtime_versionstringRuntime version which should be configured for the build. Defaults to ${ eas.job.version.runtimeVersion } or natively defined runtime version.
inputs.channelstringChannel which should be configured for the build. Defaults to ${ eas.job.updates.channel }.
eas/configure_eas_update 源代码

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

eas/inject_android_credentials

在构建机上使用凭据配置 Android keystore,并使用这些凭据将应用签名配置注入 gradle 配置中。

example.yml
build: name: Android 凭据 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/inject_android_credentials
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Inject Android credentials.
inputs.credentialsjsonThe app credentials for your Android build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for Android.
eas/inject_android_credentials 源代码

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

eas/configure_ios_credentials

在构建机上配置 iOS 凭据。通过将 provisioning profiles 分配给各个 targets 来修改 Xcode 项目的配置。

example.yml
build: name: iOS 凭据 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
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Configure iOS credentials.
inputs.build_configurationstringThe Xcode project's Build Configuration. Defaults to ${ eas.job.buildConfiguration } or if not specified is resolved to Debug for development client or Release for other builds.
inputs.credentialsjsonThe app credentials for your iOS build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for iOS.
eas/configure_ios_credentials 源代码

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

eas/configure_android_version

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

如果不使用此函数也没关系;如果未使用,则会采用 prebuild 阶段生成的原生代码中的版本。

example.yml
build: name: 配置 Android 版本 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: 配置 Android 版本 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'
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Configure Android version.
inputs.version_codestringversionCode of your Android build. Defaults to ${ eas.job.version.versionCode }.
inputs.version_namestringversionName of your Android build. Defaults to ${ eas.job.version.versionName }.
eas/configure_android_version 源代码

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

eas/configure_ios_version

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

如果不使用此函数也没关系;如果未使用,则会采用 prebuild 阶段生成的原生代码中的版本。

example.yml
build: name: 配置 iOS 版本 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: 配置 iOS 版本 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'
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Configure iOS version.
inputs.build_numberstringThe build number (CFBundleVersion) of your iOS build. Defaults to ${ eas.job.version.buildNumber }.
inputs.app_versionstringThe app version (CFBundleShortVersionString) of your iOS build. Defaults to ${ eas.job.version.appVersion }.
inputs.build_configurationstringThe Xcode project's Build Configuration. Defaults to ${ eas.job.buildConfiguration } or if not specified is resolved to Debug for development client or Release for other builds.
inputs.credentialsjsonThe app credentials for your iOS build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for iOS.
eas/configure_ios_version 源代码

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

eas/run_gradle

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

example.yml
build: name: 构建 Android 应用 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/run_gradle
example.yml
build: name: 构建 Android 应用 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/run_gradle: inputs: command: :app:bundleRelease
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Run gradle.
inputs.commandstringThe Gradle command to run to build the Android app. If not specified it is resolved based on the build configuration and contents of the ${ eas.job } object.
eas/run_gradle 源代码

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

eas/generate_gymfile_from_template

从模板生成一个用于通过 Fastlane 构建 iOS 应用的 Gymfile

使用凭据时的默认模板:

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 %>")

未传入凭据时使用的默认模板(模拟器构建):

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 %>")

CLEANSCHEMEBUILD_CONFIGURATIONEXPORT_METHODPROFILESICLOUD_CONTAINER_ENVIRONMENTKEYCHAIN_PATHLOGS_DIRECTORYOUTPUT_DIRECTORYDERIVED_DATA_PATHSCHEME_SIMULATOR_DESTINATION 的值会根据输入以及 EAS Build 的默认内部配置提供给模板。

example.yml
build: name: 生成 Gymfile 模板 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: 生成 Gymfile 模板 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/generate_gymfile_from_template

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

example.yml
build: name: 生成 Gymfile 模板 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 %>")
PropertyTypeRequiredDescription
name-The name of the step in the reusable function that shows in the build logs. Defaults to Generate Gymfile from template.
inputs.templatestringThe Gymfile template which should be used. If not specified one out of two default templates will be used depending on whether the inputs.credentials value is specified.
inputs.credentialsjsonThe app credentials for your iOS build. If specified KEYCHAIN_PATH, EXPORT_METHOD, and PROFILES values will be provided to the template.
inputs.build_configurationstringThe Xcode project's Build Configuration. Defaults to ${ eas.job.buildConfiguration } or if not specified is resolved to Debug for development client or Release for other builds. Corresponds to the BUILD_CONFIGURATION template value.
inputs.schemestringThe Xcode project's scheme which should be used for the build. Defaults to ${ eas.job.scheme } or if not specified is resolved to the first scheme found in the Xcode project. Corresponds to the SCHEME template value.
inputs.cleanbooleanWhether the Xcode project should be cleaned before the build. Defaults to true. Corresponds to CLEAN template variable.
inputs.extrajsonExtra values which should be provided to the template.
eas/generate_gymfile_from_template 源代码

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

eas/run_fastlane

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

example.yml
build: name: 构建 iOS 应用 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: 构建 iOS 应用 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 服务器。

example.yml
build: name: 构建 iOS 应用 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: 构建 iOS 应用 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: 构建 Android 应用 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_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: 上传工件 steps: - eas/checkout # - ... - eas/upload_artifact: name: 上传应用归档 inputs: path: fixtures/app-debug.apk - eas/upload_artifact: name: 上传工件 inputs: type: build-artifact path: | assets/*.jpg assets/*.png
属性类型必填描述
pathstring要上传的路径或以换行符分隔的路径列表。支持 * 和其他 glob 模式
typestring构件类型。在自定义作业中使用 other(通用构件)。当作业没有构建平台时,默认为 other;在构建作业中默认为 application-archive。构建范围的值 application-archivebuild-artifact 仅适用于构建作业。
namestring构件名称,用于从 eas/download_artifact 引用该构件。
metadatajson要附加到通用(other)构件的任意元数据。
ignore_errorbooleantrue 时,上传失败会记录日志,但不会导致步骤失败。默认为 false
输出
属性类型描述
artifact_idstring已上传构件的 ID。可传递给 eas/download_artifact
eas/upload_artifact 源代码

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

eas/install_maestro

确保已安装 Maestro 以及它的所有依赖项,这是一款移动端 UI 测试框架。

build-and-test.yml
build: name: 构建并测试 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: 上传 Maestro 工件 inputs: type: build-artifact path: ${ eas.env.HOME }/.maestro/tests
InputTypeRequiredDescription
maestro_versionstringMaestro version to install (for example, 1.35.0). If not provided, install_maestro will install the latest version.
eas/install_maestro 源代码

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

eas/start_android_emulator

启动一个可用于测试应用的 Android 模拟器。仅在执行 Android 构建时可用。

build-and-test.yml
build: name: 构建并测试 steps: - eas/build - eas/start_android_emulator: inputs: system_image_package: system-images;android-30;default;x86_64 # ... Maestro setup and tests
InputTypeRequiredDescription
device_namestringName for the created device. You can customize it if starting multiple emulators.
system_image_packagestringAndroid package path to use for the emulator. For example, system-images;android-30;default;x86_64.
To get a list of available system images, run sdkmanager --list on a local computer. VMs run on x86_64 architecture, so always choose x86_64 package variants. The sdkmanager tool comes from Android SDK command-line tools.
eas/start_android_emulator 源代码

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

eas/start_ios_simulator

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

build-and-test.yml
build: name: 构建并测试 steps: - eas/build - eas/start_ios_simulator # ... Maestro setup and tests
InputTypeRequiredDescription
device_identifierstringName or UDID of the Simulator you want to start. Examples include iPhone [XY] Pro, AEF997BB-222C-4379-89BA-D21070B1D787.
Note: Available Simulators are different for every image. If you change the image, the Simulator for a given name may become unavailable. For instance, an Xcode 14 image will have iPhone 14 Simulators, while an Xcode 15 image will have iPhone 15 simulators. In general, we encourage not providing this input. See runner images for more information.
eas/start_ios_simulator 源代码

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

eas/send_slack_message

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.

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 消息 steps: - eas/send_slack_message: name: 向给定的 webhook URL 发送 Slack 消息 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: 向来自 SLACK_HOOK_URL 密钥的默认 webhook URL 发送 Slack 消息 inputs: message: 'This is a test message to default URL from SLACK_HOOK_URL secret' - eas/send_slack_message: name: 向来自指定密钥的 webhook URL 发送 Slack 消息 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: 构建完成时发送 Slack 消息(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: 构建完成时发送 Slack 消息(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: 构建失败时发送 Slack 消息(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: 构建失败时发送 Slack 消息(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: 构建成功时发送 Slack 消息 inputs: message: | This is a test message when build succeeds - eas/send_slack_message: if: ${ always() } name: 使用 Slack Block Kit 布局发送 Slack 消息 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: 图片替代文本 - 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
PropertyTypeDescription
messagestring要发送的消息文本。例如,'This is the content of the message'

**注意:**必须提供 messagepayload,但不能同时提供两者。
payloadjson要发送的消息内容,使用 Slack Block Kit 布局定义。

**注意:**必须提供 messagepayload,但不能同时提供两者。
slack_hook_urlstring之前配置的 Slack webhook URL,该 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 函数的源代码。

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

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

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

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
PropertyTypeRequiredDescription
flagstring要更新的功能标志键。
activeboolean功能标志是否已启用。
rollout_percentagenumber功能标志面向的用户百分比,取值为 0100 之间的整数。此函数会将其应用于功能标志的兜底发布条件,并保留其他条件。如果功能标志没有兜底条件,此函数会将其应用于第一个条件。
payloadjson要附加到功能标志的负载。
variantstring在多变量功能标志上用于存储 payload 的变体键。默认为功能标志的 true 负载。
api_keystringPostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要 feature_flag:readfeature_flag:write 作用域。
project_idstringPostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。
ignore_errorbooleantrue 时,网络错误、缺少功能标志或意外响应会被记录,但不会导致步骤失败。默认为 false。权限错误或无效输入(例如超出范围的 rollout_percentage)始终会导致步骤失败。
eas/posthog_flag_rollout 源代码

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

eas/posthog_wait_for_metric

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
属性类型必填描述
querystringHogQL 查询。第一行的第一列必须是单个数字。
operatorstring比较运算符。可以是 ltltegtgteeq 之一。当 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 环境变量。
输出
属性类型描述
valuestring满足比较条件的指标值。
eas/posthog_wait_for_metric 源代码

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

eas/posthog_wait_for_query

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
属性类型必填描述
querystringHogQL 查询。当第一行的第一列为 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

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
属性类型必填描述
contentstring注释文本。
date_markerstring注释固定到的 ISO 8601 时间戳。默认为当前时间。
api_keystringPostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要 annotation:write 作用域。
project_idstringPostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。
ignore_errorboolean当值为 true 时,会记录网络错误或意外响应,但不会使步骤失败。默认为 false。权限错误始终会使步骤失败。
eas/posthog_annotation 源代码

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

eas/posthog_upload_sourcemaps

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
属性类型必填描述
directorystring包含 bundle 和源映射的目录,相对于工作目录。默认为 dist
api_keystringPostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要源映射上传权限。
project_idstringPostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。
ignore_errorboolean当为 true 时,上传失败会被记录,但不会导致步骤失败。默认为 false
eas/posthog_upload_sourcemaps 源代码

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

使用内置 EAS 函数构建应用

使用内置 EAS 函数,你可以为不同的构建类型重建默认的 EAS Build 流程。

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

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: 简单的 Android 内部分发构建 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: 简单的 iOS 模拟器构建 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - run: name: 安装 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 构建,你可以使用以下配置:

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: 自定义 Android Play Store 构建示例 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: 自定义 iOS App Store 构建示例 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: 安装 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

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

自定义构建示例仓库

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

build 中使用可复用函数

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

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

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

build: name: 函数演示 steps: - greetings: inputs: value: Expo

build 中覆盖值

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

  • working_directory
  • name
  • shell

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

functions: list_files: name: 列出文件 command: ls -la

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

build: name: 列出文件 steps: - eas/checkout - list_files

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

build: name: 列出文件 steps: - eas/checkout - list_files: working_directory: /a/b/c