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"
注意:
run前面的-计入缩进。
使用多个步骤
当定义多个 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 变量暴露给其他步骤。
注意: 使用
set-env共享的变量不会自动在本地导出。你需要自己调用export。
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
输入值的类型。它可以是 string、num 或 json。
在函数调用中设置的输入值,以及函数的 default_value 和 allowed_values 都会根据该类型进行验证。
默认的输入 type 是 string。
例如,一个函数有一个类型为 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 模块路径。每个函数都必须定义 command 或 path 属性。例如,路径 ./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
用于定义函数支持的平台。默认支持所有平台。允许的平台:darwin、linux。
例如,该函数支持的平台是 darwin(macOS):
functions: greetings: name: 说你好! supported_platforms: [darwin] command: echo "你好!"
import
用于从其他配置文件导入函数的配置文件路径列表。被导入的文件不能包含 build 部分。
例如,下面的构建配置导入了两个文件,并调用了两个导入的函数——say_hi 和 say_bye。
import: - common-functions.yml - another-file.yml build: steps: - say_hi - say_bye
functions: say_hi: name: 说你好! command: echo "你好!"
functions: say_bye: name: 说再见 :( command: echo "再见!"
函数
内置 EAS 函数
EAS 提供了一组可重用的内置函数,你可以在构建配置中直接使用,而无需定义函数声明。
提示: 任何由 EAS 内置提供的函数都必须以eas/前缀开头。
eas/build
一个集成式函数,封装整个 EAS Build 的构建流程。它会根据你的构建配置文件 eas.json 中的构建配置来解析出最佳构建方案。
对于那些希望无需手动调整和配置构建流程就能完成构建的人来说,它非常理想。如果你希望在构建前后添加其他自定义步骤,但又不想改变构建流程本身,它也可以作为自定义构建配置的良好起点。
build: name: 使用单个命令运行构建 steps: - eas/build
如果你希望对构建流程有更多控制,并根据需求进行自定义,可以查看下面这些由 eas/build 在后台执行的自定义函数和步骤。它们会根据你的构建配置作为构建流程执行。
Android
当构建配置使用 withoutCredentials 时:
eas/checkouteas/use_npm_tokeneas/install_node_moduleseas/resolve_build_configeas/prebuildeas/configure_eas_updateeas/run_gradleeas/find_and_upload_build_artifacts
当构建配置使用凭据时(适用于 internal 和 store distribution 构建):
eas/checkouteas/use_npm_tokeneas/install_node_moduleseas/resolve_build_configeas/prebuildeas/configure_eas_updateeas/inject_android_credentialseas/configure_android_versioneas/run_gradleeas/find_and_upload_build_artifacts
iOS
当构建配置使用 withoutCredentials 或 simulator 时:
eas/checkouteas/use_npm_tokeneas/install_node_moduleseas/resolve_build_configeas/prebuild- 使用
pod install命令安装 pods eas/configure_eas_updateeas/generate_gymfile_from_templateeas/run_fastlaneeas/find_and_upload_build_artifacts
当构建配置使用凭据时(适用于 internal 和 store distribution 构建):
eas/checkouteas/use_npm_tokeneas/install_node_moduleseas/resolve_build_configeas/resolve_apple_team_id_from_credentialseas/prebuild- 使用
pod install命令安装 pods eas/configure_eas_updateeas/configure_ios_credentialseas/configure_ios_versioneas/generate_gymfile_from_templateeas/run_fastlaneeas/find_and_upload_build_artifacts
你可以在 YAML 配置文件中使用这些步骤来替换 eas/build 命令调用:
查看我们示例仓库中由 `eas/build` 函数在 iOS 模拟器构建中幕后执行的步骤。
查看我们示例仓库中由 `eas/build` 函数在带凭据的 iOS 构建中幕后执行的步骤。
查看我们示例仓库中由 `eas/build` 函数在不带凭据的 Android 构建中幕后执行的步骤。
查看我们示例仓库中由 `eas/build` 函数在带凭据的 Android 构建中幕后执行的步骤。
已知限制
- 它不接受任何输入,解析后的构建流程将根据你在 eas.json 中的构建配置进行设置。
eas/build生成的构建流程不可配置,你无法对其进行自定义。如果你需要自定义构建流程,请使用该函数在幕后执行的那一组函数和步骤,并像上面的示例那样在 YAML 配置文件中手动配置它们。
eas/maestro_test
一个集成式函数,用于安装 Maestro、准备测试环境(Android Emulator 或 iOS Simulator),并测试应用。
| Input | Type | Required | Description |
|---|---|---|---|
flow_path | string | Path (or multiple paths, each in a separate line) to Maestro flows to run. | |
app_path | string | Path (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: name: 构建并测试 steps: - eas/build - eas/maestro_test: inputs: flow_path: | maestro/sign_in.yml maestro/create_post.yml maestro/sign_out.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
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
其幕后会使用:
eas/install_maestro安装 Maestro- 如果需要,使用
eas/start_android_emulator启动 Android Emulator - 如果需要,使用
eas/start_ios_simulator启动 iOS Simulator - 自定义
run,将 .apk 安装到正在运行的 Android Emulator,将 .app 安装到 iOS Simulator - 一系列
run,对提供的每个 flow 执行maestro test eas/upload_artifact将 Maestro 测试产物作为构建产物上传
我们观察到,如果在安装了 Xcode 15.0 或 15.2 的镜像上运行,Maestro 测试经常会超时。请使用latest镜像以避免任何问题。
如果你需要自定义 Maestro 版本、运行特定的 Android Emulator 或 iOS Simulator,或者上传多个构建产物,就需要自行编写这组步骤。
`eas/maestro_test` 展开后的 Android 构建配置示例
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: 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
在 GitHub 上查看 eas/maestro_test 函数的源代码。
eas/checkout
检出你的项目源文件。
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:
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-iconor a qualified ref such asrefs/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 detachedHEAD. - 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.
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
ref | string | 要检出的 Git 分支、标签或完整提交 SHA。默认为触发构建或工作流任务的 ref。 |
在 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.
build: name: 安装私有 npm 模块 steps: - eas/checkout - eas/use_npm_token - run: name: 安装依赖 run: npm install # <---- 现在可以安装私有包了
在 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.
build: name: 安装 node 模块 steps: - eas/checkout - eas/install_node_modules
在 GitHub 上查看 eas/install_node_modules 函数的源代码。
eas/restore_build_cache
从指定的 key 恢复之前保存的构建缓存。这对于通过复用已缓存的产物(如编译后的依赖、构建工具或其他中间构建输出)来加快构建速度非常有用。
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
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
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Restore build cache. | |
inputs.key | string | The cache key to restore. You can use expressions like ${{ hashFiles('package-lock.json') }} to create dynamic keys based on file hashes. | |
inputs.restore_keys | string | A 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.path | string | The path where the cache should be restored. This should match the path used when saving the cache. |
在 GitHub 上查看 eas/restore_build_cache 函数的源代码。
eas/save_build_cache
将构建缓存保存到指定的 key。这使你能够持久化构建产物、编译后的依赖或其他中间输出,以便在后续构建中复用,从而加快构建流程。
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
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Save build cache. | |
inputs.key | string | The 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.path | string | The path to the directory or files that should be cached. This should match the path used when restoring the cache. |
在 GitHub 上查看 eas/save_build_cache 函数的源代码。
eas/resolve_build_config
解析并打印构建配置。如果构建是由 GitHub 集成触发的,它会更新当前的 job 和 metadata 上下文值。它应在安装依赖之后调用,因为配置可能会受到配置插件的影响。
该函数会被 eas/build 函数组自动执行。
在 GitHub 上查看 eas/resolve_build_config 函数的源代码。
eas/get_credentials_for_build_triggered_by_github_integration
已弃用: 请用eas/resolve_build_config替换此步骤。
eas/resolve_apple_team_id_from_credentials
此函数仅适用于 iOS 构建。
根据在 inputs.credentials 中提供的构建凭据解析 Apple team ID 值。解析得到的 Apple team ID 会存储在 outputs.apple_team_id 输出值中。
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 }
| Property | Type | Required | Description |
|---|---|---|---|
name | string | The name of the step in the reusable function that shows in the build logs. Defaults to Resolve Apple team ID from credentials. | |
inputs.credentials | json | The app credentials for your iOS build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for iOS. |
在 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.
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 }
build: name: 运行 prebuild 脚本 steps: - eas/checkout - eas/install_node_modules - eas/prebuild
| 属性 | 类型 | 描述 |
|---|---|---|
clean | boolean | 可选属性,用于定义函数运行命令时是否应使用 --clean 标志。默认为 false。 |
apple_team_id | string | 可选属性,用于定义执行预构建时应使用的 Apple 团队 ID。使用凭据进行 iOS 构建时必须指定此属性。 |
在 GitHub 上查看 eas/prebuild 函数的源代码。
eas/configure_eas_update
使用此函数需要为你的项目配置 EAS Update。
为你的构建配置运行时版本和发布通道。
build: name: 配置 EAS Update steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update
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
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Configure EAS Update. | |
inputs.runtime_version | string | Runtime version which should be configured for the build. Defaults to ${ eas.job.version.runtimeVersion } or natively defined runtime version. | |
inputs.channel | string | Channel which should be configured for the build. Defaults to ${ eas.job.updates.channel }. |
在 GitHub 上查看 eas/configure_eas_update 函数的源代码。
eas/inject_android_credentials
此函数仅适用于 Android 构建。
在构建机上使用凭据配置 Android keystore,并使用这些凭据将应用签名配置注入 gradle 配置中。
build: name: Android 凭据 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/inject_android_credentials
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Inject Android credentials. | |
inputs.credentials | json | The app credentials for your Android build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for Android. |
在 GitHub 上查看 eas/inject_android_credentials 函数的源代码。
eas/configure_ios_credentials
此函数仅适用于 iOS 构建。
在构建机上配置 iOS 凭据。通过将 provisioning profiles 分配给各个 targets 来修改 Xcode 项目的配置。
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
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Configure iOS credentials. | |
inputs.build_configuration | string | The 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.credentials | json | The app credentials for your iOS build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for iOS. |
在 GitHub 上查看 eas/configure_ios_credentials 函数的源代码。
eas/configure_android_version
此函数仅适用于 Android 构建。
配置 Android 应用的版本。它用于在使用远程应用版本管理时设置版本。
如果不使用此函数也没关系;如果未使用,则会采用 prebuild 阶段生成的原生代码中的版本。
build: name: 配置 Android 版本 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/configure_android_version
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'
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Configure Android version. | |
inputs.version_code | string | versionCode of your Android build. Defaults to ${ eas.job.version.versionCode }. | |
inputs.version_name | string | versionName of your Android build. Defaults to ${ eas.job.version.versionName }. |
在 GitHub 上查看 eas/configure_android_version 函数的源代码。
eas/configure_ios_version
此函数仅适用于 iOS 构建。
配置 iOS 应用的版本。它用于在使用远程应用版本管理时设置版本。
如果不使用此函数也没关系;如果未使用,则会采用 prebuild 阶段生成的原生代码中的版本。
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
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'
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Configure iOS version. | |
inputs.build_number | string | The build number (CFBundleVersion) of your iOS build. Defaults to ${ eas.job.version.buildNumber }. | |
inputs.app_version | string | The app version (CFBundleShortVersionString) of your iOS build. Defaults to ${ eas.job.version.appVersion }. | |
inputs.build_configuration | string | The 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.credentials | json | The app credentials for your iOS build. Defaults to ${ eas.job.secrets.buildCredentials }. Needs to comply to ${ eas.job.secrets.buildCredentials } schema for iOS. |
在 GitHub 上查看 eas/configure_ios_version 函数的源代码。
eas/run_gradle
此函数仅适用于 Android 构建。
运行 Gradle 命令以构建 Android 应用。
build: name: 构建 Android 应用 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/inject_android_credentials - eas/run_gradle
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
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Run gradle. | |
inputs.command | string | The 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. |
在 GitHub 上查看 eas/run_gradle 函数的源代码。
eas/generate_gymfile_from_template
此函数仅适用于 iOS 构建。
从模板生成一个用于通过 Fastlane 构建 iOS 应用的 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 %>")
未传入凭据时使用的默认模板(模拟器构建):
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 的默认内部配置提供给模板。
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 }
build: name: 生成 Gymfile 模板 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/generate_gymfile_from_template
不过,你也可以通过在 inputs.template 中指定自定义模板,并在 inputs.extra 对象中提供这些自定义属性的值,来在模板中使用其他自定义属性。
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 %>")
| Property | Type | Required | Description |
|---|---|---|---|
name | - | The name of the step in the reusable function that shows in the build logs. Defaults to Generate Gymfile from template. | |
inputs.template | string | The 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.credentials | json | The app credentials for your iOS build. If specified KEYCHAIN_PATH, EXPORT_METHOD, and PROFILES values will be provided to the template. | |
inputs.build_configuration | string | The 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.scheme | string | The 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.clean | boolean | Whether the Xcode project should be cleaned before the build. Defaults to true. Corresponds to CLEAN template variable. | |
inputs.extra | json | Extra values which should be provided to the template. |
在 GitHub 上查看 eas/generate_gymfile_from_template 函数的源代码。
eas/run_fastlane
此函数仅适用于 iOS 构建。
在 ios 项目目录中,针对位于该目录下的 Gymfile 运行 fastlane gym 命令,以构建 iOS 应用。
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
build: name: 构建 iOS 应用 steps: - eas/checkout - eas/install_node_modules - eas/prebuild - eas/configure_eas_update - eas/generate_gymfile_from_template - eas/run_fastlane
在 GitHub 上查看 eas/run_fastlane 函数的源代码。
eas/find_and_upload_build_artifacts
警告 你目前每个构建任务中每种工件类型只能上传一次。
如果你在构建配置中设置了buildArtifactPaths,并且使用了eas/find_and_upload_build_artifacts,而该步骤找到了并上传了一些构建工件,那么后续的任何eas/upload_artifact步骤都会失败。
为了解决这个问题,目前我们建议从自定义构建的配置中移除buildArtifactPaths,并在需要时在 YAML 中使用eas/upload_artifact手动上传工件。
自动从默认位置以及使用 buildArtifactPaths 配置中查找并上传应用归档、其他构建工件和 Xcode 日志。将找到的工件上传到 EAS 服务器。
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
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
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
在 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.
警告 你目前每个构建任务中每种工件类型只能上传一次。
如果你在构建配置中设置了buildArtifactPaths,并且使用了eas/find_and_upload_build_artifacts,而该步骤找到了并上传了一些构建工件,那么后续的任何eas/upload_artifact步骤都会失败。
为了解决这个问题,目前我们建议从自定义构建的配置中移除buildArtifactPaths,并在需要时在 YAML 中使用eas/upload_artifact手动上传工件。
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
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
path | string | 要上传的路径或以换行符分隔的路径列表。支持 * 和其他 glob 模式。 | |
type | string | 构件类型。在自定义作业中使用 other(通用构件)。当作业没有构建平台时,默认为 other;在构建作业中默认为 application-archive。构建范围的值 application-archive 和 build-artifact 仅适用于构建作业。 | |
name | string | 构件名称,用于从 eas/download_artifact 引用该构件。 | |
metadata | json | 要附加到通用(other)构件的任意元数据。 | |
ignore_error | boolean | 为 true 时,上传失败会记录日志,但不会导致步骤失败。默认为 false。 |
输出
| 属性 | 类型 | 描述 |
|---|---|---|
artifact_id | string | 已上传构件的 ID。可传递给 eas/download_artifact。 |
在 GitHub 上查看 eas/upload_artifact 函数的源代码。
eas/install_maestro
确保已安装 Maestro 以及它的所有依赖项,这是一款移动端 UI 测试框架。
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
| Input | Type | Required | Description |
|---|---|---|---|
maestro_version | string | Maestro version to install (for example, 1.35.0). If not provided, install_maestro will install the latest version. |
在 GitHub 上查看 eas/install_maestro 函数的源代码。
eas/start_android_emulator
启动一个可用于测试应用的 Android 模拟器。仅在执行 Android 构建时可用。
build: name: 构建并测试 steps: - eas/build - eas/start_android_emulator: inputs: system_image_package: system-images;android-30;default;x86_64 # ... Maestro setup and tests
| Input | Type | Required | Description |
|---|---|---|---|
device_name | string | Name for the created device. You can customize it if starting multiple emulators. | |
system_image_package | string | Android 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. |
在 GitHub 上查看 eas/start_android_emulator 函数的源代码。
eas/start_ios_simulator
启动一个可用于测试应用的 iOS 模拟器。仅在执行 iOS 构建时可用。
build: name: 构建并测试 steps: - eas/build - eas/start_ios_simulator # ... Maestro setup and tests
| Input | Type | Required | Description |
|---|---|---|---|
device_identifier | string | Name 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. |
在 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 }.
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
| Property | Type | Description |
|---|---|---|
message | string | 要发送的消息文本。例如,'This is the content of the message'。**注意:**必须提供 message 或 payload,但不能同时提供两者。 |
payload | json | 要发送的消息内容,使用 Slack Block Kit 布局定义。 **注意:**必须提供 message 或 payload,但不能同时提供两者。 |
slack_hook_url | string | 之前配置的 Slack webhook URL,该 URL 会将你的消息发布到指定频道。请使用 EAS 环境变量 提供,例如 slack_hook_url: ${{ env.ANOTHER_SLACK_HOOK_URL }};或者设置 SLACK_HOOK_URL 环境变量,该变量将作为默认 webhook URL(在后一种情况下,无需提供 slack_hook_url 属性)。 |
在 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.
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
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
event | string | 要发送的事件名称。 | |
distinct_id | string | 要将事件归因到的人员。省略时,事件将匿名发送,且不会创建人员档案。 | |
properties | json | 要附加到事件的属性。 | |
api_key | string | PostHog 项目 API 密钥。默认为由 eas integrations:posthog:connect 设置的 EXPO_PUBLIC_POSTHOG_API_KEY 环境变量;如果未设置,则回退到 POSTHOG_API_KEY。 | |
host | string | PostHog 主机。默认为 EXPO_PUBLIC_POSTHOG_HOST 环境变量,或 https://us.posthog.com。 | |
ignore_error | boolean | 当值为 true 时,发送事件失败会记录日志,但不会导致步骤失败。默认为 false。 |
在 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.
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
| Property | Type | Required | Description |
|---|---|---|---|
flag | string | 要更新的功能标志键。 | |
active | boolean | 功能标志是否已启用。 | |
rollout_percentage | number | 功能标志面向的用户百分比,取值为 0 到 100 之间的整数。此函数会将其应用于功能标志的兜底发布条件,并保留其他条件。如果功能标志没有兜底条件,此函数会将其应用于第一个条件。 | |
payload | json | 要附加到功能标志的负载。 | |
variant | string | 在多变量功能标志上用于存储 payload 的变体键。默认为功能标志的 true 负载。 | |
api_key | string | PostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要 feature_flag:read 和 feature_flag:write 作用域。 | |
project_id | string | PostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。 | |
ignore_error | boolean | 为 true 时,网络错误、缺少功能标志或意外响应会被记录,但不会导致步骤失败。默认为 false。权限错误或无效输入(例如超出范围的 rollout_percentage)始终会导致步骤失败。 |
在 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.
This step has noignore_errorinput. A timeout or an unreadable query always fails the step.
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
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
query | string | HogQL 查询。第一行的第一列必须是单个数字。 | |
operator | string | 比较运算符。可以是 lt、lte、gt、gte 或 eq 之一。当 value <operator> threshold 成立时,步骤将清除。 | |
threshold | number | 用于与查询结果进行比较的值。 | |
timeout_seconds | number | 等待的最长时间,以秒为单位。默认为 600。 | |
interval_seconds | number | 检查之间的时间间隔,以秒为单位。默认为 30。 | |
api_key | string | PostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要 query:read 权限范围。 | |
project_id | string | PostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。 |
输出
| 属性 | 类型 | 描述 |
|---|---|---|
value | string | 满足比较条件的指标值。 |
在 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.
Likeeas/posthog_wait_for_metric, this step has noignore_errorinput. A timeout or an unreadable query always fails the step.
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
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
query | string | HogQL 查询。当第一行的第一列为 true 或非零数字时,该步骤将清除。 | |
timeout_seconds | number | 最大等待时间,以秒为单位。默认为 600。 | |
interval_seconds | number | 检查之间的间隔时间,以秒为单位。默认为 30。 | |
api_key | string | PostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要 query:read 作用域。 | |
project_id | string | PostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。 |
在 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.
build: name: Annotate the release in PostHog steps: - eas/posthog_annotation: name: Create a PostHog annotation inputs: content: Published a production build
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
content | string | 注释文本。 | |
date_marker | string | 注释固定到的 ISO 8601 时间戳。默认为当前时间。 | |
api_key | string | PostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要 annotation:write 作用域。 | |
project_id | string | PostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。 | |
ignore_error | boolean | 当值为 true 时,会记录网络错误或意外响应,但不会使步骤失败。默认为 false。权限错误始终会使步骤失败。 |
在 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.
This step runs the PostHog CLI, which cannot tell a permissions error apart from any other failure. Unlike the other PostHog functions, settingignore_error: truealso hides authentication and scope errors.
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 | string | 包含 bundle 和源映射的目录,相对于工作目录。默认为 dist。 | |
api_key | string | PostHog 个人 API 密钥。默认为 POSTHOG_CLI_API_KEY 环境变量。需要源映射上传权限。 | |
project_id | string | PostHog 项目 ID。默认为 POSTHOG_CLI_PROJECT_ID 环境变量。 | |
ignore_error | boolean | 当为 true 时,上传失败会被记录,但不会导致步骤失败。默认为 false。 |
在 GitHub 上查看 eas/posthog_upload_sourcemaps 函数的源代码。
使用内置 EAS 函数构建应用
使用内置 EAS 函数,你可以为不同的构建类型重建默认的 EAS Build 流程。
例如,要触发一个为 Android 创建内部分发构建、为 iOS 创建模拟器构建的任务,你可以使用以下配置:
{ %%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%% }
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
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 构建,你可以使用以下配置:
{ %%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%% }
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
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.steps可以按顺序执行多个可复用的functions。
在 build 中覆盖值
你可以为以下属性覆盖值:
working_directorynameshell
例如,一个名为 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