了解如何使用指纹运行时版本和 GitHub 操作进行持续部署。
¥Prerequisites
你需要有一个 GitHub 账户并使用它来托管你的 git 项目。
¥You need to have a GitHub account and use it to host your git project.
你需要在你的 GitHub 存储库中配置一个 Expo 令牌。
¥You need to have an Expo token configured in your GitHub repository.
EXPO_TOKEN
environment variable on your GitHub repository导航到 expo.dev/settings/access-tokens,然后:
¥Navigate to expo.dev/settings/access-tokens and then:
单击“创建令牌”以创建新的个人访问令牌。
¥Click Create token to create a new personal access token.
复制生成的令牌。
¥Copy the generated token.
将 "your-username" 和 "your-repo-name" 替换为你的项目信息,导航到 https://github.com/your-username/your-repo-name/settings/secrets/actions。
¥Navigate to https://github.com/your-username/your-repo-name/settings/secrets/actions by replacing "your-username" and "your-repo-name" with your project's info.
在存储库密钥下,单击新建存储库密钥。
¥Under Repository secrets, click New repository secret.
创建一个名为 EXPO_TOKEN 的密钥,并将复制的访问令牌粘贴为值。
¥Create a secret with the name EXPO_TOKEN, and paste the copied access token in as the value.
适用于 SDK 52 及以上版本。
Expo 提供 continuous-deploy-fingerprint GitHub Action 来持续部署使用 fingerprint
运行时版本策略 的 React Native 项目。它将每个 JS 更改作为 EAS 更新无线部署到所有兼容版本,并且在检测到运行时更改时使用 EAS Build 自动创建新版本。
¥Expo provides the continuous-deploy-fingerprint GitHub Action to continuously deploy React Native projects that use the fingerprint
runtime version policy. It deploys every JS change as an EAS Update to all compatible builds over-the-air, and new builds are automatically created using EAS Build when a runtime change is detected.
在调试模式下运行 GitHub 工作流程将自动将 --debug
标志添加到作为操作的一部分运行的命令中,并且输出将在工作流程运行日志中可用。
¥Running your GitHub workflows in debug mode will automatically add the --debug
flag to the commands run as part of the action, and the output will be available in the workflow run logs.
¥Fingerprint runtime versioning
fingerprint
运行时版本策略 在进行构建或发布更新时使用 @expo/fingerprint
包生成项目的哈希值,然后使用该哈希值作为运行时版本。哈希值是根据依赖、自定义原生代码、原生项目文件和配置等计算得出的。
¥The fingerprint
runtime version policy uses the @expo/fingerprint
package to generate a hash of your project when making a build or publishing an update, and then uses that hash as the runtime version. The hash is calculated based on dependencies, custom native code, native project files, and configuration, amongst other things.
通过自动计算运行时版本,你在部署构建更新时不必担心原生层与 JavaScript 应用的兼容性。
¥By automatically calculating the runtime version, you don't have to be concerned about native layer compatibility with the JavaScript application when deploying updates to builds.
指纹哈希中包含的默认项目文件在托管工作流项目和裸工作流项目之间有所不同。EAS 通过检查 android 和 ios 和目录是否被 gitignored 来自动检测你的工作流。如果是,EAS 会将该项目视为托管工作流项目,从而表明 package.json
依赖的哈希值足以确定指纹兼容性。
¥The default project files included in the fingerprint hash differs between managed and bare workflow projects. EAS automatically detects your workflow by checking if the android and ios and directories are gitignored. If they are, EAS will treat the project as a managed workflow project, thus dictating that a hash of the package.json
dependencies are sufficient to determine fingerprint compatibility.
如果你注意到在不同的机器或环境中生成了不同的指纹,则可能意味着哈希计算中包含了意外的文件。@expo/fingerprint
有一组预定的文件用于包含/排除哈希计算,但你的项目设置通常可能需要额外的排除。对于包含原生目录(android 和 ios)的项目,这更常见。
¥If you notice different fingerprints being generated across different machines or environments, it may mean that unanticipated files are being included in the hash calculation. @expo/fingerprint
has a predetermined set of files to include/exclude for hash calculation, but often your project setup may require additional excludes. For projects that include native directories (android and ios) this is more common.
我们提供用于识别哪些文件导致指纹不一致的工具,以及将这些文件从项目指纹计算中排除的机制。
¥We provide tools for identifying which files are causing fingerprint inconsistencies and mechanisms to exclude those files from fingerprint calculations for your project.
要识别不同机器或环境中的指纹差异:
¥To identify differences in fingerprints on different machines or environments:
在每台机器/环境(npx expo-updates fingerprint:generate
)上运行指纹生成命令时,传递 --debug
标志。
¥When running fingerprint generation commands on each machine/environment (npx expo-updates fingerprint:generate
), pass --debug
flag.
这些命令运行的差异输出以确定导致差异的文件。这些工具可能会有所帮助:
¥Diff outputs from those command runs to determine files causing the difference. These tools may be helpful:
JSON Pretty Print 格式化输出。
¥JSON Pretty Print to format the output.
JSON Diff 比较输出并识别导致差异的文件。
¥JSON Diff to compare the output and identify the files causing the discrepancies.
要排除导致差异的文件,请将它们添加到 .fingerprintignore 文件中,如 @expo/fingerprint
文档中所述。
¥To exclude files causing the differences, add them to the .fingerprintignore file as described in the documentation for @expo/fingerprint
.
¥App version numbers
使用持续部署时,版本号递增必须自动补齐。虽然具体细节会根据首选编号方案而有所不同,但总体策略是:
¥When using continuous deployment, version number incrementation must be done automatically. While the specifics will differ based on the preferred numbering scheme, the general strategy is:
在持续部署 CI 步骤之前,检查是否会创建新版本(由于新指纹)。
¥Before continuous deployment CI steps, check if a new release will be created (due to a new fingerprint).
如果是这样,请在源代码中增加版本号并推动版本增加提交。
¥If so, bump the version number in the source code and push the version bump commit.
使用新的提交继续持续部署 CI 步骤。
¥Continue continuous deployment CI steps with the new commit.
continuous-deploy-fingerprint
GitHub Action 文档 中提供了一个示例。
¥An example is provided in the continuous-deploy-fingerprint
GitHub Action documentation.
另一种 GitHub 操作是 expo-github-action,可用于发布推送更新和拉取请求预览。continuous-deploy-fingerprint
使用指纹来确定是否需要构建来部署更新,而 expo-github-action
只会发布更新。
¥An alternative GitHub action is expo-github-action that can be used to publish updates on push and previews on pull requests. continuous-deploy-fingerprint
uses fingerprints to determine if a build is needed or not to deploy an update, while expo-github-action
will only publish updates.
要了解在代码推送到主分支时发布更新,请参阅 README。
¥To learn about publishing updates when code is pushed to the main branch, refer to the README.
要了解使用 expo-github-action
的 Pull Request 预览,请参阅 GitHub PR 预览指南。
¥To learn about Pull Request previews with expo-github-action
, refer to the GitHub PR Previews guide.