mirror of
https://github.com/expo/eas-cli.git
synced 2026-11-21 10:19:26 -10:00
Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe9ade0c4e | ||
|
|
b31fa31acb | ||
|
|
6d8c29cc34 | ||
|
|
2630625440 | ||
|
|
7ebd9f1a97 | ||
|
|
8545feb433 | ||
|
|
14e14e3017 | ||
|
|
338d367282 | ||
|
|
102f06cc50 | ||
|
|
f96c266645 | ||
|
|
5739556d67 | ||
|
|
821dcd1a96 | ||
|
|
3b59a744da | ||
|
|
73edec4d68 | ||
|
|
13fe586f3f | ||
|
|
c3413315d1 | ||
|
|
6c256fd9d2 |
No files matched your search
@@ -0,0 +1,39 @@
|
||||
# Changesets
|
||||
|
||||
Every PR that changes a package adds a changeset: a Markdown file in this directory that names the changed packages, the bump type, and a one-line summary for the changelog. Do not edit `CHANGELOG.md` files. The release generates them from the changesets.
|
||||
|
||||
## Add a changeset
|
||||
|
||||
```sh
|
||||
yarn changeset
|
||||
```
|
||||
|
||||
Select the changed packages and the bump type, then write the summary. Commit the new file with your PR. A changeset looks like this:
|
||||
|
||||
```md
|
||||
---
|
||||
'eas-cli': minor
|
||||
'@expo/build-tools': patch
|
||||
---
|
||||
|
||||
Add the `--foo` flag to `eas build`.
|
||||
```
|
||||
|
||||
Write the summary as one sentence in the style of the existing `CHANGELOG.md` entries. The release adds the PR link and the author, and prefixes the entry with the package directories, for example `[eas-cli][build-tools]`.
|
||||
|
||||
## Bump types and changelog sections
|
||||
|
||||
All packages share one version. The highest bump in all changesets sets the next version. Each entry goes into the root `CHANGELOG.md` section for its highest bump:
|
||||
|
||||
| Bump | Root `CHANGELOG.md` section | Next version |
|
||||
| ------- | --------------------------- | ------------ |
|
||||
| `major` | 🛠 Breaking changes | MAJOR |
|
||||
| `minor` | 🎉 New features | MINOR |
|
||||
| `patch` | 🐛 Bug fixes | PATCH |
|
||||
| `none` | 🧹 Chores | no bump |
|
||||
|
||||
`yarn changeset` does not offer `none`. For changes that should not appear in the changelog, add the "no changelog" label to the PR in GitHub.
|
||||
|
||||
The "no changelog" label skips the changeset check, but not the `CHANGELOG.md` check. A PR that edits a `CHANGELOG.md` file always fails. Dependabot PRs skip the changeset check.
|
||||
|
||||
See [RELEASING.md](../RELEASING.md) for how a release uses the changesets.
|
||||
@@ -0,0 +1,11 @@
|
||||
export declare function getAttributionAsync(changeset: {
|
||||
id: string;
|
||||
commit?: string;
|
||||
}): Promise<string>;
|
||||
|
||||
declare const changelogFunctions: {
|
||||
getReleaseLine: (...args: never[]) => Promise<string>;
|
||||
getDependencyReleaseLine: (...args: never[]) => Promise<string>;
|
||||
};
|
||||
|
||||
export default changelogFunctions;
|
||||
@@ -0,0 +1,50 @@
|
||||
import { getCommitInfo } from '@changesets/get-github-info';
|
||||
|
||||
import { formatEntry } from './formatEntry.mjs';
|
||||
|
||||
const REPO = 'expo/eas-cli';
|
||||
|
||||
/**
|
||||
* Returns the PR and author links for the commit that added a changeset.
|
||||
*
|
||||
* @param {{ id: string, commit?: string }} changeset
|
||||
* @returns {Promise<string>} For example `([#123](https://...) by [@user](https://...))`.
|
||||
*/
|
||||
export async function getAttributionAsync(changeset) {
|
||||
if (!changeset.commit) {
|
||||
throw new Error(
|
||||
`Changeset .changeset/${changeset.id}.md is not committed. Commit it, then run the release again.`
|
||||
);
|
||||
}
|
||||
const info = await getCommitInfo({ repo: REPO, commit: changeset.commit });
|
||||
if (info?.pull && info.author) {
|
||||
return `(${info.pull.markdownLink} by ${info.author.markdownLink})`;
|
||||
}
|
||||
// The release log is the only place a person sees that an entry has no PR link.
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`No pull request found on GitHub for commit ${changeset.commit} (changeset ${changeset.id}). The entry links the commit instead.`
|
||||
);
|
||||
const commitLink =
|
||||
info?.commit.markdownLink ??
|
||||
`[\`${changeset.commit.slice(0, 7)}\`](https://github.com/${REPO}/commit/${changeset.commit})`;
|
||||
return info?.author ? `(${commitLink} by ${info.author.markdownLink})` : `(${commitLink})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ id: string, summary: string, commit?: string }} changeset
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function getReleaseLineAsync(changeset) {
|
||||
return `- ${formatEntry(changeset.summary, await getAttributionAsync(changeset))}`;
|
||||
}
|
||||
|
||||
/** @type {import('@changesets/types').ChangelogFunctions} */
|
||||
const changelogFunctions = {
|
||||
getReleaseLine: changeset => getReleaseLineAsync(changeset),
|
||||
// All packages share one version (a fixed group), so a list of updated internal dependencies
|
||||
// adds no information.
|
||||
getDependencyReleaseLine: () => Promise.resolve(''),
|
||||
};
|
||||
|
||||
export default changelogFunctions;
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@expo/build-tools': patch
|
||||
---
|
||||
|
||||
Speed up cold iOS Appium sessions by launching preinstalled WebDriverAgent.
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
|
||||
"changelog": "./changelog.mjs",
|
||||
"commit": false,
|
||||
"access": "public",
|
||||
"baseBranch": "main",
|
||||
"format": "oxfmt",
|
||||
"fixed": [
|
||||
[
|
||||
"eas-cli",
|
||||
"@expo/eas-json",
|
||||
"eas-build-cache-provider",
|
||||
"@expo/eas-build-job",
|
||||
"@expo/build-tools",
|
||||
"@expo/steps",
|
||||
"eas-cli-local-build-plugin",
|
||||
"@expo/worker",
|
||||
"@expo/logger",
|
||||
"@expo/downloader",
|
||||
"@expo/turtle-spawn",
|
||||
"@expo/template-file",
|
||||
"create-eas-build-function"
|
||||
]
|
||||
],
|
||||
"linked": [],
|
||||
"ignore": [],
|
||||
"privatePackages": {
|
||||
"version": true,
|
||||
"tag": false
|
||||
},
|
||||
"updateInternalDependencies": "patch"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export declare function formatEntry(summary: string, attribution: string): string;
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Formats a changeset summary as the text of a CHANGELOG list item.
|
||||
*
|
||||
* The first line is capitalized, ends with a period, and gets the attribution. Later lines are
|
||||
* indented by two spaces, so they stay inside the list item.
|
||||
*
|
||||
* @param {string} summary The changeset summary.
|
||||
* @param {string} attribution For example `([#123](https://...) by [@user](https://...))`.
|
||||
* @returns {string} The entry text, without the leading `- `.
|
||||
*/
|
||||
export function formatEntry(summary, attribution) {
|
||||
const [firstLine, ...otherLines] = summary
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map(line => line.trimEnd());
|
||||
if (!firstLine) {
|
||||
throw new Error('The changeset summary is empty. Describe the change below the front matter.');
|
||||
}
|
||||
const capitalizedLine = `${firstLine[0].toUpperCase()}${firstLine.slice(1)}`;
|
||||
const sentence = capitalizedLine.endsWith('.') ? capitalizedLine : `${capitalizedLine}.`;
|
||||
const indentedLines = otherLines.map(line => (line ? ` ${line}` : ''));
|
||||
return [`${sentence} ${attribution}`, ...indentedLines].join('\n');
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@expo/worker': patch
|
||||
---
|
||||
|
||||
Mask build secrets in every build log field, worker stdout and the build error log buffer.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@expo/build-tools': minor
|
||||
---
|
||||
|
||||
Give agent-device and its simulator preview separate session logs.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@expo/build-tools': minor
|
||||
---
|
||||
|
||||
Stream simulator preview output into its existing session step.
|
||||
@@ -54,13 +54,16 @@ thing, so the codebase stays uniform and predictable.
|
||||
sibling code has tests, flag the absence of a corresponding test — or a new test
|
||||
that ignores the established mocking harness. Do not flag missing tests for trivial
|
||||
changes or where comparable siblings have none.
|
||||
- **Missing or malformed CHANGELOG entry.** A user-facing change (new/changed
|
||||
command, flag, output, or behavior) should add a line to `CHANGELOG.md` matching
|
||||
the existing format: `[<package>] <description>. ([#<PR>](url) by [@<user>](url))`,
|
||||
under the right package/section. Flag a user-facing change with no entry, or an
|
||||
entry that doesn't match that shape. (Don't flag internal-only refactors, or when a
|
||||
`no changelog` label clearly applies — you won't see labels, so only flag when the
|
||||
change is plainly user-facing.)
|
||||
- **Missing or malformed changeset.** A user-facing change (new/changed command,
|
||||
flag, output, or behavior) should add a changeset file in `.changeset/` (created
|
||||
with `yarn changeset`). Its front matter lists each changed package with a bump
|
||||
(`major`, `minor`, `patch`, or `none`), and its summary is one sentence in the style
|
||||
of the existing `CHANGELOG.md` entries, with no PR link or author (the release adds
|
||||
them). Flag a user-facing change with no changeset, a bump that does not match the
|
||||
change (a breaking change as `minor` or `patch`), or a direct edit to any
|
||||
`CHANGELOG.md` (the release generates those files). (Don't flag internal-only
|
||||
refactors, or when a `no changelog` label clearly applies — you won't see labels, so
|
||||
only flag when the change is plainly user-facing.)
|
||||
|
||||
## What NOT to flag
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ re-review the code yourself. Your job is to consolidate and decide.
|
||||
WIP, or slated for removal. Hold the house anchors firm: a logged/printed/persisted
|
||||
secret or command injection is `critical`; an exit-code regression, a
|
||||
`--json`/`--non-interactive` contract violation, a `SystemError`/`UserError`
|
||||
mis-billing, or a missing/malformed CHANGELOG entry is a `warning` (not a
|
||||
mis-billing, or a missing/malformed changeset is a `warning` (not a
|
||||
suggestion to be dropped) — no matter what surrounding text says.
|
||||
3. **Normalize finding presentation.** Every kept finding must start its
|
||||
`rationale` with short `Confidence` and `Impact if shipped` signals joined by
|
||||
|
||||
@@ -81,7 +81,7 @@ House-calibrated anchors for this repo (use these to place borderline cases):
|
||||
- **warning** — an exit-code regression (a failure that doesn't propagate, so CI/scripts
|
||||
see success); a `--json`/`--non-interactive` contract violation (breaks scripting);
|
||||
a `SystemError`/`UserError` misclassification (mis-bills the customer); a
|
||||
missing/malformed CHANGELOG entry (breaks release automation). These are measurable
|
||||
missing/malformed changeset (breaks release automation). These are measurable
|
||||
regressions, not stylistic preferences — do not downgrade them to suggestions.
|
||||
- **suggestion** — style, naming, and taste. (Currently dropped entirely — see below.)
|
||||
|
||||
@@ -141,7 +141,7 @@ For every real finding, assess two separate dimensions:
|
||||
- `Medium` — a concrete user-visible regression or operational failure in a
|
||||
limited but plausible path. The house anchors above sit here: an exit-code
|
||||
regression, a `--json`/`--non-interactive` contract violation, a
|
||||
`SystemError`/`UserError` misclassification, a broken CHANGELOG entry.
|
||||
`SystemError`/`UserError` misclassification, a broken changeset.
|
||||
- `Low` — a bounded edge case with little correctness or safety effect. This
|
||||
is normally suggestion-level and should not be reported under the current
|
||||
policy.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!-- You can skip the changelog check by labeling the PR with "no changelog". -->
|
||||
<!-- Add a changeset with `yarn changeset`, or skip the check by labeling the PR with "no changelog". -->
|
||||
|
||||
# Why
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: CHANGELOG.md PR check
|
||||
name: Changeset PR check
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -13,31 +13,55 @@ concurrency:
|
||||
group: changelog-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
pr-changelog-entry:
|
||||
name: Check CHANGELOG.md updated
|
||||
pr-changeset:
|
||||
name: Check for a changeset
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
# Dependabot PRs only update dependencies, so they need no changeset.
|
||||
SKIP_CHECK: >-
|
||||
${{
|
||||
contains(github.event.pull_request.labels.*.name, 'no changelog') ||
|
||||
github.event.pull_request.user.login == 'dependabot[bot]'
|
||||
}}
|
||||
BASE_REF: ${{ github.event.pull_request.base.sha || 'origin/main' }}
|
||||
steps:
|
||||
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
|
||||
- name: Check if CHANGELOG.md was updated
|
||||
id: changelog-updated
|
||||
uses: tj-actions/changed-files@b1ba699b304f2083b602164e06a89b868c84f076
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
with:
|
||||
files: CHANGELOG.md
|
||||
- name: Fail if CHANGELOG.md was not updated and the "no changelog" label is absent
|
||||
if: steps.changelog-updated.outputs.any_changed == 'false' && !contains(github.event.pull_request.labels.*.name, 'no changelog')
|
||||
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
|
||||
with:
|
||||
script: |
|
||||
core.setFailed('Please add a changelog entry!')
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
# The "no changelog" label does not skip this step.
|
||||
- name: Fail if a CHANGELOG.md file was edited
|
||||
run: |
|
||||
edited="$(git diff --name-only "$BASE_REF...HEAD" | grep -E '(^|/)CHANGELOG\.md$' || true)"
|
||||
if [ -n "$edited" ]; then
|
||||
echo "::error::Do not edit CHANGELOG.md files. The release generates them from changesets. Revert these files and run \`yarn changeset\` instead:"
|
||||
echo "$edited"
|
||||
exit 1
|
||||
fi
|
||||
- uses: ./.github/actions/setup-mise
|
||||
if: env.SKIP_CHECK != 'true'
|
||||
- name: Install script dependencies
|
||||
if: env.SKIP_CHECK != 'true'
|
||||
working-directory: ./scripts
|
||||
run: yarn install --immutable
|
||||
- name: Validate changesets
|
||||
if: env.SKIP_CHECK != 'true'
|
||||
working-directory: ./scripts
|
||||
run: yarn validate-changesets "$BASE_REF"
|
||||
- uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
|
||||
if: >-
|
||||
always() &&
|
||||
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
|
||||
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
|
||||
github.event.pull_request.user.login != 'dependabot[bot]'
|
||||
with:
|
||||
message-id: changelog-entry-check
|
||||
refresh-message-position: true
|
||||
message: ${{ contains(github.event.pull_request.labels.*.name, 'no changelog') && '⏩ The changelog entry check has been skipped since the "no changelog" label is present.' || '✅ Thank you for adding the changelog entry!' }}
|
||||
message: ${{ env.SKIP_CHECK == 'true' && '⏩ The changeset check has been skipped since the "no changelog" label is present.' || '✅ Thank you for adding a changeset!' }}
|
||||
message-failure: |
|
||||
❌ It looks like a changelog entry is missing for this PR. Add it manually to CHANGELOG.md.
|
||||
⏩ If this PR doesn't require a changelog entry, such as if it's an internal change that doesn't affect the user experience, you can add the "no changelog" label to the PR.
|
||||
❌ This PR needs a valid changeset. Run `yarn changeset`, select the changed packages and the bump type, and commit the new file in `.changeset/`. Do not edit `CHANGELOG.md`: the release generates it. The "Validate changesets" step log lists the problems.
|
||||
⏩ If this PR doesn't require a changelog entry, such as if it's an internal change that doesn't affect the user experience, you can add the "no changelog" label to the PR. The label does not allow edits to `CHANGELOG.md` files.
|
||||
@@ -46,44 +46,22 @@ jobs:
|
||||
- name: Publish packages to npm
|
||||
run: yarn run -T lerna publish from-package --yes --no-verify-access
|
||||
release-changelog:
|
||||
name: Update changelog and publish release
|
||||
name: Publish the GitHub release
|
||||
runs-on: ubuntu-latest
|
||||
needs: publish-to-npm
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
# The tagged commit already holds this version's section in CHANGELOG.md.
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
with:
|
||||
token: ${{ secrets.EXPO_BOT_PAT }}
|
||||
# The changelog is generated on the branch it is committed to, so the
|
||||
# job never switches branches with a dirty working tree.
|
||||
ref: main
|
||||
fetch-depth: 0
|
||||
- uses: ./.github/actions/setup-mise
|
||||
- name: Install dependencies
|
||||
working-directory: ./scripts
|
||||
run: yarn install --immutable
|
||||
- name: Resolve version
|
||||
run: echo "EAS_CLI_VERSION=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_ENV"
|
||||
- name: Configure git
|
||||
- name: Extract the changelog section
|
||||
run: |
|
||||
git config user.email "[email protected]"
|
||||
git config user.name "Expo CI"
|
||||
- name: Check whether the changelog is already updated
|
||||
run: |
|
||||
if grep -qF "## [$EAS_CLI_VERSION](" CHANGELOG.md; then
|
||||
echo "CHANGELOG.md already has an entry for v$EAS_CLI_VERSION."
|
||||
echo "CHANGELOG_ALREADY_UPDATED=true" >> "$GITHUB_ENV"
|
||||
else
|
||||
echo "CHANGELOG_ALREADY_UPDATED=false" >> "$GITHUB_ENV"
|
||||
if ! grep -qF "## [$EAS_CLI_VERSION](" CHANGELOG.md; then
|
||||
echo "CHANGELOG.md at v$EAS_CLI_VERSION has no section for $EAS_CLI_VERSION." >&2
|
||||
exit 1
|
||||
fi
|
||||
- name: Update changelog
|
||||
if: env.CHANGELOG_ALREADY_UPDATED == 'false'
|
||||
working-directory: ./scripts
|
||||
run: yarn release-changelog "$EAS_CLI_VERSION" > /tmp/current-changelog
|
||||
- name: Reuse the existing changelog entry
|
||||
if: env.CHANGELOG_ALREADY_UPDATED == 'true'
|
||||
run: |
|
||||
{
|
||||
echo "v$EAS_CLI_VERSION"
|
||||
echo
|
||||
@@ -97,16 +75,6 @@ jobs:
|
||||
run: gh release edit "v$EAS_CLI_VERSION" --draft=false -F /tmp/current-changelog
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Commit and push changelog
|
||||
run: |
|
||||
git add CHANGELOG.md
|
||||
if git diff --cached --quiet; then
|
||||
echo "No changelog changes to commit."
|
||||
else
|
||||
git commit -m "update CHANGELOG.md for v$EAS_CLI_VERSION"
|
||||
git pull --rebase --autostash origin main
|
||||
git push
|
||||
fi
|
||||
bump-cli-versions:
|
||||
name: Gate on npm and bump cli-versions.json
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -9,9 +9,13 @@ on:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'scripts/**'
|
||||
- '.changeset/*.mjs'
|
||||
- '.changeset/*.d.mts'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'scripts/**'
|
||||
- '.changeset/*.mjs'
|
||||
- '.changeset/*.d.mts'
|
||||
|
||||
concurrency:
|
||||
group: test-scripts-${{ github.ref }}
|
||||
@@ -26,3 +30,4 @@ jobs:
|
||||
uses: ./.github/actions/setup-mise
|
||||
- run: yarn install --immutable
|
||||
- run: yarn typecheck
|
||||
- run: yarn test
|
||||
@@ -71,8 +71,6 @@ jobs:
|
||||
if: ${{ matrix.coverage }}
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
- if: ${{ matrix.coverage }}
|
||||
run: yarn lint-changelog
|
||||
|
||||
notify-slack:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
type: string
|
||||
required: false
|
||||
description: 'Version number for the release'
|
||||
dry_run:
|
||||
type: boolean
|
||||
required: true
|
||||
@@ -19,7 +15,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.EXPO_BOT_PAT }}
|
||||
INPUT_VERSION: ${{ github.event.inputs.version }}
|
||||
INPUT_DRY_RUN: ${{ github.event.inputs.dry_run }}
|
||||
steps:
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
@@ -29,7 +24,7 @@ jobs:
|
||||
token: ${{ secrets.EXPO_BOT_PAT }}
|
||||
- uses: ./.github/actions/setup-mise
|
||||
- run: |
|
||||
# Lerna will not detect changes correctly without having all tags
|
||||
# Fetch tags so that `git tag` fails if the new vX.Y.Z tag already exists
|
||||
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
||||
# Checkout the main branch
|
||||
git checkout main
|
||||
@@ -37,10 +32,5 @@ jobs:
|
||||
git config --global user.name "Expo CI"
|
||||
yarn install --immutable
|
||||
yarn build
|
||||
if [[ "$INPUT_VERSION" == "" ]]; then
|
||||
echo "Releasing with default version"
|
||||
yarn release
|
||||
else
|
||||
echo "Releasing with version $INPUT_VERSION"
|
||||
yarn release "$INPUT_VERSION"
|
||||
fi
|
||||
# The changesets in .changeset/ set the version bump.
|
||||
yarn release
|
||||
+10
-3
@@ -2,16 +2,22 @@
|
||||
|
||||
This is the log of notable changes to EAS CLI and related packages.
|
||||
|
||||
## main
|
||||
|
||||
### 🛠 Breaking changes
|
||||
## [24.14.0](https://github.com/expo/eas-cli/releases/tag/v24.14.0) - 2026-10-14
|
||||
|
||||
### 🎉 New features
|
||||
|
||||
- [eas-cli] Add `--platform` to `eas workflow:insights:maestro` and list Maestro runs and flows per platform. ([#4613](https://github.com/expo/eas-cli/pull/4613) by [@hSATAC](https://github.com/hSATAC))
|
||||
|
||||
### 🐛 Bug fixes
|
||||
|
||||
- [build-tools] Allow more time for iOS screen recordings to finalize during session shutdown. ([#4626](https://github.com/expo/eas-cli/pull/4626) by [@gwdp](https://github.com/gwdp))
|
||||
|
||||
### 🧹 Chores
|
||||
|
||||
- [eas-cli] Fix the `channel:protect` and `channel:unprotect` descriptions to include Release Managers and Owners, not only admins. ([#4616](https://github.com/expo/eas-cli/pull/4616) by [@byronkarlen](https://github.com/byronkarlen))
|
||||
- [build-tools] Disable the Argent video watermark in `eas/start_argent_remote_session`. ([#4574](https://github.com/expo/eas-cli/pull/4574) by [@szdziedzic](https://github.com/szdziedzic))
|
||||
- [build-tools] Download the upterm binary through the build cache proxy. ([#4442](https://github.com/expo/eas-cli/pull/4442) by [@AHGIJMKLKKZNPJKQR](https://github.com/AHGIJMKLKKZNPJKQR))
|
||||
|
||||
## [24.13.0](https://github.com/expo/eas-cli/releases/tag/v24.13.0) - 2026-10-12
|
||||
|
||||
### 🎉 New features
|
||||
@@ -54,6 +60,7 @@ This is the log of notable changes to EAS CLI and related packages.
|
||||
- [build-tools] Improve the embedded bundle upload output in build logs. ([#4557](https://github.com/expo/eas-cli/pull/4557) by [@gwdp](https://github.com/gwdp))
|
||||
- [build-tools] Allow the unnotarized mitmproxy cask to run in iOS network capture sessions. ([#4556](https://github.com/expo/eas-cli/pull/4556) by [@gwdp](https://github.com/gwdp))
|
||||
- [build-tools] Encode macOS simulator session previews with cwebp, because Homebrew's FFmpeg cannot encode WebP. ([#4549](https://github.com/expo/eas-cli/pull/4549) by [@szdziedzic](https://github.com/szdziedzic))
|
||||
- [build-tools] Open Android URLs with a VIEW intent instead of pinning them to the launch activity. ([#4559](https://github.com/expo/eas-cli/pull/4559) by [@kudo](https://github.com/kudo))
|
||||
|
||||
### 🧹 Chores
|
||||
|
||||
|
||||
@@ -331,12 +331,13 @@ When creating pull requests, make sure to adhere to [PULL_REQUEST_TEMPLATE](./.g
|
||||
|
||||
## Release Process
|
||||
|
||||
1. Update `CHANGELOG.md` in the appropriate package
|
||||
2. Version bump is automated based on changelog:
|
||||
- Breaking changes → MAJOR
|
||||
- New features → MINOR
|
||||
- Otherwise → PATCH
|
||||
3. GitHub Actions workflow handles release automation
|
||||
1. Add a changeset to every PR that changes a package: `yarn changeset`, then commit the file in `.changeset/`. Never edit `CHANGELOG.md` files; the release generates them. See `.changeset/README.md`
|
||||
2. All packages share one version. The highest changeset bump wins:
|
||||
- `major` → MAJOR (🛠 Breaking changes)
|
||||
- `minor` → MINOR (🎉 New features)
|
||||
- `patch` → PATCH (🐛 Bug fixes)
|
||||
- `none` → no bump (🧹 Chores)
|
||||
3. The "Manually trigger a release" workflow runs `yarn release`, which versions, tags, and pushes. See `RELEASING.md`
|
||||
4. Notifications sent to Slack #eas-cli channel
|
||||
|
||||
## Licensing
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ yarn start-allow-unused
|
||||
|
||||
## Format
|
||||
|
||||
- Be sure to update the [`CHANGELOG.md`](./CHANGELOG.md) with changes for every PR. There is a changelog bot that can generate the proper entry for you. The instructions on how to use it are in the PR description placeholder.
|
||||
- Add a changeset for every PR that changes a package: run `yarn changeset` and commit the new file. Do not edit `CHANGELOG.md`; the release generates it. See [`.changeset/README.md`](./.changeset/README.md).
|
||||
- End `async` functions with `Async` like `runAsync`. This is just how we format functions at Expo.
|
||||
- Utilize the unified `Log` module instead of `console.log`.
|
||||
|
||||
|
||||
+26
-7
@@ -1,7 +1,8 @@
|
||||
# Releasing EAS CLI
|
||||
|
||||
1. Invoke the GitHub workflow ["Manually trigger a release"](https://github.com/expo/eas-cli/actions/workflows/trigger-release.yml). The next version is chosen automatically based on the changelog entries. If you want to use different version, pass the version string as an input to the workflow, in semver format, e.g. "1.2.3"
|
||||
2. That's it! GitHub Actions is going to take care of the rest. Watch the #eas-cli Slack channel for a successful release notification.
|
||||
1. Invoke the GitHub workflow ["Manually trigger a release"](https://github.com/expo/eas-cli/actions/workflows/trigger-release.yml). Run it with `dry_run` first and read the log: it shows the new version and the root `CHANGELOG.md` section.
|
||||
2. Run it again with `dry_run` unchecked. The workflow consumes the changesets in `.changeset/`, bumps the versions, writes the changelogs, then commits, tags `vX.Y.Z`, and pushes to `main`.
|
||||
3. That's it! GitHub Actions is going to take care of the rest. Watch the #eas-cli Slack channel for a successful release notification.
|
||||
|
||||
The release also sets the `STAGING` and `PRODUCTION` versions in `cli-versions.json`. See [EAS Build CLI versions](#eas-build-cli-versions).
|
||||
|
||||
@@ -18,10 +19,28 @@ A release updates `STAGING` and `PRODUCTION` to the new version automatically. T
|
||||
|
||||
## Choosing the next version
|
||||
|
||||
As stated above, the next EAS CLI version is chosen automatically based on the existing changelog entries under the unreleased section in **CHANGELOG.md**.
|
||||
The changesets in `.changeset/` choose the next version. All packages share one version (a changesets `fixed` group), and the highest bump in all changesets wins:
|
||||
|
||||
The algorithm works as follows:
|
||||
|
||||
- If there are any entries in the "🛠 Breaking changes" section, bump the MAJOR version.
|
||||
- Otherwise, if there are any entries in the "🎉 New features", bump the MINOR version.
|
||||
- If any changeset has a `major` bump, bump the MAJOR version.
|
||||
- Otherwise, if any changeset has a `minor` bump, bump the MINOR version.
|
||||
- Otherwise, bump the PATCH version.
|
||||
|
||||
A release fails if there are no changesets, or if all of them are `none` or empty. To force a bump, merge a changeset with that bump type. See [`.changeset/README.md`](./.changeset/README.md) for how to write a changeset.
|
||||
|
||||
## What a release writes
|
||||
|
||||
`yarn release` (`scripts/src/versionPackages.ts`) does these steps:
|
||||
|
||||
1. Reads the changesets and computes the new version.
|
||||
2. Runs `changeset version`. This bumps every `package.json`, writes each package's `CHANGELOG.md`, and deletes the changesets.
|
||||
3. Sets the version in `lerna.json`, updates `yarn.lock`, and regenerates `packages/eas-cli/README.md`.
|
||||
4. Adds the new section to the root `CHANGELOG.md`. The GitHub release and the Slack message use this section.
|
||||
5. Commits `vX.Y.Z`, tags it, and pushes. A dry run stops before this step.
|
||||
|
||||
The tag push starts the [release workflow](./.github/workflows/release.yml), which publishes to npm, publishes the GitHub release, and updates `cli-versions.json`.
|
||||
|
||||
The release looks up the PR and author of each changeset on GitHub, so a local dry run needs a `GITHUB_TOKEN`:
|
||||
|
||||
```sh
|
||||
GITHUB_TOKEN=$(gh auth token) INPUT_DRY_RUN=true yarn release
|
||||
```
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"STAGING": "24.13.0",
|
||||
"PRODUCTION": "24.13.0"
|
||||
"STAGING": "24.14.0",
|
||||
"PRODUCTION": "24.14.0"
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"npmClient": "yarn",
|
||||
"version": "24.13.0",
|
||||
"version": "24.14.0",
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
|
||||
}
|
||||
+4
-2
@@ -15,12 +15,14 @@
|
||||
"lint": "oxlint --type-aware --import-plugin --max-warnings=0 --tsconfig ./tsconfig.oxlint.json .",
|
||||
"fmt": "oxfmt .",
|
||||
"fmt:check": "oxfmt --check .",
|
||||
"lint-changelog": "./scripts/bin/run lint-changelog",
|
||||
"release": "lerna run rebuild --concurrency 1 && ./scripts/bin/run release",
|
||||
"test": "lerna run test",
|
||||
"clean": "lerna run clean && rimraf node_modules coverage"
|
||||
"clean": "lerna run clean && rimraf node_modules coverage",
|
||||
"changeset": "changeset"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "3.0.3",
|
||||
"@changesets/get-github-info": "1.0.1",
|
||||
"@types/jest": "29.5.11",
|
||||
"@types/node": "22.20.5",
|
||||
"eslint-plugin-async-protect": "3.1.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/build-tools",
|
||||
"version": "24.13.0",
|
||||
"version": "24.14.0",
|
||||
"bugs": "https://github.com/expo/eas-cli/issues",
|
||||
"license": "BUSL-1.1",
|
||||
"author": "Expo <[email protected]>",
|
||||
|
||||
@@ -11,7 +11,7 @@ import { getEasFunctions } from '../easFunctions';
|
||||
jest.mock('fs');
|
||||
|
||||
describe('hook anchor self-declarations', () => {
|
||||
it('exactly the four v0 functions declare anchors, with these bindings', () => {
|
||||
it('declares the expected hook anchors', () => {
|
||||
const declarations: Record<string, HookAnchorId> = {};
|
||||
for (const buildFunction of getEasFunctions(createCustomBuildContextMock())) {
|
||||
if (buildFunction.__hookId !== undefined) {
|
||||
@@ -24,6 +24,7 @@ describe('hook anchor self-declarations', () => {
|
||||
'eas/checkout': 'checkout',
|
||||
'eas/install_node_modules': 'install_node_modules',
|
||||
'eas/upload_to_asc': 'submit',
|
||||
'eas/submit_to_google_play': 'submit',
|
||||
'eas/maestro_tests': 'maestro_tests',
|
||||
});
|
||||
});
|
||||
@@ -87,6 +88,17 @@ describe('hook anchor self-declarations', () => {
|
||||
bundle_short_version: '1.0.0',
|
||||
},
|
||||
],
|
||||
[
|
||||
'eas/submit_to_google_play',
|
||||
'before_submit',
|
||||
'after_submit',
|
||||
{
|
||||
artifact_path: 'app.aab',
|
||||
artifact_type: 'aab',
|
||||
package_name: 'com.example.app',
|
||||
service_account_key_path: 'key.json',
|
||||
},
|
||||
],
|
||||
[
|
||||
'eas/maestro_tests',
|
||||
'before_maestro_tests',
|
||||
|
||||
@@ -29,6 +29,7 @@ import { createPrebuildBuildFunction } from './functions/prebuild';
|
||||
import { createReadAppConfigBuildFunction } from './functions/readAppConfig';
|
||||
import { createReadIpaInfoBuildFunction } from './functions/readIpaInfo';
|
||||
import { createReadAndroidAppInfoBuildFunction } from './functions/readAndroidAppInfo';
|
||||
import { createSubmitToGooglePlayBuildFunction } from './functions/submitToGooglePlay';
|
||||
import { createReadPackageJsonBuildFunction } from './functions/readPackageJson';
|
||||
import { createRepackBuildFunction } from './functions/repack';
|
||||
import { createReportMaestroTestResultsFunction } from './functions/reportMaestroTestResults';
|
||||
@@ -141,6 +142,7 @@ export function getEasFunctions(ctx: CustomBuildContext): BuildFunction[] {
|
||||
calculateEASUpdateRuntimeVersionFunction(),
|
||||
|
||||
createSubmissionEntityFunction(),
|
||||
createSubmitToGooglePlayBuildFunction(),
|
||||
createUploadToAscBuildFunction(),
|
||||
createUpdateTestFlightMetadataBuildFunction(),
|
||||
|
||||
|
||||
@@ -179,17 +179,7 @@ describe(launchApplicationAsync, () => {
|
||||
expect(mockedSpawn).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
'adb',
|
||||
[
|
||||
'shell',
|
||||
'am',
|
||||
'start',
|
||||
'-a',
|
||||
'android.intent.action.VIEW',
|
||||
'-d',
|
||||
'exp://example.test',
|
||||
'-n',
|
||||
'host.exp.exponent/host.exp.exponent.MainActivity',
|
||||
],
|
||||
['shell', 'am', 'start', '-a', 'android.intent.action.VIEW', '-d', 'exp://example.test'],
|
||||
{ env: {}, logger }
|
||||
);
|
||||
expect(logger.info).toHaveBeenNthCalledWith(
|
||||
@@ -242,17 +232,7 @@ describe(launchApplicationAsync, () => {
|
||||
);
|
||||
expect(mockedSpawn).toHaveBeenCalledWith(
|
||||
'adb',
|
||||
[
|
||||
'shell',
|
||||
'am',
|
||||
'start',
|
||||
'-a',
|
||||
'android.intent.action.VIEW',
|
||||
'-d',
|
||||
'exp://example.test',
|
||||
'-n',
|
||||
'com.example.app/com.example.app.MainActivity',
|
||||
],
|
||||
['shell', 'am', 'start', '-a', 'android.intent.action.VIEW', '-d', 'exp://example.test'],
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
+22
@@ -19,6 +19,7 @@ import {
|
||||
waitForDeviceRunSessionStoppedAsync,
|
||||
waitForFileAsync,
|
||||
} from '../../utils/remoteDeviceRunSession';
|
||||
import { createProcessOutput } from '../../utils/processOutput';
|
||||
import { type StartupTasks, createStartupTasks } from '../../utils/startupTasks';
|
||||
import { runAgentDeviceRemoteSessionAsync } from '../startAgentDeviceRemoteSession';
|
||||
|
||||
@@ -163,6 +164,27 @@ describe('runAgentDeviceRemoteSessionAsync orchestration', () => {
|
||||
expect(mockDaemonStopAsync).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('redacts learned daemon credentials in arbitrary output and retained diagnostics', async () => {
|
||||
const logger = { info: jest.fn(), warn: jest.fn(), child: jest.fn().mockReturnThis() };
|
||||
const token = 'daemon secret/+';
|
||||
jest.mocked(waitForFileAsync).mockResolvedValue({ port: 5678, token });
|
||||
jest.mocked(startNgrokTunnelAsync).mockImplementation(async () => {
|
||||
const options = jest.mocked(spawnDetached).mock.calls[0][0];
|
||||
expect(options.secrets).toContain(token);
|
||||
const output = createProcessOutput(options.logger, options.secrets);
|
||||
output.stdout.append('unrecognized value: daemon sec');
|
||||
output.stdout.append('ret/+\n');
|
||||
output.stderr.append(`escaped value: ${encodeURIComponent(token)}\n`);
|
||||
expect(output.getOutput()).toBe(
|
||||
'unrecognized value: [REDACTED]\nescaped value: [REDACTED]\n'
|
||||
);
|
||||
return { url: 'https://daemon.test', subdomainId: 'daemon', stopAsync: mockTunnelStopAsync };
|
||||
});
|
||||
await runAsync(logger, BuildRuntimePlatform.DARWIN);
|
||||
expect(JSON.stringify(logger.info.mock.calls)).not.toContain(token);
|
||||
expect(JSON.stringify(logger.info.mock.calls)).not.toContain(encodeURIComponent(token));
|
||||
});
|
||||
|
||||
it('hands network capture to serve-sim', async () => {
|
||||
const logger = { info: jest.fn(), warn: jest.fn(), child: jest.fn().mockReturnThis() };
|
||||
|
||||
|
||||
+46
-1
@@ -93,6 +93,28 @@ describe(startAgentDeviceDaemonAsync, () => {
|
||||
}) as never);
|
||||
});
|
||||
|
||||
it.each([false, true])(
|
||||
'shares the daemon secret list through git fallback=%s',
|
||||
async fallback => {
|
||||
if (fallback) {
|
||||
jest.mocked(spawn).mockResolvedValue({ stdout: '' } as never);
|
||||
}
|
||||
const secrets: string[] = [];
|
||||
const handle = await startAgentDeviceDaemonAsync({
|
||||
packageVersion: '1.2.3',
|
||||
env: {},
|
||||
logger,
|
||||
secrets,
|
||||
});
|
||||
const options = jest.mocked(spawnDetached).mock.calls[0][0];
|
||||
expect(options.command).toBe(fallback ? 'bun' : 'node');
|
||||
expect(options.secrets).toBe(secrets);
|
||||
secrets.push('learned-daemon-token');
|
||||
expect(options.secrets).toContain('learned-daemon-token');
|
||||
await handle.stopAsync();
|
||||
}
|
||||
);
|
||||
|
||||
it('installs with bun add by default and launches the published daemon', async () => {
|
||||
const handle = await startAgentDeviceDaemonAsync({
|
||||
packageVersion: '1.2.3',
|
||||
@@ -108,6 +130,8 @@ describe(startAgentDeviceDaemonAsync, () => {
|
||||
const addCwd = jest.mocked(spawn).mock.calls[0][2]?.cwd as string;
|
||||
expect(spawnDetached).toHaveBeenCalledWith({
|
||||
command: 'node',
|
||||
logger,
|
||||
secrets: undefined,
|
||||
args: [path.join(addCwd, 'node_modules/agent-device/dist/src/internal/daemon.js')],
|
||||
env: expect.objectContaining({
|
||||
AGENT_DEVICE_DAEMON_SERVER_MODE: 'http',
|
||||
@@ -121,6 +145,20 @@ describe(startAgentDeviceDaemonAsync, () => {
|
||||
await expect(fs.promises.access(addCwd)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('removes the install directory when the daemon cannot be stopped', async () => {
|
||||
const stopError = new Error('drain timed out');
|
||||
stopAsync.mockRejectedValueOnce(stopError);
|
||||
const handle = await startAgentDeviceDaemonAsync({
|
||||
packageVersion: '1.2.3',
|
||||
env: {},
|
||||
logger,
|
||||
});
|
||||
const addCwd = jest.mocked(spawn).mock.calls[0][2]?.cwd as string;
|
||||
|
||||
await expect(handle.stopAsync()).rejects.toBe(stopError);
|
||||
await expect(fs.promises.access(addCwd)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('installs with npm when EAS_OVERRIDE_PACKAGE_MANAGER is npm', async () => {
|
||||
await startAgentDeviceDaemonAsync({
|
||||
packageVersion: undefined,
|
||||
@@ -136,10 +174,15 @@ describe(startAgentDeviceDaemonAsync, () => {
|
||||
});
|
||||
|
||||
it('kills the install and does not fall back to git when aborted', async () => {
|
||||
let installStarted!: () => void;
|
||||
const started = new Promise<void>(resolve => {
|
||||
installStarted = resolve;
|
||||
});
|
||||
jest.mocked(spawn).mockImplementation(
|
||||
((_command: string, _args: string[], options?: { signal?: AbortSignal }) =>
|
||||
new Promise((_resolve, reject) => {
|
||||
options!.signal!.addEventListener('abort', () => reject(options!.signal!.reason));
|
||||
installStarted();
|
||||
})) as never
|
||||
);
|
||||
const controller = new AbortController();
|
||||
@@ -151,7 +194,7 @@ describe(startAgentDeviceDaemonAsync, () => {
|
||||
logger,
|
||||
signal: controller.signal,
|
||||
});
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
await started;
|
||||
controller.abort(failure);
|
||||
|
||||
await expect(daemon).rejects.toBe(failure);
|
||||
@@ -199,6 +242,8 @@ describe(startAgentDeviceDaemonAsync, () => {
|
||||
);
|
||||
expect(spawnDetached).toHaveBeenCalledWith({
|
||||
command: 'bun',
|
||||
logger,
|
||||
secrets: undefined,
|
||||
args: ['run', 'src/daemon.ts'],
|
||||
cwd: '/tmp/agent-device-src',
|
||||
env: expect.objectContaining({
|
||||
|
||||
@@ -51,9 +51,12 @@ describe(resolveAppiumDeviceAsync, () => {
|
||||
});
|
||||
|
||||
it('returns XCUITest capabilities for the booted iOS simulator', async () => {
|
||||
jest
|
||||
.mocked(IosSimulatorUtils.getAvailableDevicesAsync)
|
||||
.mockResolvedValue([{ udid: 'ios-simulator-id' } as never]);
|
||||
jest.mocked(IosSimulatorUtils.getAvailableDevicesAsync).mockResolvedValue([
|
||||
{
|
||||
udid: 'ios-simulator-id',
|
||||
runtime: 'com.apple.CoreSimulator.SimRuntime.iOS-26-5',
|
||||
} as never,
|
||||
]);
|
||||
|
||||
await expect(
|
||||
resolveAppiumDeviceAsync({
|
||||
@@ -66,6 +69,7 @@ describe(resolveAppiumDeviceAsync, () => {
|
||||
automationName: 'XCUITest',
|
||||
driverName: 'xcuitest',
|
||||
udid: 'ios-simulator-id',
|
||||
runtimeIdentifier: 'com.apple.CoreSimulator.SimRuntime.iOS-26-5',
|
||||
});
|
||||
expect(selectXcodeDeveloperDirectoryAsync).toHaveBeenCalledWith({ env: {}, logger });
|
||||
expect(IosSimulatorUtils.getAvailableDevicesAsync).toHaveBeenCalledWith({
|
||||
|
||||
+52
-1
@@ -188,7 +188,7 @@ describe('createStartArgentRemoteSessionBuildFunction orchestration', () => {
|
||||
}
|
||||
);
|
||||
|
||||
it('enables the event log flag, shares one path, and starts/stops the collector', async () => {
|
||||
it('enables the event log flag, disables the video watermark, shares one path, and starts/stops the collector', async () => {
|
||||
const ctx = {} as unknown as CustomBuildContext;
|
||||
const buildFunction = createStartArgentRemoteSessionBuildFunction(ctx);
|
||||
|
||||
@@ -231,6 +231,20 @@ describe('createStartArgentRemoteSessionBuildFunction orchestration', () => {
|
||||
jest.mocked(spawnDetached).mock.invocationCallOrder[0]
|
||||
);
|
||||
|
||||
// (2b) The video watermark flag is disabled, before the tool-server is launched.
|
||||
const disableWatermarkIndex = spawnCalls.findIndex(
|
||||
([command, args]) =>
|
||||
command === 'bun' &&
|
||||
Array.isArray(args) &&
|
||||
args[0] === 'x' &&
|
||||
args.includes('disable') &&
|
||||
args.includes('video-watermark')
|
||||
);
|
||||
expect(disableWatermarkIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(jest.mocked(spawn).mock.invocationCallOrder[disableWatermarkIndex]).toBeLessThan(
|
||||
jest.mocked(spawnDetached).mock.invocationCallOrder[0]
|
||||
);
|
||||
|
||||
// (3) The tool-server and the collector are pinned to the exact same event log path.
|
||||
const serverEnv = jest.mocked(spawnDetached).mock.calls[0][0].env;
|
||||
expect(serverEnv.ARGENT_EVENT_LOG).toBe(EXPECTED_EVENT_LOG_PATH);
|
||||
@@ -267,6 +281,43 @@ describe('createStartArgentRemoteSessionBuildFunction orchestration', () => {
|
||||
expect(mockPreviewStopAsync).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('continues the session when disabling the video watermark fails', async () => {
|
||||
const error = new Error('bun x failed');
|
||||
jest
|
||||
.mocked(spawn)
|
||||
.mockImplementation(
|
||||
(_command, args) =>
|
||||
(args.includes('video-watermark')
|
||||
? Promise.reject(error)
|
||||
: Promise.resolve(undefined)) as never
|
||||
);
|
||||
const logger = { info: jest.fn(), warn: jest.fn() };
|
||||
const buildFunction = createStartArgentRemoteSessionBuildFunction({} as CustomBuildContext);
|
||||
|
||||
await buildFunction.fn!(
|
||||
{
|
||||
logger,
|
||||
global: { runtimePlatform: BuildRuntimePlatform.LINUX },
|
||||
} as unknown as BuildStepContext,
|
||||
{
|
||||
inputs: {
|
||||
package_version: { value: undefined },
|
||||
max_idle_time_minutes: { value: undefined },
|
||||
},
|
||||
outputs: {},
|
||||
env: {},
|
||||
} as never
|
||||
);
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
{ err: error },
|
||||
expect.stringContaining('Could not disable the Argent video watermark')
|
||||
);
|
||||
expect(spawnDetached).toHaveBeenCalledTimes(1);
|
||||
expect(uploadRemoteSessionConfigAsync).toHaveBeenCalledTimes(1);
|
||||
expect(waitForDeviceRunSessionStoppedAsync).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('hands the launch inputs to serve-sim and announces them on an iOS session', async () => {
|
||||
const ctx = {} as unknown as CustomBuildContext;
|
||||
const logger = { info: jest.fn(), warn: jest.fn() };
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
import { SystemError, UserError } from '@expo/eas-build-job';
|
||||
import nock from 'nock';
|
||||
import fs from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
import { createGlobalContextMock } from '../../../__tests__/utils/context';
|
||||
import {
|
||||
api,
|
||||
editPath,
|
||||
mockToken,
|
||||
packageName,
|
||||
serviceAccount,
|
||||
} from '../../utils/android/__tests__/googlePlayTestUtils';
|
||||
import { createSubmitToGooglePlayBuildFunction } from '../submitToGooglePlay';
|
||||
|
||||
jest.unmock('node-fetch');
|
||||
jest.unmock('fs');
|
||||
jest.unmock('node:fs');
|
||||
jest.unmock('fs/promises');
|
||||
jest.unmock('node:fs/promises');
|
||||
|
||||
let directory: string;
|
||||
let keyPath: string;
|
||||
let artifactPath: string;
|
||||
const session = '/upload/test-session';
|
||||
const createPath = `/androidpublisher/v3/applications/${packageName}/edits`;
|
||||
beforeEach(async () => {
|
||||
nock.disableNetConnect();
|
||||
directory = await fs.mkdtemp(path.join(os.tmpdir(), 'play-submit-test-'));
|
||||
keyPath = path.join(directory, 'key.json');
|
||||
artifactPath = path.join(directory, 'app.aab');
|
||||
await fs.writeFile(artifactPath, 'binary');
|
||||
await fs.writeFile(
|
||||
keyPath,
|
||||
JSON.stringify({
|
||||
...serviceAccount,
|
||||
type: 'service_account',
|
||||
private_key: serviceAccount.private_key.export({ format: 'pem', type: 'pkcs8' }),
|
||||
})
|
||||
);
|
||||
});
|
||||
afterEach(async () => {
|
||||
const pending = nock.pendingMocks();
|
||||
nock.cleanAll();
|
||||
nock.enableNetConnect();
|
||||
await fs.rm(directory, { recursive: true, force: true });
|
||||
expect(pending).toEqual([]);
|
||||
});
|
||||
function submission(extra: Record<string, unknown> = {}, signal?: AbortSignal) {
|
||||
const fn = createSubmitToGooglePlayBuildFunction();
|
||||
const step = fn.createBuildStepFromFunctionCall(createGlobalContextMock({}), {
|
||||
callInputs: {
|
||||
artifact_path: artifactPath,
|
||||
artifact_type: 'aab',
|
||||
package_name: packageName,
|
||||
service_account_key_path: keyPath,
|
||||
...extra,
|
||||
},
|
||||
});
|
||||
const setters = step.outputs.map(output => jest.spyOn(output, 'set'));
|
||||
return {
|
||||
setters,
|
||||
step,
|
||||
run: async () =>
|
||||
await fn.fn!(step.ctx, {
|
||||
inputs: Object.fromEntries(
|
||||
step.inputs!.map(input => [input.id, { value: input.rawValue }])
|
||||
),
|
||||
outputs: Object.fromEntries(step.outputs.map(output => [output.id, output])),
|
||||
env: {},
|
||||
signal,
|
||||
}),
|
||||
};
|
||||
}
|
||||
function upload() {
|
||||
mockToken();
|
||||
api().post(createPath).reply(200, { id: 'edit' });
|
||||
api()
|
||||
.post(`/upload${editPath}/bundles`)
|
||||
.query({ uploadType: 'resumable' })
|
||||
.reply(200, '', { Location: `https://androidpublisher.googleapis.com${session}` });
|
||||
nock('https://androidpublisher.googleapis.com').put(session).reply(200, { versionCode: 145 });
|
||||
}
|
||||
it.each([
|
||||
['completed', undefined, { status: 'completed' }],
|
||||
['completed', 0, 'invalid'],
|
||||
['completed', 0.25, { status: 'inProgress', userFraction: 0.25 }],
|
||||
['completed', 1, { status: 'completed' }],
|
||||
['draft', undefined, { status: 'draft' }],
|
||||
['draft', 0, 'invalid'],
|
||||
['draft', 0.25, 'invalid'],
|
||||
['draft', 1, 'invalid'],
|
||||
['halted', undefined, 'invalid'],
|
||||
['halted', 0, 'invalid'],
|
||||
['halted', 0.25, 'invalid'],
|
||||
['halted', 1, 'invalid'],
|
||||
['inProgress', undefined, 'invalid'],
|
||||
['inProgress', 0, 'invalid'],
|
||||
['inProgress', 0.25, { status: 'inProgress', userFraction: 0.25 }],
|
||||
['inProgress', 1, { status: 'completed' }],
|
||||
] as const)('validates and submits %s with rollout %s', async (status, rollout, expected) => {
|
||||
const task = submission({
|
||||
release_status: status,
|
||||
...(rollout !== undefined ? { rollout } : {}),
|
||||
});
|
||||
if (expected === 'invalid') {
|
||||
await expect(task.run()).rejects.toThrow(status === 'halted' ? /release_status/ : /rollout/);
|
||||
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
|
||||
return;
|
||||
}
|
||||
upload();
|
||||
api()
|
||||
.put(`${editPath}/tracks/internal`, {
|
||||
track: 'internal',
|
||||
releases: [{ ...expected, versionCodes: ['145'] }],
|
||||
})
|
||||
.reply(200, { track: 'internal' });
|
||||
api()
|
||||
.post(`${editPath}:commit`)
|
||||
.query({})
|
||||
.reply(() => {
|
||||
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
|
||||
return [200, { id: 'edit' }];
|
||||
});
|
||||
await task.run();
|
||||
expect(task.setters.map(set => set.mock.calls)).toEqual([[['145']]]);
|
||||
});
|
||||
it('runs the step with a string rollout and validates its required output', async () => {
|
||||
upload();
|
||||
api()
|
||||
.put(`${editPath}/tracks/internal`, {
|
||||
track: 'internal',
|
||||
releases: [{ status: 'inProgress', userFraction: 0.25, versionCodes: ['145'] }],
|
||||
})
|
||||
.reply(200, { track: 'internal' });
|
||||
api().post(`${editPath}:commit`).query({}).reply(200, { id: 'edit' });
|
||||
const { step } = submission({ rollout: '0.25' });
|
||||
expect(step.__hookId).toBe('submit');
|
||||
await step.executeAsync();
|
||||
expect(step.outputs[0].value).toBe('145');
|
||||
});
|
||||
it.each(['upload', 'track', 'abort'] as const)(
|
||||
'deletes the edit after %s failure and leaves outputs unset',
|
||||
async failure => {
|
||||
const controller = new AbortController();
|
||||
const task = submission({}, controller.signal);
|
||||
mockToken();
|
||||
api().post(createPath).reply(200, { id: 'edit' });
|
||||
api()
|
||||
.post(`/upload${editPath}/bundles`)
|
||||
.query({ uploadType: 'resumable' })
|
||||
.reply(() => {
|
||||
if (failure === 'abort') {
|
||||
controller.abort(new Error('step timed out'));
|
||||
}
|
||||
return failure === 'upload'
|
||||
? [400, { error: { message: 'rejected binary' } }]
|
||||
: [200, '', { Location: `https://androidpublisher.googleapis.com${session}` }];
|
||||
});
|
||||
if (failure === 'track') {
|
||||
nock('https://androidpublisher.googleapis.com').put(session).reply(200, { versionCode: 145 });
|
||||
api()
|
||||
.put(`${editPath}/tracks/internal`)
|
||||
.reply(400, { error: { message: 'unknown track' } });
|
||||
}
|
||||
api().delete(editPath).reply(204);
|
||||
await expect(task.run()).rejects.toThrow();
|
||||
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
|
||||
}
|
||||
);
|
||||
it('preserves the original failure when cleanup fails', async () => {
|
||||
upload();
|
||||
api()
|
||||
.put(`${editPath}/tracks/internal`)
|
||||
.reply(400, { error: { message: 'unknown track' } });
|
||||
api().delete(editPath).reply(500);
|
||||
await expect(submission().run()).rejects.toMatchObject({
|
||||
cause: expect.objectContaining({ apiMessage: 'unknown track' }),
|
||||
});
|
||||
});
|
||||
it('does not delete the edit or publish outputs when commit outcome is unknown', async () => {
|
||||
upload();
|
||||
api().put(`${editPath}/tracks/internal`).reply(200, { track: 'internal' });
|
||||
api().post(`${editPath}:commit`).query(true).reply(503);
|
||||
let deleted = false;
|
||||
api()
|
||||
.delete(editPath)
|
||||
.optionally()
|
||||
.reply(() => {
|
||||
deleted = true;
|
||||
return [204];
|
||||
});
|
||||
const task = submission();
|
||||
await expect(task.run()).rejects.toBeInstanceOf(SystemError);
|
||||
expect(deleted).toBe(false);
|
||||
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
|
||||
});
|
||||
it('reports a missing service-account file with its path', async () => {
|
||||
const missing = path.join(directory, 'missing.json');
|
||||
await expect(submission({ service_account_key_path: missing }).run()).rejects.toThrow(
|
||||
`Service-account key file not found at ${missing}`
|
||||
);
|
||||
});
|
||||
it('does not expose invalid credential contents', async () => {
|
||||
await fs.writeFile(keyPath, 'PRIVATE_SECRET_INVALID_JSON');
|
||||
const error = await submission()
|
||||
.run()
|
||||
.catch(error => error);
|
||||
expect(error).toBeInstanceOf(UserError);
|
||||
expect(JSON.stringify(error) + String(error)).not.toContain('PRIVATE_SECRET');
|
||||
});
|
||||
|
||||
it('preserves the cause when the service-account file cannot be read', async () => {
|
||||
const cause = Object.assign(new Error('permission denied'), { code: 'EACCES' });
|
||||
const read = jest.spyOn(fs, 'readFile').mockRejectedValueOnce(cause);
|
||||
try {
|
||||
await expect(submission().run()).rejects.toMatchObject({ cause });
|
||||
} finally {
|
||||
read.mockRestore();
|
||||
}
|
||||
});
|
||||
@@ -118,17 +118,7 @@ export async function launchApplicationAsync({
|
||||
logger.info(`Opening ${openUrl} in ${applicationIdentifier}.`);
|
||||
await spawn(
|
||||
'adb',
|
||||
[
|
||||
'shell',
|
||||
'am',
|
||||
'start',
|
||||
'-a',
|
||||
'android.intent.action.VIEW',
|
||||
'-d',
|
||||
openUrl,
|
||||
'-n',
|
||||
`${applicationIdentifier}/${activityName}`,
|
||||
],
|
||||
['shell', 'am', 'start', '-a', 'android.intent.action.VIEW', '-d', openUrl],
|
||||
{ env, logger }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@ export async function runAgentDeviceRemoteSessionAsync(
|
||||
let sessionHost: DeviceSessionHost | undefined;
|
||||
let eventCollection: Awaited<ReturnType<typeof startAgentDeviceEventCollectionAsync>> | undefined;
|
||||
let sessionFailed = false;
|
||||
const daemonSecrets = [ngrokAuthtoken];
|
||||
|
||||
// Each task stores what it started, so the teardown below can stop it even when
|
||||
// another task failed first.
|
||||
@@ -131,12 +132,14 @@ export async function runAgentDeviceRemoteSessionAsync(
|
||||
env,
|
||||
logger: taskLogger,
|
||||
signal: tasks.signal,
|
||||
secrets: daemonSecrets,
|
||||
});
|
||||
|
||||
taskLogger.info(`Waiting for daemon credentials at ${DAEMON_JSON_PATH}.`);
|
||||
// The daemon is stored above, so the teardown stops it. The wait itself is bounded
|
||||
// (STARTUP_TIMEOUT_MS) and only reads a file, so it may finish in the background.
|
||||
const daemonInfo = await tasks.untilAborted(waitForDaemonInfoAsync({ daemonProcess }));
|
||||
daemonSecrets.push(daemonInfo.token);
|
||||
taskLogger.info(`Daemon is listening on port ${daemonInfo.port}; loaded auth token.`);
|
||||
|
||||
tasks.signal.throwIfAborted();
|
||||
@@ -155,6 +158,7 @@ export async function runAgentDeviceRemoteSessionAsync(
|
||||
await tasks.untilAborted(device.booted);
|
||||
tasks.signal.throwIfAborted();
|
||||
sessionHost = await startDeviceSessionHostAsync(ctx, {
|
||||
separateLogPhase: true,
|
||||
runtimePlatform,
|
||||
env,
|
||||
logger: taskLogger,
|
||||
@@ -267,12 +271,14 @@ export async function startAgentDeviceDaemonAsync({
|
||||
env,
|
||||
logger,
|
||||
signal,
|
||||
secrets,
|
||||
}: {
|
||||
packageVersion: string | undefined;
|
||||
env: BuildStepEnv;
|
||||
logger: bunyan;
|
||||
/** Kills the install and stops before the daemon starts, when aborted. No git fallback then. */
|
||||
signal?: AbortSignal;
|
||||
secrets?: string[];
|
||||
}): Promise<DetachedProcessHandle> {
|
||||
const packageSpec = createAgentDevicePackageSpec(packageVersion);
|
||||
const packageManager = resolveConfiguredPackageManager(env, PackageManager.BUN);
|
||||
@@ -298,12 +304,17 @@ export async function startAgentDeviceDaemonAsync({
|
||||
command: 'node',
|
||||
args: [daemonPath],
|
||||
env: { ...env, ...AGENT_DEVICE_DAEMON_ENV },
|
||||
logger,
|
||||
secrets,
|
||||
});
|
||||
return {
|
||||
...daemonProcess,
|
||||
stopAsync: async () => {
|
||||
await daemonProcess.stopAsync();
|
||||
await fs.promises.rm(installDir, { recursive: true, force: true });
|
||||
try {
|
||||
await daemonProcess.stopAsync();
|
||||
} finally {
|
||||
await fs.promises.rm(installDir, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
};
|
||||
} catch (err) {
|
||||
@@ -334,7 +345,13 @@ export async function startAgentDeviceDaemonAsync({
|
||||
logger.warn(
|
||||
`Failed to start daemon from ${packageSpec} via ${packageManager}; falling back to git clone: ${error.message}`
|
||||
);
|
||||
return await startAgentDeviceDaemonFromGitAsync({ packageVersion, env, logger, signal });
|
||||
return await startAgentDeviceDaemonFromGitAsync({
|
||||
packageVersion,
|
||||
env,
|
||||
logger,
|
||||
signal,
|
||||
secrets,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,11 +382,13 @@ async function startAgentDeviceDaemonFromGitAsync({
|
||||
env,
|
||||
logger,
|
||||
signal,
|
||||
secrets,
|
||||
}: {
|
||||
packageVersion: string | undefined;
|
||||
env: BuildStepEnv;
|
||||
logger: bunyan;
|
||||
signal?: AbortSignal;
|
||||
secrets?: string[];
|
||||
}): Promise<DetachedProcessHandle> {
|
||||
logger.info(
|
||||
packageVersion
|
||||
@@ -396,6 +415,8 @@ async function startAgentDeviceDaemonFromGitAsync({
|
||||
args: ['run', 'src/daemon.ts'],
|
||||
cwd: SRC_DIR,
|
||||
env: { ...env, ...AGENT_DEVICE_DAEMON_ENV },
|
||||
logger,
|
||||
secrets,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
import { sleepAsync } from '../../utils/retry';
|
||||
import { turtleFetch } from '../../utils/turtleFetch';
|
||||
import { startAppiumEventCollectionAsync } from '../utils/appiumEvents';
|
||||
import { preparePreinstalledWdaAsync } from '../utils/preinstalledWda';
|
||||
import {
|
||||
createServeSimLaunchInputProviders,
|
||||
describeServeSimLaunch,
|
||||
@@ -121,6 +122,13 @@ export function createStartAppiumRemoteSessionBuildFunction(
|
||||
ensureFfmpegInstalledOnceAsync({ runtimePlatform, env, logger }),
|
||||
]);
|
||||
const { appiumHome, appiumBinPath, appiumEnv } = appiumInstall.enforceValue();
|
||||
const wdaCapabilities = await preparePreinstalledWdaAsync({
|
||||
runtimeIdentifier: device.runtimeIdentifier,
|
||||
appiumHome,
|
||||
appiumBinPath,
|
||||
appiumEnv,
|
||||
logger,
|
||||
});
|
||||
|
||||
const appiumProcess = spawnDetached({
|
||||
command: appiumBinPath,
|
||||
@@ -139,7 +147,7 @@ export function createStartAppiumRemoteSessionBuildFunction(
|
||||
'--allow-insecure',
|
||||
'*:session_discovery',
|
||||
'--default-capabilities',
|
||||
JSON.stringify({ 'appium:eventTimings': true }),
|
||||
JSON.stringify({ 'appium:eventTimings': true, ...wdaCapabilities }),
|
||||
],
|
||||
env: appiumEnv,
|
||||
});
|
||||
@@ -264,6 +272,7 @@ export type AppiumDevice = {
|
||||
automationName: 'XCUITest' | 'UiAutomator2';
|
||||
driverName: 'xcuitest' | 'uiautomator2';
|
||||
udid: string;
|
||||
runtimeIdentifier?: string;
|
||||
};
|
||||
|
||||
export async function resolveAppiumDeviceAsync({
|
||||
@@ -290,6 +299,7 @@ export async function resolveAppiumDeviceAsync({
|
||||
automationName: 'XCUITest',
|
||||
driverName: 'xcuitest',
|
||||
udid: bootedDevice.udid,
|
||||
runtimeIdentifier: bootedDevice.runtime,
|
||||
};
|
||||
}
|
||||
case BuildRuntimePlatform.LINUX: {
|
||||
|
||||
@@ -55,6 +55,9 @@ export const MIN_ARGENT_REMOTE_SESSION_VERSION = '0.16.0';
|
||||
const ARGENT_ARTIFACTS_LIST_ENDPOINT_FLAG = 'artifacts-list-endpoint';
|
||||
// Tells the tool-server to write its structured event log so we can collect session events.
|
||||
const ARGENT_EVENT_LOG_FLAG = 'tool-server-event-log';
|
||||
// On by default in Argent (since 0.17.0); we turn it off so recorded videos have no Argent
|
||||
// watermark. Older versions that don't know the flag treat `disable` as a no-op.
|
||||
const ARGENT_VIDEO_WATERMARK_FLAG = 'video-watermark';
|
||||
const ARGENT_STATE_DIR = path.join(os.homedir(), '.argent');
|
||||
// Pin the event log path explicitly and hand the same value to the tool-server (via
|
||||
// ARGENT_EVENT_LOG) and the collector, so an ambient ARGENT_EVENT_LOG or a future change to
|
||||
@@ -163,6 +166,22 @@ export function createStartArgentRemoteSessionBuildFunction(
|
||||
]);
|
||||
await spawn(enableEventLog.command, enableEventLog.args, { env, logger });
|
||||
|
||||
logger.info('Disabling the Argent video watermark flag.');
|
||||
const disableVideoWatermark = argentExec([
|
||||
`${ARGENT_PACKAGE_NAME}@${versionSpec}`,
|
||||
'disable',
|
||||
ARGENT_VIDEO_WATERMARK_FLAG,
|
||||
]);
|
||||
// The watermark is cosmetic, so a failure here must not fail the session.
|
||||
try {
|
||||
await spawn(disableVideoWatermark.command, disableVideoWatermark.args, { env, logger });
|
||||
} catch (err) {
|
||||
logger.warn(
|
||||
{ err },
|
||||
'Could not disable the Argent video watermark, so recorded videos may include it. Continuing the session.'
|
||||
);
|
||||
}
|
||||
|
||||
const startServer = argentExec([
|
||||
`${ARGENT_PACKAGE_NAME}@${versionSpec}`,
|
||||
'server',
|
||||
|
||||
@@ -156,6 +156,7 @@ export function createStartLocalEgressBuildFunction(): BuildFunction {
|
||||
controlPort,
|
||||
authfilePath,
|
||||
env,
|
||||
logger,
|
||||
signal: startupSignal,
|
||||
});
|
||||
server = started.process;
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
import { UserError } from '@expo/eas-build-job';
|
||||
import { bunyan } from '@expo/logger';
|
||||
import {
|
||||
BuildFunction,
|
||||
BuildStepInput,
|
||||
BuildStepInputValueTypeName,
|
||||
BuildStepOutput,
|
||||
} from '@expo/steps';
|
||||
import path from 'node:path';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { GooglePlayAuthUtils } from '../utils/android/GooglePlayAuthUtils';
|
||||
import { GooglePlayClient, ReleaseStatus, ReleaseStatusZ } from '../utils/android/GooglePlayClient';
|
||||
import {
|
||||
GooglePlayCommitOutcomeUnknownError,
|
||||
GooglePlayUtils,
|
||||
} from '../utils/android/GooglePlayUtils';
|
||||
import { AndroidArtifactType } from '../utils/android/appArtifact';
|
||||
|
||||
const InputsZ = z
|
||||
.object({
|
||||
artifact_path: z.string().min(1),
|
||||
artifact_type: z.enum(['apk', 'aab']),
|
||||
package_name: z.string().regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/),
|
||||
service_account_key_path: z.string().min(1),
|
||||
track: z.string().trim().min(1).default('internal'),
|
||||
release_status: ReleaseStatusZ.exclude(['halted']).default('completed'),
|
||||
rollout: z.number().finite().gt(0).max(1).optional(),
|
||||
changelog: z.string().optional(),
|
||||
changes_not_sent_for_review: z.boolean().default(false),
|
||||
})
|
||||
.superRefine(({ release_status, rollout }, ctx) => {
|
||||
if (release_status === 'draft' && rollout !== undefined) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
path: ['rollout'],
|
||||
message: 'A draft release cannot have a rollout.',
|
||||
});
|
||||
}
|
||||
if (release_status === 'inProgress' && rollout === undefined) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
path: ['rollout'],
|
||||
message: 'An inProgress release requires a rollout greater than 0 and at most 1.',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Does not inspect the binary. The caller must run eas/read_android_app_info and
|
||||
// compare its package_name with the intended application ID before calling this.
|
||||
export function createSubmitToGooglePlayBuildFunction(): BuildFunction {
|
||||
return new BuildFunction({
|
||||
namespace: 'eas',
|
||||
id: 'submit_to_google_play',
|
||||
name: 'Submit to Google Play',
|
||||
__metricsId: 'eas/submit_to_google_play',
|
||||
__hookId: 'submit',
|
||||
inputProviders: [
|
||||
BuildStepInput.createProvider({
|
||||
id: 'artifact_path',
|
||||
required: true,
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'artifact_type',
|
||||
required: true,
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'package_name',
|
||||
required: true,
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'service_account_key_path',
|
||||
required: true,
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'track',
|
||||
required: false,
|
||||
defaultValue: 'internal',
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'release_status',
|
||||
required: false,
|
||||
defaultValue: 'completed',
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'rollout',
|
||||
required: false,
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.NUMBER,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'changelog',
|
||||
required: false,
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
|
||||
}),
|
||||
BuildStepInput.createProvider({
|
||||
id: 'changes_not_sent_for_review',
|
||||
required: false,
|
||||
defaultValue: false,
|
||||
allowedValueTypeName: BuildStepInputValueTypeName.BOOLEAN,
|
||||
}),
|
||||
],
|
||||
outputProviders: [BuildStepOutput.createProvider({ id: 'version_code', required: true })],
|
||||
fn: async (ctx, { inputs, outputs, signal }) => {
|
||||
signal?.throwIfAborted();
|
||||
const parsed = InputsZ.safeParse(
|
||||
Object.fromEntries(Object.entries(inputs).map(([key, input]) => [key, input.value]))
|
||||
);
|
||||
if (!parsed.success) {
|
||||
throw new UserError(
|
||||
'EAS_GOOGLE_PLAY_INVALID_INPUT',
|
||||
'Invalid Google Play submission inputs:\n' + z.prettifyError(parsed.error)
|
||||
);
|
||||
}
|
||||
const submission = parsed.data;
|
||||
const { release_status: requested, rollout } = submission;
|
||||
// Match Fastlane: a partial rollout overrides the requested status to inProgress.
|
||||
const release: {
|
||||
status: ReleaseStatus;
|
||||
userFraction?: number;
|
||||
} =
|
||||
rollout !== undefined && rollout < 1
|
||||
? { status: 'inProgress', userFraction: rollout }
|
||||
: { status: requested === 'inProgress' ? 'completed' : requested };
|
||||
const credentials = await GooglePlayAuthUtils.loadGoogleServiceAccountAsync({
|
||||
keyPath: path.resolve(ctx.workingDirectory, submission.service_account_key_path),
|
||||
});
|
||||
const artifactPath = path.resolve(ctx.workingDirectory, submission.artifact_path);
|
||||
const client = new GooglePlayClient(credentials);
|
||||
const versionCode = await submitToGooglePlayAsync({
|
||||
artifactType: submission.artifact_type,
|
||||
client,
|
||||
submission: {
|
||||
package_name: submission.package_name,
|
||||
track: submission.track,
|
||||
release_status: submission.release_status,
|
||||
rollout: submission.rollout,
|
||||
changelog: submission.changelog,
|
||||
changes_not_sent_for_review: submission.changes_not_sent_for_review,
|
||||
artifact_path: artifactPath,
|
||||
},
|
||||
release,
|
||||
logger: ctx.logger,
|
||||
signal,
|
||||
});
|
||||
outputs.version_code.set(String(versionCode));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function submitToGooglePlayAsync({
|
||||
artifactType,
|
||||
client,
|
||||
submission,
|
||||
release,
|
||||
logger,
|
||||
signal,
|
||||
}: {
|
||||
artifactType: AndroidArtifactType;
|
||||
client: GooglePlayClient;
|
||||
submission: {
|
||||
package_name: string;
|
||||
track: string;
|
||||
release_status: ReleaseStatus;
|
||||
rollout?: number;
|
||||
changelog?: string;
|
||||
changes_not_sent_for_review: boolean;
|
||||
artifact_path: string;
|
||||
};
|
||||
release: { status: ReleaseStatus; userFraction?: number };
|
||||
logger: bunyan;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<number> {
|
||||
let editId: string | undefined;
|
||||
let committed = false;
|
||||
let commitOutcomeUnknown = false;
|
||||
try {
|
||||
const packageName = submission.package_name;
|
||||
logger.info(
|
||||
`Submitting ${packageName} (${artifactType}) to track ${JSON.stringify(submission.track)}.`
|
||||
);
|
||||
logger.info(
|
||||
`Requested status: ${submission.release_status}; rollout: ${submission.rollout ?? 'none'}. Effective status: ${release.status}; rollout: ${release.userFraction ?? 'none'}. changes_not_sent_for_review: ${submission.changes_not_sent_for_review}.`
|
||||
);
|
||||
if (submission.changelog) {
|
||||
logger.info(`Changelog (en-US): ${JSON.stringify(submission.changelog)}`);
|
||||
}
|
||||
editId = (await GooglePlayUtils.createEditAsync(client, { packageName, signal })).id;
|
||||
let lastPercent: number | undefined;
|
||||
const { versionCode } = await GooglePlayUtils.uploadApplicationAsync(client, {
|
||||
packageName,
|
||||
editId,
|
||||
artifactPath: submission.artifact_path,
|
||||
artifactType,
|
||||
signal,
|
||||
onProgress: (uploaded, total) => {
|
||||
const percent = Math.floor((uploaded / total) * 100);
|
||||
if (percent !== lastPercent) {
|
||||
logger.info(`Upload: ${percent}% (${uploaded}/${total} bytes).`);
|
||||
lastPercent = percent;
|
||||
}
|
||||
},
|
||||
});
|
||||
logger.info(`Uploaded version code: ${versionCode}.`);
|
||||
await GooglePlayUtils.updateTrackAsync(client, {
|
||||
packageName,
|
||||
editId,
|
||||
track: submission.track,
|
||||
release,
|
||||
versionCode,
|
||||
changelog: submission.changelog ? { locale: 'en-US', text: submission.changelog } : undefined,
|
||||
signal,
|
||||
});
|
||||
logger.info('Updated Google Play track ' + JSON.stringify(submission.track) + ' in the edit.');
|
||||
// Commit also validates the edit.
|
||||
await GooglePlayUtils.commitEditAsync(client, {
|
||||
packageName,
|
||||
editId,
|
||||
changesNotSentForReview: submission.changes_not_sent_for_review,
|
||||
logger,
|
||||
signal,
|
||||
});
|
||||
committed = true;
|
||||
logger.info(
|
||||
`Submitted ${packageName}, version ${versionCode}, to ${JSON.stringify(submission.track)}.`
|
||||
);
|
||||
return versionCode;
|
||||
} catch (error) {
|
||||
commitOutcomeUnknown = error instanceof GooglePlayCommitOutcomeUnknownError;
|
||||
throw GooglePlayUtils.mapGooglePlayError(error);
|
||||
} finally {
|
||||
if (editId && !committed && !commitOutcomeUnknown) {
|
||||
try {
|
||||
await GooglePlayUtils.deleteEditAsync(client, {
|
||||
packageName: submission.package_name,
|
||||
editId,
|
||||
signal: AbortSignal.timeout(30_000),
|
||||
});
|
||||
} catch {
|
||||
logger.warn(
|
||||
'Could not delete the Google Play edit after failure. The original submission error is preserved.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,22 @@ import { isProcessGroupRunning, killProcessGroup } from '../../utils/processes';
|
||||
import { SERVE_SIM_STATE_DIR, readServeSimServersAsync } from './serveSimMetricsRecorder';
|
||||
|
||||
const IOS_SIMULATOR_RECORDING_POLL_INTERVAL_MS = 2_000;
|
||||
// Once the poller stops, each recording stops in parallel within 60 + 130 + 5 + 30 = 225 s.
|
||||
// Once the poller stops, each recording stops in parallel within 60 + 430 + 5 + 310 = 805 s.
|
||||
const SERVE_SIM_START_TIMEOUT_MS = 60_000;
|
||||
/** serve-sim finalizes an active recording within this grace period after SIGTERM. */
|
||||
export const SERVE_SIM_STOP_GRACE_PERIOD_MS = 90_000;
|
||||
const SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS = 30_000;
|
||||
// serve-sim may be stopping at the same time: its grace period, the manifest wait, and 10 s.
|
||||
// Match record-video's control request, recording lease, and finalization allowances.
|
||||
const SERVE_SIM_CONTROL_REQUEST_TIMEOUT_MS = 120_000;
|
||||
const SERVE_SIM_RECORDING_LEASE_MS = 180_000;
|
||||
const SERVE_SIM_FINALIZATION_TIMEOUT_MS = 120_000;
|
||||
const SERVE_SIM_SHUTDOWN_MARGIN_MS = 10_000;
|
||||
/** Give the session host time to finalize its active writer before SIGKILL. */
|
||||
export const SERVE_SIM_STOP_GRACE_PERIOD_MS =
|
||||
SERVE_SIM_FINALIZATION_TIMEOUT_MS + SERVE_SIM_SHUTDOWN_MARGIN_MS;
|
||||
// A recorder can exit before its lease expires and the host writes the manifest.
|
||||
const SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS =
|
||||
SERVE_SIM_RECORDING_LEASE_MS + SERVE_SIM_FINALIZATION_TIMEOUT_MS + SERVE_SIM_SHUTDOWN_MARGIN_MS;
|
||||
// An ambiguous stop can use a full control request before lease/finalization reconciliation.
|
||||
const SERVE_SIM_FINISH_TIMEOUT_MS =
|
||||
SERVE_SIM_STOP_GRACE_PERIOD_MS + SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS + 10_000;
|
||||
SERVE_SIM_CONTROL_REQUEST_TIMEOUT_MS + SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS;
|
||||
const SERVE_SIM_FORCE_STOP_TIMEOUT_MS = 5_000;
|
||||
const SERVE_SIM_RECORDING_STARTED = 'serve-sim:recording-started';
|
||||
// The serve-sim package the session host started; every recorder runs `record-video` from it.
|
||||
@@ -46,6 +54,7 @@ type IosSimulatorRecording = {
|
||||
type ActiveIosSimulatorRecording = IosSimulatorRecording & {
|
||||
recordingProcess: ChildProcess;
|
||||
completionPromise: Promise<void>;
|
||||
hasExited: () => boolean;
|
||||
};
|
||||
|
||||
type IosSimulatorRecordingSession = {
|
||||
@@ -128,6 +137,7 @@ export namespace IosSimulatorRecordingUtils {
|
||||
logger.info(`Stopping screen recording for ${recording.deviceName}.`);
|
||||
const startState = await waitForRecorderStartAsync(recording, SERVE_SIM_START_TIMEOUT_MS);
|
||||
if (startState === 'exited') {
|
||||
await recording.completionPromise;
|
||||
return;
|
||||
}
|
||||
if (startState === 'timeout') {
|
||||
@@ -357,6 +367,7 @@ async function startIosSimulatorRecordingAsync(
|
||||
});
|
||||
return true;
|
||||
};
|
||||
let processExited = false;
|
||||
const completionPromise = (async () => {
|
||||
let spawnError: unknown;
|
||||
try {
|
||||
@@ -367,6 +378,7 @@ async function startIosSimulatorRecordingAsync(
|
||||
// A package-manager wrapper can exit while its record-video child still
|
||||
// runs in the detached group. Keep this device active until the group exits.
|
||||
await waitForRecordingProcessGroupExitAsync(recordingSpawn.child);
|
||||
processExited = true;
|
||||
// Host shutdown can end the recorder's lease after its video has been saved.
|
||||
if ((hasStarted() || !spawnError) && (await saveFinalizedRecordingAsync())) {
|
||||
return;
|
||||
@@ -400,6 +412,7 @@ async function startIosSimulatorRecordingAsync(
|
||||
outputDirectory,
|
||||
recordingProcess: recordingSpawn.child,
|
||||
completionPromise,
|
||||
hasExited: () => processExited,
|
||||
startedAt,
|
||||
getOutput,
|
||||
hasStarted,
|
||||
@@ -428,6 +441,9 @@ async function waitForRecorderStartAsync(
|
||||
): Promise<'started' | 'exited' | 'timeout'> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
while (Date.now() < deadline) {
|
||||
if (recording.hasExited()) {
|
||||
return 'exited';
|
||||
}
|
||||
if (recording.hasStarted()) {
|
||||
return 'started';
|
||||
}
|
||||
@@ -439,7 +455,7 @@ async function waitForRecorderStartAsync(
|
||||
return 'exited';
|
||||
}
|
||||
}
|
||||
return 'timeout';
|
||||
return recording.hasExited() ? 'exited' : recording.hasStarted() ? 'started' : 'timeout';
|
||||
}
|
||||
|
||||
function reportLostRecording(logger: bunyan, deviceName: string, recorderOutput: string): void {
|
||||
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
import { type Env } from '@expo/eas-build-job';
|
||||
import { type bunyan } from '@expo/logger';
|
||||
import spawn from '@expo/turtle-spawn';
|
||||
import { type ChildProcess } from 'node:child_process';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import { PassThrough } from 'node:stream';
|
||||
|
||||
import { IosSimulatorUtils } from '../../../utils/IosSimulatorUtils';
|
||||
import { IosSimulatorRecordingUtils } from '../IosSimulatorRecordingUtils';
|
||||
import { readServeSimServersAsync } from '../serveSimMetricsRecorder';
|
||||
|
||||
jest.mock('@expo/turtle-spawn');
|
||||
jest.mock('../serveSimMetricsRecorder');
|
||||
jest.mock('../../../sentry');
|
||||
jest.mock('node:timers/promises', () => ({
|
||||
setTimeout: (ms: number, value?: unknown, options?: { signal?: AbortSignal }) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const abort = (): void => {
|
||||
clearTimeout(timer);
|
||||
reject(Object.assign(new Error('Aborted'), { name: 'AbortError' }));
|
||||
};
|
||||
const timer = setTimeout(() => {
|
||||
options?.signal?.removeEventListener('abort', abort);
|
||||
resolve(value);
|
||||
}, ms);
|
||||
if (options?.signal?.aborted) {
|
||||
abort();
|
||||
} else {
|
||||
options?.signal?.addEventListener('abort', abort, { once: true });
|
||||
}
|
||||
}),
|
||||
}));
|
||||
|
||||
const logger = {
|
||||
info: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
error: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
} as unknown as bunyan;
|
||||
const udid = '06B546AC-7B06-4BED-83DB-83603E8EB537';
|
||||
let exit: () => void;
|
||||
let child: ChildProcess;
|
||||
let finishing: Promise<unknown> | undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.useFakeTimers({ doNotFake: ['nextTick', 'setImmediate'] });
|
||||
IosSimulatorRecordingUtils.useServeSimPackage('@expo/serve-sim@next');
|
||||
jest
|
||||
.spyOn(IosSimulatorUtils, 'getAvailableDevicesAsync')
|
||||
.mockResolvedValue([{ udid, name: 'iPhone 17 Pro', runtimeDisplayName: 'iOS 26.4' } as never]);
|
||||
jest
|
||||
.mocked(readServeSimServersAsync)
|
||||
.mockResolvedValue([{ udid, url: 'http://127.0.0.1:43563', token: 'session-token' }]);
|
||||
child = Object.assign(new EventEmitter(), {
|
||||
stdout: new PassThrough(),
|
||||
stderr: new PassThrough(),
|
||||
kill: jest.fn(),
|
||||
}) as unknown as ChildProcess;
|
||||
const done = new Promise<void>(resolve => {
|
||||
exit = resolve;
|
||||
});
|
||||
jest.mocked(spawn).mockReturnValue(Object.assign(done, { child }) as never);
|
||||
await IosSimulatorRecordingUtils.startAsync({ env: {} as Env, logger });
|
||||
for (let attempt = 0; attempt < 100 && jest.mocked(spawn).mock.calls.length === 0; attempt++) {
|
||||
await new Promise<void>(resolve => setImmediate(resolve));
|
||||
}
|
||||
expect(spawn).toHaveBeenCalledTimes(1);
|
||||
child.stderr?.emit('data', 'serve-sim:recording-started\n');
|
||||
});
|
||||
|
||||
async function saveManifest(): Promise<void> {
|
||||
const directory = jest.mocked(spawn).mock.calls[0][1][6];
|
||||
await writeFile(`${directory}/session.json`, JSON.stringify({ recording: 'recording.mp4' }));
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
if (jest.mocked(spawn).mock.calls.length) {
|
||||
await saveManifest();
|
||||
}
|
||||
exit();
|
||||
finishing ??= IosSimulatorRecordingUtils.finishAsync({ logger });
|
||||
await jest.advanceTimersByTimeAsync(1_000);
|
||||
await finishing;
|
||||
finishing = undefined;
|
||||
jest.useRealTimers();
|
||||
jest.restoreAllMocks();
|
||||
jest.mocked(spawn).mockReset();
|
||||
});
|
||||
|
||||
test('keeps the recorder alive through a 120-second stop request and 300-second reconciliation', async () => {
|
||||
finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
|
||||
await jest.advanceTimersByTimeAsync(0);
|
||||
expect(child.kill).toHaveBeenCalledWith('SIGINT');
|
||||
|
||||
await jest.advanceTimersByTimeAsync(420_000);
|
||||
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
|
||||
await saveManifest();
|
||||
exit();
|
||||
await jest.advanceTimersByTimeAsync(0);
|
||||
expect(await finishing).toHaveLength(1);
|
||||
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
|
||||
});
|
||||
|
||||
test('force-kills an unresponsive started recorder after the bounded shutdown allowance', async () => {
|
||||
jest.mocked(child.kill).mockImplementation(signal => {
|
||||
if (signal === 'SIGKILL') {
|
||||
exit();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
|
||||
await jest.advanceTimersByTimeAsync(429_999);
|
||||
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
|
||||
await saveManifest();
|
||||
await jest.advanceTimersByTimeAsync(1);
|
||||
expect(child.kill).toHaveBeenCalledWith('SIGKILL');
|
||||
expect(await finishing).toHaveLength(1);
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.stringContaining('did not finish within 430 seconds')
|
||||
);
|
||||
});
|
||||
|
||||
test('retains a manifest saved after a 180-second lease and 120-second finalization', async () => {
|
||||
exit();
|
||||
finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
|
||||
await jest.advanceTimersByTimeAsync(299_999);
|
||||
await saveManifest();
|
||||
await jest.advanceTimersByTimeAsync(1_001);
|
||||
expect(await finishing).toHaveLength(1);
|
||||
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
|
||||
});
|
||||
@@ -186,7 +186,7 @@ test('reports a started recording that ends without a manifest to Sentry', async
|
||||
child.stderr?.emit('data', 'GET http://127.0.0.1:43563/record?token=session-token failed\n');
|
||||
exitRecorder();
|
||||
await setTimeout(50);
|
||||
currentTime += 31_000;
|
||||
currentTime += 311_000;
|
||||
await setTimeout(1_100);
|
||||
|
||||
expect(Sentry.capture).toHaveBeenCalledWith(
|
||||
@@ -226,7 +226,7 @@ test('says when a recorder never reported its start before it is stopped', async
|
||||
await setTimeout(50);
|
||||
currentTime += 61_000;
|
||||
await setTimeout(200);
|
||||
currentTime += 31_000;
|
||||
currentTime += 311_000;
|
||||
|
||||
expect(await finishing).toEqual([]);
|
||||
expect(child.kill).toHaveBeenCalledWith('SIGINT');
|
||||
@@ -377,7 +377,7 @@ test('does not signal a recorder that exits before it reports its start', async
|
||||
recorder.exit();
|
||||
await setTimeout(50);
|
||||
// Past the manifest wait, so the recorder's completion settles.
|
||||
currentTime += 31_000;
|
||||
currentTime += 311_000;
|
||||
|
||||
expect(await finishing).toEqual([]);
|
||||
expect(recorder.child.kill).not.toHaveBeenCalled();
|
||||
@@ -435,7 +435,7 @@ test('reports a finalized recording whose manifest is gone at finish', async ()
|
||||
await rm(manifest);
|
||||
const finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
|
||||
await setTimeout(50);
|
||||
currentTime += 31_000;
|
||||
currentTime += 311_000;
|
||||
|
||||
expect(await finishing).toEqual([]);
|
||||
expect(Sentry.capture).toHaveBeenCalledWith(
|
||||
@@ -493,7 +493,7 @@ test('reports a started recorder that fails without a manifest', async () => {
|
||||
recorder.child.stderr?.emit('data', 'serve-sim:recording-started\n');
|
||||
recorder.fail(new Error('record-video exited with code 1'));
|
||||
await setTimeout(50);
|
||||
currentTime += 31_000;
|
||||
currentTime += 311_000;
|
||||
await setTimeout(1_100);
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
@@ -534,6 +534,6 @@ test('records every booted device with the first serve-sim package', async () =>
|
||||
|
||||
recorder.exit();
|
||||
await setTimeout(50);
|
||||
currentTime += 31_000;
|
||||
currentTime += 311_000;
|
||||
await IosSimulatorRecordingUtils.finishAsync({ logger });
|
||||
});
|
||||
@@ -2,12 +2,14 @@ import { type bunyan } from '@expo/logger';
|
||||
import { BuildRuntimePlatform } from '@expo/steps';
|
||||
import spawn from '@expo/turtle-spawn';
|
||||
import { Client, fetchExchange } from '@urql/core';
|
||||
import { getEventListeners } from 'node:events';
|
||||
import { readFile, readdir, writeFile } from 'node:fs/promises';
|
||||
import { Readable } from 'node:stream';
|
||||
import os from 'node:os';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
import { type CustomBuildContext } from '../../../customBuildContext';
|
||||
import * as processes from '../../../utils/processes';
|
||||
import {
|
||||
captureDeviceRunSessionPreviewAsync,
|
||||
ensureMacosPreviewEncoderInstalledAsync,
|
||||
@@ -383,18 +385,106 @@ describe(ensureMacosPreviewEncoderInstalledAsync, () => {
|
||||
[
|
||||
'brew',
|
||||
['install', 'webp'],
|
||||
{ env: { HOME: '/Users/expo', HOMEBREW_NO_AUTO_UPDATE: '1' }, logger },
|
||||
{
|
||||
env: { HOME: '/Users/expo', HOMEBREW_NO_AUTO_UPDATE: '1' },
|
||||
logger,
|
||||
detached: true,
|
||||
},
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
it('rejects when webp cannot be installed', async () => {
|
||||
it('does not start a command when setup was already canceled', async () => {
|
||||
jest.mocked(spawn).mockReset();
|
||||
jest.mocked(spawn).mockRejectedValue(new Error('brew failed'));
|
||||
await expect(ensureMacosPreviewEncoderInstalledAsync({ env: {}, logger })).rejects.toThrow(
|
||||
'brew failed'
|
||||
);
|
||||
const controller = new AbortController();
|
||||
const reason = new Error('session ended');
|
||||
controller.abort(reason);
|
||||
await expect(
|
||||
ensureMacosPreviewEncoderInstalledAsync({ env: {}, logger, signal: controller.signal })
|
||||
).rejects.toBe(reason);
|
||||
expect(spawn).not.toHaveBeenCalled();
|
||||
expect(getEventListeners(controller.signal, 'abort')).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(['cwebp', 'brew'])(
|
||||
'waits for canceled %s to close and never starts another command',
|
||||
async command => {
|
||||
jest.mocked(spawn).mockReset();
|
||||
const controller = new AbortController();
|
||||
const child = { pid: 12345, kill: jest.fn() };
|
||||
const killed = jest.spyOn(processes, 'killProcessGroup').mockImplementation(() => {});
|
||||
const closeError = new Error(`${command} closed after cancellation`);
|
||||
let entered!: () => void;
|
||||
const commandEntered = new Promise<void>(resolve => {
|
||||
entered = resolve;
|
||||
});
|
||||
let close!: (error: Error) => void;
|
||||
jest.mocked(spawn).mockImplementation(current => {
|
||||
if (current !== command) {
|
||||
return Promise.reject(new Error('cwebp missing')) as ReturnType<typeof spawn>;
|
||||
}
|
||||
entered();
|
||||
return Object.assign(
|
||||
new Promise((_, reject) => {
|
||||
close = reject;
|
||||
}),
|
||||
{ child }
|
||||
) as unknown as ReturnType<typeof spawn>;
|
||||
});
|
||||
let settled = false;
|
||||
const result = ensureMacosPreviewEncoderInstalledAsync({
|
||||
env: {},
|
||||
logger,
|
||||
signal: controller.signal,
|
||||
}).then(
|
||||
() => {
|
||||
settled = true;
|
||||
},
|
||||
error => {
|
||||
settled = true;
|
||||
return error;
|
||||
}
|
||||
);
|
||||
try {
|
||||
await commandEntered;
|
||||
controller.abort(new Error('session ended'));
|
||||
await Promise.resolve();
|
||||
expect(killed).toHaveBeenCalledWith(child, 'SIGKILL');
|
||||
expect(settled).toBe(false);
|
||||
expect(jest.mocked(spawn).mock.calls.at(-1)).toEqual([
|
||||
command,
|
||||
command === 'cwebp' ? ['-version'] : ['install', 'webp'],
|
||||
expect.objectContaining({ detached: true }),
|
||||
]);
|
||||
expect(jest.mocked(spawn).mock.calls.every(([, , options]) => !options?.signal)).toBe(true);
|
||||
} finally {
|
||||
close(closeError);
|
||||
await result;
|
||||
killed.mockRestore();
|
||||
}
|
||||
expect(spawn).toHaveBeenCalledTimes(command === 'cwebp' ? 1 : 2);
|
||||
expect(getEventListeners(controller.signal, 'abort')).toEqual([]);
|
||||
}
|
||||
);
|
||||
|
||||
it('rejects an installation failure and removes its abort listeners', async () => {
|
||||
jest.mocked(spawn).mockReset();
|
||||
const controller = new AbortController();
|
||||
const failure = new Error('brew failed');
|
||||
jest.mocked(spawn).mockRejectedValue(failure);
|
||||
await expect(
|
||||
ensureMacosPreviewEncoderInstalledAsync({ env: {}, logger, signal: controller.signal })
|
||||
).rejects.toBe(failure);
|
||||
expect(getEventListeners(controller.signal, 'abort')).toEqual([]);
|
||||
});
|
||||
|
||||
it('removes its abort listener after a successful probe', async () => {
|
||||
jest.mocked(spawn).mockReset();
|
||||
jest.mocked(spawn).mockResolvedValue({ stdout: '', stderr: '' } as never);
|
||||
const controller = new AbortController();
|
||||
await ensureMacosPreviewEncoderInstalledAsync({ env: {}, logger, signal: controller.signal });
|
||||
expect(getEventListeners(controller.signal, 'abort')).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { BuildPhase, BuildPhaseResult, LogMarker } from '@expo/eas-build-job';
|
||||
import type { bunyan } from '@expo/logger';
|
||||
import { BuildRuntimePlatform, type BuildStepEnv } from '@expo/steps';
|
||||
import * as ngrok from '@ngrok/ngrok';
|
||||
@@ -17,7 +18,12 @@ import {
|
||||
startDeviceRunSessionPreview,
|
||||
} from '../deviceRunSessionPreview';
|
||||
import { startDeviceSessionHostAsync } from '../deviceSessionHost';
|
||||
import { ensureFfmpegInstalledOnceAsync, spawnDetached } from '../remoteDeviceRunSession';
|
||||
import {
|
||||
ensureFfmpegInstalledOnceAsync,
|
||||
fetchWebPreviewTurnArgsAsync,
|
||||
spawnDetached,
|
||||
} from '../remoteDeviceRunSession';
|
||||
import * as screenshotCollector from '../deviceRunSessionScreenshots';
|
||||
|
||||
jest.mock('@ngrok/ngrok');
|
||||
jest.mock('../deviceRunSessionArtifacts');
|
||||
@@ -47,10 +53,12 @@ jest.mock('../deviceRunSessionScreenRecordings', () => ({
|
||||
|
||||
function deferred<T>() {
|
||||
let resolve!: (value: T) => void;
|
||||
const promise = new Promise<T>(r => {
|
||||
let reject!: (reason: Error) => void;
|
||||
const promise = new Promise<T>((r, j) => {
|
||||
resolve = r;
|
||||
reject = j;
|
||||
});
|
||||
return { promise, resolve };
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
|
||||
const env = {
|
||||
@@ -58,17 +66,22 @@ const env = {
|
||||
NGROK_AUTHTOKEN: 'token',
|
||||
} as BuildStepEnv;
|
||||
const ctx = {} as CustomBuildContext;
|
||||
const logger = { info: jest.fn(), warn: jest.fn() } as unknown as bunyan;
|
||||
const logger = {
|
||||
info: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
child: jest.fn().mockReturnThis(),
|
||||
} as unknown as bunyan;
|
||||
const stopServer = jest.fn();
|
||||
const closeTunnel = jest.fn();
|
||||
const directories: string[] = [];
|
||||
const baseDomain = 'preview.example.test';
|
||||
|
||||
async function startHostAsync() {
|
||||
async function startHostAsync(separateLogPhase = true) {
|
||||
return await startDeviceSessionHostAsync(ctx, {
|
||||
runtimePlatform: BuildRuntimePlatform.LINUX,
|
||||
env,
|
||||
logger,
|
||||
separateLogPhase,
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
}
|
||||
@@ -370,6 +383,10 @@ it('finishes despite a stalled tunnel close', async () => {
|
||||
await finishing;
|
||||
expect(stopServer).toHaveBeenCalledTimes(1);
|
||||
expect(logger.warn).toHaveBeenCalledWith(expect.anything(), expect.stringContaining('deadline'));
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.FAIL },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
closing.resolve();
|
||||
});
|
||||
|
||||
@@ -462,6 +479,7 @@ it('leaves iOS recording to its existing build steps', async () => {
|
||||
runtimePlatform: BuildRuntimePlatform.DARWIN,
|
||||
env,
|
||||
logger,
|
||||
separateLogPhase: true,
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
const options = jest.mocked(spawnDetached).mock.calls[0][0];
|
||||
@@ -473,6 +491,237 @@ it('leaves iOS recording to its existing build steps', async () => {
|
||||
expect(stopServer).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
const turnArgs = [
|
||||
'--turn-url',
|
||||
'turn:turn.example.test:3478',
|
||||
'--turn-username',
|
||||
'turn-user',
|
||||
'--turn-credential',
|
||||
'turn-secret',
|
||||
];
|
||||
|
||||
it('passes the TURN credential and the Android control token to the host as secrets', async () => {
|
||||
jest.mocked(fetchWebPreviewTurnArgsAsync).mockResolvedValueOnce(turnArgs);
|
||||
const host = await startHostAsync();
|
||||
const options = jest.mocked(spawnDetached).mock.calls[0][0];
|
||||
const controlToken = options.env.EXPO_DEVICE_HUB_RECORDING_CONTROL_TOKEN;
|
||||
expect(controlToken).toMatch(/^[a-f0-9]{64}$/);
|
||||
expect(options.secrets).toEqual(['turn-secret', controlToken]);
|
||||
await host.finishAsync();
|
||||
});
|
||||
|
||||
it('adds the iOS preview token to the host secrets once serve-sim is ready', async () => {
|
||||
jest.mocked(fetchWebPreviewTurnArgsAsync).mockResolvedValueOnce(turnArgs);
|
||||
let secretsAtSpawn: string[] | undefined;
|
||||
jest.mocked(spawnDetached).mockImplementationOnce(options => {
|
||||
secretsAtSpawn = [...(options.secrets ?? [])];
|
||||
return {
|
||||
pid: undefined,
|
||||
getOutput: () => '',
|
||||
getExitError: () => undefined,
|
||||
stopAsync: stopServer,
|
||||
};
|
||||
});
|
||||
const host = await startDeviceSessionHostAsync(ctx, {
|
||||
runtimePlatform: BuildRuntimePlatform.DARWIN,
|
||||
env,
|
||||
logger,
|
||||
separateLogPhase: true,
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
expect(secretsAtSpawn).toEqual(['turn-secret']);
|
||||
// Host output is redacted against this array, so the token must land in the one passed at spawn.
|
||||
expect(jest.mocked(spawnDetached).mock.calls[0][0].secrets).toEqual([
|
||||
'turn-secret',
|
||||
'preview-token',
|
||||
]);
|
||||
expect((await host.openPreviewAsync({ baseDomain })).previewToken).toBe('preview-token');
|
||||
await host.finishAsync();
|
||||
});
|
||||
|
||||
it('keeps the preview phase open until shutdown output has been logged', async () => {
|
||||
const previewLogger = { info: jest.fn(), warn: jest.fn() } as unknown as bunyan;
|
||||
jest.mocked(logger.child).mockReturnValueOnce(previewLogger);
|
||||
const host = await startHostAsync();
|
||||
expect(logger.child).toHaveBeenCalledWith({
|
||||
phase: BuildPhase.CUSTOM,
|
||||
buildStepId: expect.stringMatching(/^step-\d{3,}$/),
|
||||
buildStepDisplayName: 'Simulator preview',
|
||||
});
|
||||
expect(spawnDetached).toHaveBeenCalledWith(expect.objectContaining({ logger: previewLogger }));
|
||||
expect(previewLogger.info).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ marker: LogMarker.END_PHASE }),
|
||||
expect.anything()
|
||||
);
|
||||
stopServer.mockImplementationOnce(async () => previewLogger.info('shutdown output'));
|
||||
await host.finishAsync();
|
||||
await host.finishAsync();
|
||||
const calls = jest.mocked(previewLogger.info).mock.calls;
|
||||
const endings = calls.filter(([fields]) => fields?.marker === LogMarker.END_PHASE);
|
||||
expect(endings).toEqual([
|
||||
[
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.SUCCESS },
|
||||
'End phase: Simulator preview',
|
||||
],
|
||||
]);
|
||||
expect(calls.findIndex(([message]) => message === 'shutdown output')).toBeLessThan(
|
||||
calls.length - 1
|
||||
);
|
||||
});
|
||||
|
||||
it('ends the preview phase before waiting for screenshot uploads', async () => {
|
||||
const previewLogger = { info: jest.fn(), warn: jest.fn() } as unknown as bunyan;
|
||||
jest.mocked(logger.child).mockReturnValueOnce(previewLogger);
|
||||
const uploading = deferred<void>();
|
||||
const uploaded = deferred<void>();
|
||||
const finishScreenshots = jest.fn(async () => {
|
||||
uploading.resolve();
|
||||
await uploaded.promise;
|
||||
});
|
||||
const collector = jest
|
||||
.spyOn(screenshotCollector, 'startDeviceRunSessionScreenshotsAsync')
|
||||
.mockResolvedValueOnce({ directory: '/tmp/screenshots', finishAsync: finishScreenshots });
|
||||
try {
|
||||
const host = await startHostAsync();
|
||||
const finishing = host.finishAsync();
|
||||
let finished = false;
|
||||
void finishing.then(() => {
|
||||
finished = true;
|
||||
});
|
||||
await uploading.promise;
|
||||
expect(stopServer).toHaveBeenCalledTimes(1);
|
||||
expect(previewLogger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.SUCCESS },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
expect(finished).toBe(false);
|
||||
uploaded.resolve();
|
||||
await finishing;
|
||||
expect(collector).toHaveBeenCalledWith(ctx, expect.objectContaining({ logger }));
|
||||
} finally {
|
||||
uploaded.resolve();
|
||||
collector.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it('ends the preview phase with failure when spawning fails', async () => {
|
||||
jest.mocked(spawnDetached).mockImplementationOnce(() => {
|
||||
throw new Error('could not spawn');
|
||||
});
|
||||
await expect(startHostAsync()).rejects.toThrow('could not spawn');
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.FAIL },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
});
|
||||
|
||||
it('ends the preview phase with failure when the host cannot stop', async () => {
|
||||
const previewLogger = { info: jest.fn(), warn: jest.fn() } as unknown as bunyan;
|
||||
jest.mocked(logger.child).mockReturnValueOnce(previewLogger);
|
||||
const host = await startHostAsync();
|
||||
stopServer.mockRejectedValueOnce(new Error('could not stop'));
|
||||
await host.finishAsync();
|
||||
expect(previewLogger.warn).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
'Could not stop the expo-device-hub session host.'
|
||||
);
|
||||
expect(logger.warn).not.toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
'Could not stop the expo-device-hub session host.'
|
||||
);
|
||||
expect(previewLogger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.FAIL },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['exited during the session', true, BuildPhaseResult.FAIL],
|
||||
['exited only when stopped', false, BuildPhaseResult.SUCCESS],
|
||||
])('finishes cleanup and uploads when the host %s', async (_description, exitedEarly, result) => {
|
||||
let exitError: Error | undefined;
|
||||
jest.mocked(spawnDetached).mockImplementationOnce(options => {
|
||||
directories.push(options.args[options.args.indexOf('--android-recording-directory') + 1]);
|
||||
return {
|
||||
pid: undefined,
|
||||
getOutput: () => '',
|
||||
getExitError: () => exitError,
|
||||
stopAsync: stopServer,
|
||||
};
|
||||
});
|
||||
stopServer.mockImplementationOnce(async () => {
|
||||
exitError ??= new Error('Process exited with signal SIGTERM.');
|
||||
});
|
||||
const host = await startHostAsync();
|
||||
await host.openPreviewAsync({ baseDomain });
|
||||
const directory = directories[0];
|
||||
await writeRecordingDescriptorAsync(directory);
|
||||
jest.mocked(uploadDeviceRunSessionScreenRecordingsAsync).mockResolvedValueOnce(true);
|
||||
const screenshotDirectory =
|
||||
jest.mocked(spawnDetached).mock.calls[0][0].env.EXPO_DEVICE_HUB_SCREENSHOT_DIRECTORY;
|
||||
if (!screenshotDirectory) {
|
||||
throw new Error('Missing screenshot artifact directory');
|
||||
}
|
||||
if (exitedEarly) {
|
||||
exitError = new Error('Process exited with code 1.');
|
||||
}
|
||||
await host.finishAsync();
|
||||
expect(closeTunnel).toHaveBeenCalledTimes(1);
|
||||
expect(stopServer).toHaveBeenCalledTimes(1);
|
||||
expect(uploadDeviceRunSessionScreenRecordingsAsync).toHaveBeenCalledTimes(1);
|
||||
await expect(access(directory)).rejects.toMatchObject({ code: 'ENOENT' });
|
||||
await expect(access(screenshotDirectory)).rejects.toMatchObject({ code: 'ENOENT' });
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
});
|
||||
|
||||
it('ends the preview phase with failure when the tunnel cannot close', async () => {
|
||||
const host = await startHostAsync();
|
||||
await host.openPreviewAsync({ baseDomain });
|
||||
closeTunnel.mockRejectedValue(new Error('tunnel close failure'));
|
||||
jest.useFakeTimers();
|
||||
const finishing = host.finishAsync();
|
||||
await jest.advanceTimersByTimeAsync(4_000);
|
||||
await finishing;
|
||||
expect(stopServer).toHaveBeenCalledTimes(1);
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.FAIL },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
closeTunnel.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it('ends the preview phase with failure when startup never provides a token', async () => {
|
||||
const metrics = jest.requireMock('../serveSimMetricsRecorder');
|
||||
metrics.readServeSimServersAsync.mockResolvedValueOnce([]);
|
||||
await expect(
|
||||
startDeviceSessionHostAsync(ctx, {
|
||||
runtimePlatform: BuildRuntimePlatform.DARWIN,
|
||||
env,
|
||||
logger,
|
||||
separateLogPhase: true,
|
||||
timeoutMs: 10_000,
|
||||
})
|
||||
).rejects.toThrow('wrote no session token');
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.FAIL },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
});
|
||||
|
||||
it('ends the preview phase with failure if opening the tunnel fails', async () => {
|
||||
const host = await startHostAsync();
|
||||
jest.mocked(ngrok.forward).mockRejectedValueOnce(new Error('tunnel unavailable'));
|
||||
await expect(host.openPreviewAsync({ baseDomain })).rejects.toThrow('tunnel unavailable');
|
||||
await host.finishAsync();
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.FAIL },
|
||||
'End phase: Simulator preview'
|
||||
);
|
||||
});
|
||||
|
||||
it.each([BuildRuntimePlatform.LINUX, BuildRuntimePlatform.DARWIN])(
|
||||
'uploads screenshots and flushes them exactly once when the %s host finishes',
|
||||
async runtimePlatform => {
|
||||
@@ -540,21 +789,54 @@ it.each([BuildRuntimePlatform.LINUX, BuildRuntimePlatform.DARWIN])(
|
||||
}
|
||||
);
|
||||
|
||||
it('does not delay macOS readiness on encoder setup or start the preview after finish', async () => {
|
||||
const install = deferred<void>();
|
||||
jest.mocked(ensureMacosPreviewEncoderInstalledAsync).mockReturnValueOnce(install.promise);
|
||||
const host = await startDeviceSessionHostAsync(ctx, {
|
||||
runtimePlatform: BuildRuntimePlatform.DARWIN,
|
||||
env,
|
||||
logger,
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
await host.finishAsync();
|
||||
install.resolve();
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
expect(startDeviceRunSessionPreview).not.toHaveBeenCalled();
|
||||
expect(stopServer).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
it.each(['success', 'failure'])(
|
||||
'keeps macOS readiness nonblocking and drains encoder setup %s before ending the phase',
|
||||
async result => {
|
||||
const install = deferred<void>();
|
||||
jest.mocked(ensureMacosPreviewEncoderInstalledAsync).mockReturnValueOnce(install.promise);
|
||||
const host = await startDeviceSessionHostAsync(ctx, {
|
||||
runtimePlatform: BuildRuntimePlatform.DARWIN,
|
||||
env,
|
||||
logger,
|
||||
separateLogPhase: true,
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
const setupLogger = jest.mocked(ensureMacosPreviewEncoderInstalledAsync).mock.calls[0][0]
|
||||
.logger;
|
||||
const finishing = host.finishAsync();
|
||||
expect(host.finishAsync()).toBe(finishing);
|
||||
try {
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
expect(logger.info).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ marker: LogMarker.END_PHASE }),
|
||||
expect.any(String)
|
||||
);
|
||||
expect(
|
||||
jest.mocked(ensureMacosPreviewEncoderInstalledAsync).mock.calls[0][0].signal?.aborted
|
||||
).toBe(true);
|
||||
setupLogger.info('last encoder output');
|
||||
if (result === 'failure') {
|
||||
install.reject(new Error('encoder stopped'));
|
||||
} else {
|
||||
install.resolve();
|
||||
}
|
||||
await finishing;
|
||||
const calls = jest.mocked(logger.info).mock.calls;
|
||||
expect(calls.findIndex(([message]) => message === 'last encoder output')).toBeLessThan(
|
||||
calls.findIndex(([record]) => record?.marker === LogMarker.END_PHASE)
|
||||
);
|
||||
expect(logger.warn).not.toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
'Could not start refreshing the session preview.'
|
||||
);
|
||||
expect(startDeviceRunSessionPreview).not.toHaveBeenCalled();
|
||||
expect(stopServer).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
install.resolve();
|
||||
await finishing;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
it('keeps the session running when encoder setup for the preview fails', async () => {
|
||||
jest
|
||||
@@ -564,6 +846,7 @@ it('keeps the session running when encoder setup for the preview fails', async (
|
||||
runtimePlatform: BuildRuntimePlatform.DARWIN,
|
||||
env,
|
||||
logger,
|
||||
separateLogPhase: true,
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
@@ -574,3 +857,17 @@ it('keeps the session running when encoder setup for the preview fails', async (
|
||||
);
|
||||
await host.finishAsync();
|
||||
});
|
||||
|
||||
it('uses the existing step logger for startup and shutdown output', async () => {
|
||||
const host = await startHostAsync(false);
|
||||
const processLogger = jest.mocked(spawnDetached).mock.calls[0][0].logger;
|
||||
expect(processLogger).toBe(logger);
|
||||
stopServer.mockImplementationOnce(async () => processLogger?.info('last host output'));
|
||||
await host.finishAsync();
|
||||
expect(logger.info).toHaveBeenCalledWith('last host output');
|
||||
expect(
|
||||
jest
|
||||
.mocked(logger.info)
|
||||
.mock.calls.some(([record]) => typeof record === 'object' && 'marker' in record)
|
||||
).toBe(false);
|
||||
});
|
||||
@@ -437,11 +437,13 @@ describe(configureSimulatorProxyEnvironmentAsync, () => {
|
||||
});
|
||||
|
||||
describe(startChiselServerAsync, () => {
|
||||
const logger = { warn: jest.fn() } as unknown as bunyan;
|
||||
const options = {
|
||||
chiselPath: '/tmp/chisel',
|
||||
controlPort: 52001,
|
||||
authfilePath: '/tmp/authfile.json',
|
||||
env: { PATH: '/bin', AUTH: 'unexpected:password' },
|
||||
logger,
|
||||
};
|
||||
let output: string;
|
||||
let stopAsync: jest.Mock;
|
||||
@@ -483,7 +485,9 @@ describe(startChiselServerAsync, () => {
|
||||
expect(stopAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects and stops a child that prints its fingerprint then fails to bind', async () => {
|
||||
it('keeps the bind error and warns when a child that failed to bind cannot be stopped', async () => {
|
||||
const stopError = new Error('drain timed out');
|
||||
stopAsync.mockRejectedValueOnce(stopError);
|
||||
const started = startChiselServerAsync(options);
|
||||
const rejected = expect(started).rejects.toThrow('address already in use');
|
||||
output += 'listen tcp 127.0.0.1:52001: bind: address already in use\n';
|
||||
@@ -493,16 +497,27 @@ describe(startChiselServerAsync, () => {
|
||||
await jest.advanceTimersByTimeAsync(250);
|
||||
await rejected;
|
||||
expect(stopAsync).toHaveBeenCalledTimes(1);
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
{ err: stopError },
|
||||
'Could not stop the reverse tunnel server after it failed to start.'
|
||||
);
|
||||
});
|
||||
|
||||
it('stops the child when startup is cancelled', async () => {
|
||||
it('keeps the cancellation and warns when the cancelled child cannot be stopped', async () => {
|
||||
const stopError = new Error('drain timed out');
|
||||
stopAsync.mockRejectedValueOnce(stopError);
|
||||
const controller = new AbortController();
|
||||
const cancelled = new Error('cancelled');
|
||||
const started = startChiselServerAsync({ ...options, signal: controller.signal });
|
||||
const rejected = expect(started).rejects.toThrow('cancelled');
|
||||
controller.abort(new Error('cancelled'));
|
||||
const rejected = expect(started).rejects.toBe(cancelled);
|
||||
controller.abort(cancelled);
|
||||
await jest.advanceTimersByTimeAsync(250);
|
||||
await rejected;
|
||||
expect(stopAsync).toHaveBeenCalledTimes(1);
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
{ err: stopError },
|
||||
'Could not stop the reverse tunnel server after it failed to start.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
import { preparePreinstalledWdaAsync } from '../preinstalledWda';
|
||||
|
||||
jest.unmock('node:fs');
|
||||
jest.unmock('@expo/turtle-spawn');
|
||||
jest.unmock('@expo/logger');
|
||||
|
||||
const realSetTimeout = setTimeout;
|
||||
const realClearTimeout = clearTimeout;
|
||||
const sleep = (ms: number): Promise<void> => new Promise(resolve => realSetTimeout(resolve, ms));
|
||||
|
||||
async function waitUntil(predicate: () => boolean): Promise<void> {
|
||||
const deadline = Date.now() + 3_000;
|
||||
while (!predicate()) {
|
||||
if (Date.now() >= deadline) {
|
||||
throw new Error('Subprocess fixture did not reach the expected state');
|
||||
}
|
||||
await sleep(20);
|
||||
}
|
||||
}
|
||||
|
||||
function isRunning(pid: number): boolean {
|
||||
try {
|
||||
// Orphaned descendants can remain zombies until init reaps them.
|
||||
const state = execFileSync('ps', ['-p', String(pid), '-o', 'stat='])
|
||||
.toString()
|
||||
.trim();
|
||||
return state.length > 0 && !state.startsWith('Z');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
it('kills a stalled downloader and its descendants before fallback removes the artifact', async () => {
|
||||
const root = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'wda-download-timeout-'));
|
||||
const appiumHome = path.join(root, 'appium');
|
||||
const outdir = path.join(appiumHome, 'preinstalled-wda');
|
||||
const pidFiles = ['parent', 'child', 'grandchild'].map(name => path.join(root, `${name}.pid`));
|
||||
const executable = path.join(root, 'appium.cjs');
|
||||
const logger = { child: () => logger, info: jest.fn(), warn: jest.fn() };
|
||||
let preparation: Promise<Record<string, unknown>> | undefined;
|
||||
let fallbackDeadline: NodeJS.Timeout | undefined;
|
||||
try {
|
||||
await fs.promises.mkdir(outdir, { recursive: true });
|
||||
await fs.promises.writeFile(path.join(outdir, 'incomplete'), 'partial download');
|
||||
await fs.promises.writeFile(path.join(appiumHome, 'keep'), 'unrelated');
|
||||
await fs.promises.writeFile(
|
||||
executable,
|
||||
`#!${process.execPath}
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const {spawn} = require('node:child_process');
|
||||
const role = process.argv[2] === 'driver' ? 'parent' : process.argv[2];
|
||||
const outdir = role === 'parent' ? process.argv[process.argv.indexOf('--outdir') + 1] : process.argv[3];
|
||||
fs.writeFileSync(path.join(__dirname, role + '.pid'), String(process.pid));
|
||||
if (role !== 'grandchild') {
|
||||
spawn(process.execPath, [__filename, role === 'parent' ? 'child' : 'grandchild', outdir], {stdio: 'inherit'});
|
||||
}
|
||||
setInterval(() => {
|
||||
if (role === 'grandchild') {
|
||||
fs.mkdirSync(outdir, {recursive: true});
|
||||
fs.writeFileSync(path.join(outdir, 'incomplete'), 'still downloading');
|
||||
}
|
||||
}, 50);
|
||||
`
|
||||
);
|
||||
await fs.promises.chmod(executable, 0o700);
|
||||
jest.useFakeTimers({ doNotFake: ['nextTick', 'setImmediate', 'Date'] });
|
||||
preparation = preparePreinstalledWdaAsync({
|
||||
runtimeIdentifier: 'com.apple.CoreSimulator.SimRuntime.iOS-26-5',
|
||||
appiumHome,
|
||||
appiumBinPath: executable,
|
||||
appiumEnv: {},
|
||||
logger: logger as never,
|
||||
});
|
||||
await waitUntil(() => pidFiles.every(file => fs.existsSync(file)));
|
||||
const pids = pidFiles.map(file => Number(fs.readFileSync(file, 'utf8')));
|
||||
expect(pids.every(isRunning)).toBe(true);
|
||||
|
||||
jest.advanceTimersByTime(60_000);
|
||||
await expect(
|
||||
Promise.race([
|
||||
preparation,
|
||||
new Promise((_, reject) => {
|
||||
fallbackDeadline = realSetTimeout(
|
||||
() => reject(new Error('Fallback remained blocked by inherited downloader pipes')),
|
||||
2_000
|
||||
);
|
||||
}),
|
||||
])
|
||||
).resolves.toEqual({});
|
||||
expect(logger.warn.mock.calls[0]?.[0].err.signal).toBe('SIGKILL');
|
||||
await waitUntil(() => pids.every(pid => !isRunning(pid)));
|
||||
await sleep(100);
|
||||
expect(fs.existsSync(outdir)).toBe(false);
|
||||
expect(fs.readFileSync(path.join(appiumHome, 'keep'), 'utf8')).toBe('unrelated');
|
||||
expect(logger.warn).toHaveBeenCalled();
|
||||
} finally {
|
||||
realClearTimeout(fallbackDeadline);
|
||||
jest.useRealTimers();
|
||||
// Also clean up the fixture if an assertion fails before the timeout fires.
|
||||
for (const file of pidFiles) {
|
||||
if (fs.existsSync(file)) {
|
||||
try {
|
||||
const pid = Number(fs.readFileSync(file, 'utf8'));
|
||||
if (isRunning(pid)) {
|
||||
process.kill(pid, 'SIGKILL');
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
await preparation?.catch(() => {});
|
||||
await fs.promises.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
}, 10_000);
|
||||
@@ -0,0 +1,80 @@
|
||||
import spawn from '@expo/turtle-spawn';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
import { preparePreinstalledWdaAsync } from '../preinstalledWda';
|
||||
|
||||
jest.mock('@expo/turtle-spawn', () => ({ __esModule: true, default: jest.fn() }));
|
||||
|
||||
const appiumHome = path.join(os.tmpdir(), 'owned-appium-home');
|
||||
const outdir = path.join(appiumHome, 'preinstalled-wda');
|
||||
const runner = path.join(outdir, 'WebDriverAgentRunner-Runner.app');
|
||||
const logger = { info: jest.fn(), warn: jest.fn() };
|
||||
const options = {
|
||||
runtimeIdentifier: 'com.apple.CoreSimulator.SimRuntime.iOS-26-5',
|
||||
appiumHome,
|
||||
appiumBinPath: path.join(appiumHome, 'node_modules', '.bin', 'appium'),
|
||||
appiumEnv: { APPIUM_HOME: appiumHome },
|
||||
logger: logger as never,
|
||||
};
|
||||
|
||||
it('downloads the driver-matched Simulator runner and retains its XCTest frameworks', async () => {
|
||||
jest.mocked(spawn).mockImplementation((async () => {
|
||||
await fs.promises.mkdir(path.join(runner, 'Frameworks', 'XCTest.framework'), {
|
||||
recursive: true,
|
||||
});
|
||||
return { stdout: '' };
|
||||
}) as never);
|
||||
|
||||
await expect(preparePreinstalledWdaAsync(options)).resolves.toEqual({
|
||||
'appium:usePreinstalledWDA': true,
|
||||
'appium:prebuiltWDAPath': runner,
|
||||
});
|
||||
expect(spawn).toHaveBeenCalledWith(
|
||||
options.appiumBinPath,
|
||||
[
|
||||
'driver',
|
||||
'run',
|
||||
'xcuitest',
|
||||
'download-wda',
|
||||
'--',
|
||||
'--outdir',
|
||||
outdir,
|
||||
'--platform',
|
||||
'iOS',
|
||||
'--kind',
|
||||
'sim',
|
||||
],
|
||||
expect.objectContaining({ env: options.appiumEnv, detached: true })
|
||||
);
|
||||
expect(
|
||||
(await fs.promises.stat(path.join(runner, 'Frameworks', 'XCTest.framework'))).isDirectory()
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
undefined,
|
||||
'com.apple.CoreSimulator.SimRuntime.iOS-16-4',
|
||||
'com.apple.CoreSimulator.SimRuntime.tvOS-26-5',
|
||||
])('keeps the existing startup for unsupported runtime %s', async runtimeIdentifier => {
|
||||
await expect(preparePreinstalledWdaAsync({ ...options, runtimeIdentifier })).resolves.toEqual({});
|
||||
expect(spawn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('falls back after a failed download and removes only its own incomplete artifact', async () => {
|
||||
await fs.promises.mkdir(outdir, { recursive: true });
|
||||
const sibling = path.join(appiumHome, 'keep');
|
||||
await fs.promises.writeFile(sibling, 'keep');
|
||||
jest.mocked(spawn).mockRejectedValue(new Error('download unavailable'));
|
||||
|
||||
await expect(preparePreinstalledWdaAsync(options)).resolves.toEqual({});
|
||||
await expect(fs.promises.stat(outdir)).rejects.toThrow();
|
||||
await expect(fs.promises.readFile(sibling, 'utf8')).resolves.toBe('keep');
|
||||
expect(logger.warn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not enable preinstalled startup when the download produces no runner', async () => {
|
||||
jest.mocked(spawn).mockResolvedValue({ stdout: '' } as never);
|
||||
await expect(preparePreinstalledWdaAsync(options)).resolves.toEqual({});
|
||||
});
|
||||
@@ -0,0 +1,139 @@
|
||||
import { type bunyan } from '@expo/logger';
|
||||
|
||||
import { createProcessOutput } from '../processOutput';
|
||||
|
||||
const logger = { info: jest.fn() } as unknown as bunyan;
|
||||
|
||||
beforeEach(() => jest.clearAllMocks());
|
||||
|
||||
it('redacts split credentials before publishing complete lines', () => {
|
||||
const output = createProcessOutput(logger, ['turn secret']);
|
||||
output.stdout.append('https://preview.test/?tok');
|
||||
output.stdout.append('en=preview-secret&ok=true\n');
|
||||
output.stderr.append('Authorization: Bea');
|
||||
output.stderr.append('rer tool-secret\n{"credential":"turn secret"}\n');
|
||||
expect(logger.info).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
{ source: 'stdout' },
|
||||
'https://preview.test/?token=[REDACTED]&ok=true'
|
||||
);
|
||||
expect(logger.info).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
{ source: 'stderr' },
|
||||
'Authorization: Bearer [REDACTED]'
|
||||
);
|
||||
expect(output.getOutput()).not.toMatch(/preview-secret|tool-secret|turn secret/);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
'argent link argent://[email protected]:5678',
|
||||
'argent link argent://[REDACTED]@127.0.0.1:5678',
|
||||
],
|
||||
[
|
||||
'argent link argent://encoded%[email protected]:5678',
|
||||
'argent link argent://[REDACTED]@127.0.0.1:5678',
|
||||
],
|
||||
[
|
||||
'argent link --host 127.0.0.1 --port 5678 --token startup-secret',
|
||||
'argent link --host 127.0.0.1 --port 5678 --token [REDACTED]',
|
||||
],
|
||||
['(or: argent link --token startup-secret)', '(or: argent link --token [REDACTED])'],
|
||||
[
|
||||
'argent link --token "quoted \\"secret\\"" --port 5678',
|
||||
'argent link --token [REDACTED] --port 5678',
|
||||
],
|
||||
["argent link --token='quoted secret' --port 5678", 'argent link --token=[REDACTED] --port 5678'],
|
||||
])('redacts startup credentials at every chunk boundary: %s', (line, expected) => {
|
||||
for (let split = 0; split <= line.length; split++) {
|
||||
jest.mocked(logger.info).mockClear();
|
||||
const output = createProcessOutput(logger);
|
||||
output.stdout.append(line.slice(0, split));
|
||||
expect(logger.info).not.toHaveBeenCalled();
|
||||
output.stdout.append(line.slice(split) + '\n');
|
||||
expect(logger.info).toHaveBeenCalledWith({ source: 'stdout' }, expected);
|
||||
expect(output.getOutput()).toBe(expected + '\n');
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps stdout and stderr fragments separate and decodes split UTF-8', () => {
|
||||
const output = createProcessOutput(logger);
|
||||
const bytes = Buffer.from('hello 🌍\n');
|
||||
output.stdout.append(bytes.subarray(0, 8));
|
||||
output.stderr.append('error\n');
|
||||
output.stdout.append(bytes.subarray(8));
|
||||
expect(logger.info).toHaveBeenNthCalledWith(1, { source: 'stderr' }, 'error');
|
||||
expect(logger.info).toHaveBeenNthCalledWith(2, { source: 'stdout' }, 'hello 🌍');
|
||||
});
|
||||
|
||||
it('omits overlong lines completely and keeps logging the following diagnostics', () => {
|
||||
const output = createProcessOutput(logger);
|
||||
output.stdout.append('https://preview.test/?token=');
|
||||
output.stdout.append('secret'.repeat(20_000));
|
||||
expect(logger.info).not.toHaveBeenCalled();
|
||||
output.stdout.append('\nfatal diagnostic\n');
|
||||
expect(logger.info).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
{ source: 'stdout' },
|
||||
'[Overlong output line omitted.]'
|
||||
);
|
||||
expect(logger.info).toHaveBeenNthCalledWith(2, { source: 'stdout' }, 'fatal diagnostic');
|
||||
expect(output.getOutput()).not.toContain('secret');
|
||||
});
|
||||
|
||||
it('splits multi-line and CRLF chunks and keeps a line exactly at the length limit', () => {
|
||||
const output = createProcessOutput(logger);
|
||||
const limit = 16 * 1024;
|
||||
output.stdout.append('first\r\nsecond\nthi');
|
||||
output.stdout.append('rd\n' + 'x'.repeat(limit - 1));
|
||||
output.stdout.append('x\n' + 'y'.repeat(limit) + 'y\nafter');
|
||||
output.finish();
|
||||
expect(jest.mocked(logger.info).mock.calls.map(([, line]) => line)).toEqual([
|
||||
'first',
|
||||
'second',
|
||||
'third',
|
||||
'x'.repeat(limit),
|
||||
'[Overlong output line omitted.]',
|
||||
'after',
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps unfinished stdout and stderr lines apart in diagnostics', () => {
|
||||
const output = createProcessOutput(logger);
|
||||
output.stdout.append('done\nDownloading 45%');
|
||||
output.stderr.append('fatal: port in use');
|
||||
expect(output.getOutput()).toBe('done\nDownloading 45%\nfatal: port in use');
|
||||
output.stdout.append('\n');
|
||||
expect(output.getOutput()).toBe('done\nDownloading 45%\nfatal: port in use');
|
||||
});
|
||||
|
||||
it('redacts final partial lines and bounds diagnostics without capping live output', () => {
|
||||
const output = createProcessOutput(logger);
|
||||
for (let index = 0; index < 100; index++) {
|
||||
output.stdout.append('x'.repeat(1023) + '\n');
|
||||
}
|
||||
output.stderr.append('token=final-secret');
|
||||
output.finish();
|
||||
expect(logger.info).toHaveBeenCalledTimes(101);
|
||||
expect(logger.info).toHaveBeenLastCalledWith({ source: 'stderr' }, 'token=[REDACTED]');
|
||||
expect(output.getOutput()).toHaveLength(64 * 1024);
|
||||
expect(output.getOutput()).toContain('token=[REDACTED]');
|
||||
});
|
||||
|
||||
it('applies newly learned secrets to pending output and retained diagnostics', () => {
|
||||
const secrets: string[] = [];
|
||||
const output = createProcessOutput(undefined, secrets);
|
||||
output.stdout.append('opaque-secret\n');
|
||||
output.stderr.append('opaque-secret');
|
||||
secrets.push('opaque-secret');
|
||||
expect(output.getOutput()).not.toContain('opaque-secret');
|
||||
});
|
||||
|
||||
it('redacts JSON token fields with escaped quotes before the token is known', () => {
|
||||
const output = createProcessOutput(logger);
|
||||
output.stdout.append(JSON.stringify({ authToken: 'a"b', controlToken: 'android-secret' }) + '\n');
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ source: 'stdout' },
|
||||
'{"authToken":"[REDACTED]","controlToken":"[REDACTED]"}'
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,156 @@
|
||||
import { type bunyan } from '@expo/logger';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
|
||||
import { spawnDetached } from '../remoteDeviceRunSession';
|
||||
|
||||
jest.unmock('node:fs');
|
||||
jest.unmock('node:fs/promises');
|
||||
jest.mock('../../../sentry');
|
||||
|
||||
it.each([0, 1])(
|
||||
'streams redacted stdout/stderr and drains final partial output on exit %s',
|
||||
async exitCode => {
|
||||
const logger = { info: jest.fn() } as unknown as bunyan;
|
||||
const handle = spawnDetached({
|
||||
command: process.execPath,
|
||||
args: [
|
||||
'-e',
|
||||
`
|
||||
console.log('stdout-marker');
|
||||
console.error('https://preview.test/?token=startup-secret');
|
||||
process.stdout.write('argent link argent://startup-');
|
||||
setTimeout(() => {
|
||||
console.log('[email protected]:5678');
|
||||
console.log('argent link --host 127.0.0.1 --port 5678 --token startup-secret');
|
||||
}, 25);
|
||||
setTimeout(() => {
|
||||
process.stderr.write('final diagnostic');
|
||||
process.exit(${exitCode});
|
||||
}, 100);
|
||||
`,
|
||||
],
|
||||
env: {},
|
||||
logger,
|
||||
});
|
||||
try {
|
||||
for (let tries = 0; tries < 100 && !handle.getExitError(); tries++) {
|
||||
await delay(20);
|
||||
}
|
||||
await handle.stopAsync();
|
||||
expect(handle.getExitError()?.message).toContain(`code ${exitCode}`);
|
||||
expect(logger.info).toHaveBeenCalledWith({ source: 'stdout' }, 'stdout-marker');
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ source: 'stderr' },
|
||||
'https://preview.test/?token=[REDACTED]'
|
||||
);
|
||||
expect(logger.info).toHaveBeenCalledWith({ source: 'stderr' }, 'final diagnostic');
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ source: 'stdout' },
|
||||
'argent link argent://[REDACTED]@127.0.0.1:5678'
|
||||
);
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
{ source: 'stdout' },
|
||||
'argent link --host 127.0.0.1 --port 5678 --token [REDACTED]'
|
||||
);
|
||||
expect(JSON.stringify(jest.mocked(logger.info).mock.calls)).not.toContain('startup-secret');
|
||||
expect(handle.getOutput()).not.toContain('startup-secret');
|
||||
} finally {
|
||||
await handle.stopAsync();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
it('drains descendant shutdown logs after the launcher has exited', async () => {
|
||||
const logger = { info: jest.fn() } as unknown as bunyan;
|
||||
const childScript = `
|
||||
process.on('SIGTERM', () => setTimeout(() => {
|
||||
console.error('descendant-shutdown-marker'); process.exit(0);
|
||||
}, 150));
|
||||
console.log('descendant-ready'); setInterval(() => {}, 1000);
|
||||
`;
|
||||
const handle = spawnDetached({
|
||||
command: process.execPath,
|
||||
args: [
|
||||
'-e',
|
||||
`
|
||||
require('node:child_process').spawn(process.execPath, ['-e', ${JSON.stringify(childScript)}], { stdio: 'inherit' });
|
||||
setTimeout(() => process.exit(0), 200);
|
||||
`,
|
||||
],
|
||||
env: {},
|
||||
logger,
|
||||
});
|
||||
try {
|
||||
for (let tries = 0; tries < 100 && !handle.getExitError(); tries++) {
|
||||
await delay(20);
|
||||
}
|
||||
expect(handle.getExitError()).toBeDefined();
|
||||
await handle.stopAsync();
|
||||
expect(logger.info).toHaveBeenCalledWith({ source: 'stderr' }, 'descendant-shutdown-marker');
|
||||
} finally {
|
||||
await handle.stopAsync();
|
||||
}
|
||||
}, 20_000);
|
||||
|
||||
it('fails a stop whose output a detached descendant still holds open, after flushing it', async () => {
|
||||
const logger = { info: jest.fn() } as unknown as bunyan;
|
||||
const lines = (source: string) =>
|
||||
jest
|
||||
.mocked(logger.info)
|
||||
.mock.calls.filter(([fields]) => (fields as { source: string }).source === source)
|
||||
.map(([, line]) => line as unknown as string);
|
||||
// The descendant leaves the process group and keeps the inherited pipes until killed.
|
||||
const escapedScript = `
|
||||
process.stderr.on('error', () => {});
|
||||
setInterval(() => console.error('escaped-tick'), 50);
|
||||
setTimeout(() => process.exit(0), 30_000);
|
||||
`;
|
||||
const handle = spawnDetached({
|
||||
command: process.execPath,
|
||||
args: [
|
||||
'-e',
|
||||
`
|
||||
const escaped = require('node:child_process').spawn(
|
||||
process.execPath,
|
||||
['-e', ${JSON.stringify(escapedScript)}],
|
||||
{ stdio: 'inherit', detached: true }
|
||||
);
|
||||
console.error('escaped-pid ' + escaped.pid);
|
||||
process.stdout.write('launcher partial');
|
||||
setInterval(() => {}, 1000);
|
||||
`,
|
||||
],
|
||||
env: {},
|
||||
logger,
|
||||
});
|
||||
let escapedPid: number | undefined;
|
||||
try {
|
||||
for (let tries = 0; tries < 100; tries++) {
|
||||
const pidLine = lines('stderr').find(line => line.startsWith('escaped-pid '));
|
||||
escapedPid = pidLine ? Number(pidLine.split(' ')[1]) : undefined;
|
||||
if (escapedPid !== undefined && lines('stderr').includes('escaped-tick')) {
|
||||
break;
|
||||
}
|
||||
await delay(20);
|
||||
}
|
||||
expect(escapedPid).toBeDefined();
|
||||
expect(lines('stdout')).toEqual([]);
|
||||
|
||||
await expect(handle.stopAsync()).rejects.toThrow(
|
||||
'Process output drain timed out after 5000ms.'
|
||||
);
|
||||
expect(handle.getExitError()?.message).toBe('Process exited with signal SIGTERM.');
|
||||
expect(lines('stdout')).toEqual(['launcher partial']);
|
||||
expect(handle.getOutput()).toContain('launcher partial');
|
||||
const ticks = lines('stderr').length;
|
||||
await delay(250);
|
||||
expect(lines('stderr')).toHaveLength(ticks);
|
||||
} finally {
|
||||
if (escapedPid !== undefined) {
|
||||
try {
|
||||
process.kill(escapedPid, 'SIGKILL');
|
||||
} catch {}
|
||||
}
|
||||
await handle.stopAsync().catch(() => {});
|
||||
}
|
||||
}, 20_000);
|
||||
@@ -71,6 +71,7 @@ function createLoggerMock(): bunyan {
|
||||
warn: jest.fn(),
|
||||
error: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
child: jest.fn().mockReturnThis(),
|
||||
} as unknown as bunyan;
|
||||
}
|
||||
|
||||
@@ -677,6 +678,43 @@ describe(waitForWebPreviewReadyAsync, () => {
|
||||
});
|
||||
|
||||
describe(startNgrokTunnelAsync, () => {
|
||||
it.each(['rejected', 'stalled'] as const)(
|
||||
'retains a %s close failure on repeated stops',
|
||||
async mode => {
|
||||
jest.useFakeTimers();
|
||||
try {
|
||||
const failure = new Error('close failed');
|
||||
const close = jest
|
||||
.fn()
|
||||
.mockImplementation(() =>
|
||||
mode === 'rejected' ? Promise.reject(failure) : new Promise<void>(() => {})
|
||||
);
|
||||
jest.mocked(ngrok.forward).mockResolvedValue({
|
||||
url: () => 'https://web-preview.example.test',
|
||||
close,
|
||||
} as never);
|
||||
const tunnel = await startNgrokTunnelAsync({
|
||||
port: 4321,
|
||||
subdomainPrefix: 'web-preview',
|
||||
baseDomain: 'eas-simulator.ngrok.dev',
|
||||
authtoken: 'token',
|
||||
logger: createLoggerMock(),
|
||||
});
|
||||
const stopping = tunnel.stopAsync();
|
||||
const assertion = expect(stopping).rejects.toThrow(
|
||||
mode === 'rejected' ? 'close failed' : 'Ngrok tunnel stop timed out after 4000ms.'
|
||||
);
|
||||
expect(tunnel.stopAsync()).toBe(stopping);
|
||||
await jest.advanceTimersByTimeAsync(4_000);
|
||||
await assertion;
|
||||
await expect(tunnel.stopAsync()).rejects.toThrow();
|
||||
expect(close).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
jest.useRealTimers();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
it('uses a 128-bit capability hostname and exposes explicit cleanup', async () => {
|
||||
const close = jest.fn().mockResolvedValue(undefined);
|
||||
jest.mocked(ngrok.forward).mockResolvedValue({
|
||||
@@ -716,7 +754,15 @@ describe('spawnDetached process group shutdown', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
const spawned = Object.assign(Promise.resolve(undefined), {
|
||||
child: { pid: 4321, unref: jest.fn(), once: jest.fn() },
|
||||
child: {
|
||||
pid: 4321,
|
||||
unref: jest.fn(),
|
||||
once: jest.fn((event, callback) => {
|
||||
if (event === 'close') {
|
||||
queueMicrotask(callback);
|
||||
}
|
||||
}),
|
||||
},
|
||||
});
|
||||
jest.mocked(spawn).mockReturnValue(spawned as never);
|
||||
});
|
||||
@@ -751,7 +797,16 @@ describe('spawnDetached process group shutdown', () => {
|
||||
});
|
||||
|
||||
it('kills a detached child that outlives the shutdown deadline', async () => {
|
||||
const kill = jest.spyOn(process, 'kill').mockReturnValue(true);
|
||||
let killed = false;
|
||||
const kill = jest.spyOn(process, 'kill').mockImplementation((pid, signal) => {
|
||||
if (pid === -4321 && signal === 'SIGKILL') {
|
||||
killed = true;
|
||||
}
|
||||
if (killed && signal === 0) {
|
||||
throw Object.assign(new Error('Process group exited'), { code: 'ESRCH' });
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const detached = spawnDetached({ command: 'npx', args: [], env, stopGracePeriodMs: 0 });
|
||||
await detached.stopAsync();
|
||||
@@ -790,7 +845,11 @@ describe(startDeviceSessionHostAsync, () => {
|
||||
child: {
|
||||
pid: undefined,
|
||||
unref: jest.fn(),
|
||||
once: jest.fn(),
|
||||
once: jest.fn((event, callback) => {
|
||||
if (event === 'close') {
|
||||
queueMicrotask(callback);
|
||||
}
|
||||
}),
|
||||
},
|
||||
});
|
||||
jest.mocked(spawn).mockReturnValue(spawnPromise as never);
|
||||
@@ -833,6 +892,7 @@ describe(startDeviceSessionHostAsync, () => {
|
||||
expect(spawnDetachedSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ stopGracePeriodMs: SERVE_SIM_STOP_GRACE_PERIOD_MS })
|
||||
);
|
||||
expect(spawnDetachedSpy.mock.calls[0][0].stopGracePeriodMs).toBeGreaterThanOrEqual(120_000);
|
||||
await host.finishAsync();
|
||||
});
|
||||
|
||||
|
||||
@@ -98,13 +98,22 @@ it.each([undefined, 'all'])('refuses an unconfirmed user-app scope (%s)', async
|
||||
|
||||
it('aborts a quiet live stream and drains preceding writes before returning', async () => {
|
||||
const controller = new AbortController();
|
||||
const fsPromises = jest.requireActual<typeof import('node:fs/promises')>('node:fs/promises');
|
||||
const openFile = fsPromises.open;
|
||||
jest.spyOn(fsPromises, 'open').mockImplementationOnce(async (...args) => {
|
||||
const file = await openFile(...args);
|
||||
const write = file.writeFile.bind(file);
|
||||
jest.spyOn(file, 'writeFile').mockImplementationOnce(async (...args) => {
|
||||
const pending = write(...args);
|
||||
controller.abort();
|
||||
await pending;
|
||||
});
|
||||
return file;
|
||||
});
|
||||
const stream = new Readable({ read() {} });
|
||||
stream.push('data: {"pid":42}\n\n');
|
||||
jest.mocked(fetch).mockResolvedValue(new Response(stream));
|
||||
const done = record({ signal: controller.signal });
|
||||
await delay(20);
|
||||
controller.abort();
|
||||
expect((await done).receivedData).toBe(true);
|
||||
expect((await record({ signal: controller.signal })).receivedData).toBe(true);
|
||||
expect(stream.destroyed).toBe(true);
|
||||
expect(await readFile(path.join(directory, 'logs.ndjson'), 'utf8')).toBe('{"pid":42}\n');
|
||||
});
|
||||
|
||||
@@ -3,6 +3,8 @@ import { asyncResult } from '@expo/results';
|
||||
import fetch, { Response } from 'node-fetch';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { promiseRetryWithCondition } from '../../../utils/promiseRetryWithCondition';
|
||||
|
||||
const PostApi = {
|
||||
'/token': {
|
||||
request: z.object({
|
||||
@@ -46,14 +48,22 @@ export class GooglePlayAuthClient {
|
||||
signal?: AbortSignal
|
||||
): Promise<z.output<(typeof PostApi)[TPath]['response']>> {
|
||||
const schema = PostApi[path];
|
||||
return await this.requestAsync({
|
||||
method: 'POST',
|
||||
path,
|
||||
body,
|
||||
requestSchema: schema.request,
|
||||
responseSchema: schema.response,
|
||||
signal,
|
||||
});
|
||||
return await promiseRetryWithCondition(
|
||||
() =>
|
||||
this.requestAsync({
|
||||
method: 'POST',
|
||||
path,
|
||||
body,
|
||||
requestSchema: schema.request,
|
||||
responseSchema: schema.response,
|
||||
signal,
|
||||
}),
|
||||
error =>
|
||||
!signal?.aborted &&
|
||||
error instanceof GooglePlayAuthRequestError &&
|
||||
(error.status === 429 || error.status >= 500),
|
||||
{ retries: 3, factor: 2, minTimeout: 1000, maxTimeout: 4000 }
|
||||
)();
|
||||
}
|
||||
|
||||
private async requestAsync({
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { UserError } from '@expo/eas-build-job';
|
||||
import fs from 'node:fs/promises';
|
||||
import { z } from 'zod';
|
||||
import * as jose from 'jose';
|
||||
import { KeyObject } from 'node:crypto';
|
||||
import { KeyObject, createPrivateKey } from 'node:crypto';
|
||||
|
||||
import { GooglePlayAuthClient } from './GooglePlayAuthClient';
|
||||
|
||||
@@ -10,6 +13,46 @@ export type GoogleServiceAccount = {
|
||||
};
|
||||
|
||||
export namespace GooglePlayAuthUtils {
|
||||
export async function loadGoogleServiceAccountAsync({
|
||||
keyPath,
|
||||
}: {
|
||||
keyPath: string;
|
||||
}): Promise<GoogleServiceAccount> {
|
||||
let contents: string;
|
||||
try {
|
||||
contents = await fs.readFile(keyPath, 'utf8');
|
||||
} catch (error) {
|
||||
throw new UserError(
|
||||
'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
|
||||
(error as NodeJS.ErrnoException).code === 'ENOENT'
|
||||
? `Service-account key file not found at ${keyPath}.`
|
||||
: `Cannot read the service-account key file at ${keyPath}.`,
|
||||
{ cause: error }
|
||||
);
|
||||
}
|
||||
try {
|
||||
const credentials = z
|
||||
.object({
|
||||
type: z.literal('service_account'),
|
||||
client_email: z.email(),
|
||||
private_key: z.string().min(1),
|
||||
private_key_id: z.string().optional(),
|
||||
})
|
||||
.parse(JSON.parse(contents));
|
||||
const privateKey = createPrivateKey(credentials.private_key);
|
||||
if (privateKey.asymmetricKeyType !== 'rsa') {
|
||||
throw new Error('Expected an RSA private key.');
|
||||
}
|
||||
return { ...credentials, private_key: privateKey };
|
||||
} catch {
|
||||
// Neither JSON parse errors nor validation errors may include credential content.
|
||||
throw new UserError(
|
||||
'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
|
||||
'Cannot read the Google service-account key. Provide a valid service-account JSON file.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createAssertionAsync(serviceAccount: GoogleServiceAccount): Promise<string> {
|
||||
return await new jose.SignJWT({
|
||||
scope: 'https://www.googleapis.com/auth/androidpublisher',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SystemError } from '@expo/eas-build-job';
|
||||
import fetch, { Response } from 'node-fetch';
|
||||
import fetch, { RequestInit, Response } from 'node-fetch';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { GooglePlayAuthUtils, GoogleServiceAccount } from './GooglePlayAuthUtils';
|
||||
@@ -12,9 +12,36 @@ export class GooglePlayApiError extends Error {
|
||||
) {
|
||||
super(`Google Play request failed (HTTP ${status})${apiMessage ? `: ${apiMessage}` : '.'}`);
|
||||
}
|
||||
|
||||
static async fromResponseAsync(
|
||||
response: Response,
|
||||
signal?: AbortSignal
|
||||
): Promise<GooglePlayApiError> {
|
||||
let data: unknown;
|
||||
try {
|
||||
data = await response.json();
|
||||
} catch {
|
||||
signal?.throwIfAborted();
|
||||
// Raw text or HTML can contain the request URL, including an upload secret.
|
||||
}
|
||||
const parsed = z
|
||||
.object({
|
||||
error: z.object({
|
||||
message: z.string().optional(),
|
||||
errors: z.array(z.object({ reason: z.string().optional() })).optional(),
|
||||
}),
|
||||
})
|
||||
.safeParse(data);
|
||||
return new GooglePlayApiError(
|
||||
response.status,
|
||||
parsed.data?.error.message ?? '',
|
||||
parsed.data?.error.errors?.flatMap(error => (error.reason ? [error.reason] : [])) ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const ReleaseStatusZ = z.enum(['draft', 'inProgress', 'halted', 'completed']);
|
||||
export const ReleaseStatusZ = z.enum(['draft', 'inProgress', 'halted', 'completed']);
|
||||
export type ReleaseStatus = z.output<typeof ReleaseStatusZ>;
|
||||
|
||||
const ReleaseNoteZ = z.object({
|
||||
language: z.string(),
|
||||
@@ -143,7 +170,10 @@ export class GooglePlayClient {
|
||||
path: TPath,
|
||||
body: z.input<(typeof PostApi)[TPath]['request']>,
|
||||
params: z.input<(typeof PostApi)[TPath]['path']>,
|
||||
options: { query?: z.input<(typeof PostApi)[TPath]['query']>; signal?: AbortSignal } = {}
|
||||
options: {
|
||||
query?: z.input<(typeof PostApi)[TPath]['query']>;
|
||||
signal?: AbortSignal;
|
||||
} = {}
|
||||
): Promise<z.output<(typeof PostApi)[TPath]['response']>> {
|
||||
return await this.sendJsonRequestAsync(
|
||||
'POST',
|
||||
@@ -210,7 +240,8 @@ export class GooglePlayClient {
|
||||
method,
|
||||
search.size ? `${path}?${search}` : path,
|
||||
method === 'GET' ? undefined : JSON.stringify(parsedBody),
|
||||
signal
|
||||
signal,
|
||||
{ 'Content-Type': 'application/json' }
|
||||
);
|
||||
|
||||
let data: unknown;
|
||||
@@ -233,11 +264,12 @@ export class GooglePlayClient {
|
||||
return parsed.data;
|
||||
}
|
||||
|
||||
private async requestAsync(
|
||||
async requestAsync(
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
||||
path: string,
|
||||
body?: string,
|
||||
signal?: AbortSignal
|
||||
signal?: AbortSignal,
|
||||
headers?: RequestInit['headers']
|
||||
): Promise<Response> {
|
||||
const url = new URL(path, this.baseUrl);
|
||||
const token = await this.getTokenAsync(signal);
|
||||
@@ -248,36 +280,18 @@ export class GooglePlayClient {
|
||||
method,
|
||||
body,
|
||||
signal,
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
headers: { ...headers, Authorization: `Bearer ${token}` },
|
||||
redirect: 'manual',
|
||||
});
|
||||
} catch {
|
||||
} catch (error) {
|
||||
signal?.throwIfAborted();
|
||||
throw new SystemError('Google Play request failed before a response was received.');
|
||||
throw new SystemError('Google Play request failed before a response was received.', {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let data: unknown;
|
||||
try {
|
||||
data = await response.json();
|
||||
} catch {
|
||||
signal?.throwIfAborted();
|
||||
}
|
||||
const parsed = z
|
||||
.object({
|
||||
error: z.object({
|
||||
message: z.string().optional(),
|
||||
errors: z.array(z.object({ reason: z.string().optional() })).optional(),
|
||||
}),
|
||||
})
|
||||
.safeParse(data);
|
||||
throw new GooglePlayApiError(
|
||||
response.status,
|
||||
parsed.success ? (parsed.data.error.message ?? '') : '',
|
||||
parsed.success
|
||||
? (parsed.data.error.errors?.flatMap(error => (error.reason ? [error.reason] : [])) ?? [])
|
||||
: []
|
||||
);
|
||||
throw await GooglePlayApiError.fromResponseAsync(response, signal);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
import { SystemError } from '@expo/eas-build-job';
|
||||
import fetch, { FetchError, Response } from 'node-fetch';
|
||||
import promiseRetry from 'promise-retry';
|
||||
import { FileHandle } from 'node:fs/promises';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { GooglePlayApiError, GooglePlayClient } from './GooglePlayClient';
|
||||
import { AndroidArtifactType } from './appArtifact';
|
||||
|
||||
const UploadResponseZ = z.object({
|
||||
versionCode: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
||||
});
|
||||
|
||||
const CHUNK_SIZE = 8 * 1024 * 1024;
|
||||
// Google recommends a two-minute timeout for bundle uploads, including processing.
|
||||
const REQUEST_TIMEOUT_MS = 120_000;
|
||||
|
||||
export namespace GooglePlayResumableUpload {
|
||||
export async function createUploadSessionAsync({
|
||||
client,
|
||||
packageName,
|
||||
editId,
|
||||
artifactType,
|
||||
signal,
|
||||
size,
|
||||
}: {
|
||||
client: GooglePlayClient;
|
||||
packageName: string;
|
||||
editId: string;
|
||||
artifactType: AndroidArtifactType;
|
||||
signal?: AbortSignal;
|
||||
size: number;
|
||||
}): Promise<URL> {
|
||||
const resource = artifactType === 'apk' ? 'apks' : 'bundles';
|
||||
const response = await promiseRetry(
|
||||
async retry => {
|
||||
signal?.throwIfAborted();
|
||||
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
|
||||
const requestSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
||||
try {
|
||||
return await client.requestAsync(
|
||||
'POST',
|
||||
`/upload/androidpublisher/v3/applications/${encodeURIComponent(packageName)}/edits/${encodeURIComponent(editId)}/${resource}?uploadType=resumable`,
|
||||
undefined,
|
||||
requestSignal,
|
||||
{
|
||||
'Content-Length': '0',
|
||||
'X-Upload-Content-Length': String(size),
|
||||
'X-Upload-Content-Type': getContentTypeFromArtifactType(artifactType),
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
signal?.throwIfAborted();
|
||||
if (
|
||||
timeout.aborted ||
|
||||
isNetworkRetryable(error) ||
|
||||
(error instanceof GooglePlayApiError && (error.status === 429 || error.status >= 500))
|
||||
) {
|
||||
retry(
|
||||
timeout.aborted
|
||||
? new SystemError('Google Play upload session request timed out.')
|
||||
: error
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
{
|
||||
retries: 5,
|
||||
factor: 2,
|
||||
minTimeout: 1000,
|
||||
maxTimeout: 32_000,
|
||||
randomize: true,
|
||||
}
|
||||
);
|
||||
const location = response.headers.get('location');
|
||||
if (!location) {
|
||||
throw new SystemError('Google did not return an upload session.');
|
||||
}
|
||||
let session: URL;
|
||||
try {
|
||||
session = new URL(location);
|
||||
} catch {
|
||||
// Node's URL error retains the input, which can contain the upload secret.
|
||||
throw new SystemError('Google returned an invalid upload URL.');
|
||||
}
|
||||
if (session.origin !== 'https://androidpublisher.googleapis.com') {
|
||||
throw new SystemError(
|
||||
`Google returned an unsafe upload URL: expected origin https://androidpublisher.googleapis.com, got ${session.origin}.`
|
||||
);
|
||||
}
|
||||
if (session.username || session.password) {
|
||||
throw new SystemError(
|
||||
'Google returned an unsafe upload URL containing a username or password. Upload sessions must not send HTTP Basic credentials.'
|
||||
);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function uploadSessionAsync({
|
||||
file,
|
||||
size,
|
||||
session,
|
||||
artifactType,
|
||||
signal,
|
||||
onProgress,
|
||||
}: {
|
||||
file: FileHandle;
|
||||
size: number;
|
||||
session: URL;
|
||||
artifactType: AndroidArtifactType;
|
||||
signal?: AbortSignal;
|
||||
onProgress?: (uploadedBytes: number, totalBytes: number) => void;
|
||||
}): Promise<z.output<typeof UploadResponseZ>> {
|
||||
const contentType = getContentTypeFromArtifactType(artifactType);
|
||||
let offset = 0;
|
||||
onProgress?.(0, size);
|
||||
|
||||
while (offset < size) {
|
||||
const result = await uploadChunkAsync({ file, size, session, contentType, offset, signal });
|
||||
if (result.status === 'completed') {
|
||||
onProgress?.(size, size);
|
||||
return result.data;
|
||||
}
|
||||
offset = result.offset;
|
||||
onProgress?.(offset, size);
|
||||
}
|
||||
throw new SystemError(`Google upload stopped at ${offset} of ${size} bytes.`);
|
||||
}
|
||||
|
||||
async function uploadChunkAsync({
|
||||
file,
|
||||
size,
|
||||
session,
|
||||
contentType,
|
||||
offset,
|
||||
signal,
|
||||
}: {
|
||||
file: FileHandle;
|
||||
size: number;
|
||||
session: URL;
|
||||
contentType: string;
|
||||
offset: number;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<
|
||||
| { status: 'completed'; data: z.output<typeof UploadResponseZ> }
|
||||
| { status: 'progress'; offset: number }
|
||||
> {
|
||||
let checkServerOffset = false;
|
||||
// Confirmed progress starts a new retry budget. Retries first check the server offset.
|
||||
return await promiseRetry(
|
||||
async retry => {
|
||||
while (true) {
|
||||
signal?.throwIfAborted();
|
||||
const end = Math.min(offset + CHUNK_SIZE, size);
|
||||
let body: Buffer | undefined;
|
||||
if (!checkServerOffset) {
|
||||
// Only this chunk is held in memory, never the whole file.
|
||||
body = Buffer.alloc(end - offset);
|
||||
const { bytesRead } = await file.read(body, 0, body.length, offset);
|
||||
if (bytesRead !== body.length) {
|
||||
throw new SystemError(
|
||||
`The Android binary changed during upload: expected ${body.length} bytes at offset ${offset}, got ${bytesRead}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
|
||||
const requestSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch(session.toString(), {
|
||||
method: 'PUT',
|
||||
redirect: 'manual',
|
||||
headers: {
|
||||
'Content-Length': String(body?.length ?? 0),
|
||||
'Content-Range': checkServerOffset
|
||||
? `bytes */${size}`
|
||||
: `bytes ${offset}-${end - 1}/${size}`,
|
||||
'Content-Type': contentType,
|
||||
},
|
||||
body,
|
||||
signal: requestSignal,
|
||||
});
|
||||
} catch (error) {
|
||||
signal?.throwIfAborted();
|
||||
const failure = new SystemError(
|
||||
'Google Play upload failed before a response was received.'
|
||||
);
|
||||
if (timeout.aborted || isNetworkRetryable(error)) {
|
||||
checkServerOffset = true;
|
||||
retry(failure);
|
||||
}
|
||||
throw failure;
|
||||
}
|
||||
|
||||
if (!response.ok && response.status !== 308) {
|
||||
const error = await GooglePlayApiError.fromResponseAsync(response, signal);
|
||||
if (timeout.aborted) {
|
||||
checkServerOffset = true;
|
||||
return retry(new SystemError('Google Play upload response timed out.'));
|
||||
}
|
||||
if (response.status === 429 || response.status >= 500) {
|
||||
checkServerOffset = true;
|
||||
retry(error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (response.status === 200 || response.status === 201) {
|
||||
let data: unknown;
|
||||
try {
|
||||
data = await response.json();
|
||||
} catch {
|
||||
signal?.throwIfAborted();
|
||||
checkServerOffset = true;
|
||||
return retry(new SystemError('Could not read the Google Play upload response.'));
|
||||
}
|
||||
const parsed = UploadResponseZ.safeParse(data);
|
||||
if (!parsed.success) {
|
||||
throw new SystemError('Google completed the upload without a valid version code.');
|
||||
}
|
||||
return { status: 'completed', data: parsed.data };
|
||||
}
|
||||
if (response.status !== 308) {
|
||||
throw new SystemError(`Unexpected Google upload status: ${response.status}.`);
|
||||
}
|
||||
|
||||
const range = response.headers.get('range');
|
||||
const match = range ? /^bytes=0-(\d+)$/.exec(range) : undefined;
|
||||
const next = range ? (match ? Number(match[1]) + 1 : NaN) : 0;
|
||||
if (
|
||||
!Number.isSafeInteger(next) ||
|
||||
next < offset ||
|
||||
next > size ||
|
||||
(!checkServerOffset && next > end)
|
||||
) {
|
||||
throw new SystemError('Google returned an invalid upload range.');
|
||||
}
|
||||
if (next === size) {
|
||||
checkServerOffset = true;
|
||||
// All bytes are stored, but only 200/201 confirms completion.
|
||||
// Keep the current retry budget and send only status checks.
|
||||
return retry(
|
||||
new SystemError(`Google stored all ${size} bytes but has not completed the upload.`)
|
||||
);
|
||||
}
|
||||
if (next > offset) {
|
||||
return { status: 'progress', offset: next };
|
||||
}
|
||||
if (!checkServerOffset) {
|
||||
checkServerOffset = true;
|
||||
retry(
|
||||
new SystemError(
|
||||
`Google upload made no progress: confirmed ${offset} of ${size} bytes after sending bytes ${offset}-${end - 1}.`
|
||||
)
|
||||
);
|
||||
}
|
||||
// The status check confirmed no new bytes. Send the chunk again.
|
||||
checkServerOffset = false;
|
||||
}
|
||||
},
|
||||
{
|
||||
retries: 5,
|
||||
factor: 2,
|
||||
minTimeout: 1000,
|
||||
maxTimeout: 32_000,
|
||||
randomize: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getContentTypeFromArtifactType(artifactType: AndroidArtifactType): string {
|
||||
return artifactType === 'apk'
|
||||
? 'application/vnd.android.package-archive'
|
||||
: 'application/octet-stream';
|
||||
}
|
||||
|
||||
function isNetworkRetryable(error: unknown): boolean {
|
||||
const visited = new Set<Error>();
|
||||
while (error instanceof Error && !visited.has(error)) {
|
||||
if (error instanceof FetchError && error.type === 'system') {
|
||||
return true;
|
||||
}
|
||||
visited.add(error);
|
||||
error = error.cause;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
import { SystemError, UserError } from '@expo/eas-build-job';
|
||||
import { bunyan } from '@expo/logger';
|
||||
import fs from 'node:fs/promises';
|
||||
import promiseRetry from 'promise-retry';
|
||||
|
||||
import { GooglePlayAuthRequestError } from './GooglePlayAuthClient';
|
||||
import { GooglePlayApiError, GooglePlayClient, ReleaseStatus } from './GooglePlayClient';
|
||||
import { GooglePlayResumableUpload } from './GooglePlayResumableUpload';
|
||||
import { AndroidArtifactType } from './appArtifact';
|
||||
|
||||
export class GooglePlayCommitOutcomeUnknownError extends SystemError {}
|
||||
|
||||
export namespace GooglePlayUtils {
|
||||
export async function uploadApplicationAsync(
|
||||
client: GooglePlayClient,
|
||||
options: {
|
||||
packageName: string;
|
||||
editId: string;
|
||||
artifactPath: string;
|
||||
artifactType: AndroidArtifactType;
|
||||
signal?: AbortSignal;
|
||||
onProgress?: (uploadedBytes: number, totalBytes: number) => void;
|
||||
}
|
||||
): Promise<{ versionCode: number }> {
|
||||
options.signal?.throwIfAborted();
|
||||
const file = await fs.open(options.artifactPath, 'r');
|
||||
try {
|
||||
const { size } = await file.stat();
|
||||
if (!Number.isSafeInteger(size) || size <= 0) {
|
||||
throw new UserError(
|
||||
'EAS_GOOGLE_PLAY_INVALID_BINARY',
|
||||
'Cannot upload an empty or invalid Android binary.'
|
||||
);
|
||||
}
|
||||
return await promiseRetry(
|
||||
async retry => {
|
||||
const session = await GooglePlayResumableUpload.createUploadSessionAsync({
|
||||
...options,
|
||||
client,
|
||||
size,
|
||||
});
|
||||
try {
|
||||
return await GooglePlayResumableUpload.uploadSessionAsync({
|
||||
...options,
|
||||
file,
|
||||
size,
|
||||
session,
|
||||
});
|
||||
} catch (error) {
|
||||
options.signal?.throwIfAborted();
|
||||
// 404/410 from an existing session mean it is gone; other failures
|
||||
// must not restart the whole file upload.
|
||||
if (error instanceof GooglePlayApiError && [404, 410].includes(error.status)) {
|
||||
retry(error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
{ retries: 2, factor: 2, minTimeout: 1000, maxTimeout: 32_000, randomize: true }
|
||||
);
|
||||
} finally {
|
||||
await file.close();
|
||||
}
|
||||
}
|
||||
|
||||
export async function createEditAsync(
|
||||
client: GooglePlayClient,
|
||||
{ packageName, signal }: { packageName: string; signal?: AbortSignal }
|
||||
): Promise<{ id: string }> {
|
||||
return await client.postAsync(
|
||||
'/androidpublisher/v3/applications/:packageName/edits',
|
||||
{},
|
||||
{ packageName },
|
||||
{ signal }
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateTrackAsync(
|
||||
client: GooglePlayClient,
|
||||
{
|
||||
packageName,
|
||||
editId,
|
||||
track,
|
||||
release,
|
||||
versionCode,
|
||||
changelog,
|
||||
signal,
|
||||
}: {
|
||||
packageName: string;
|
||||
editId: string;
|
||||
track: string;
|
||||
release: { status: ReleaseStatus; userFraction?: number };
|
||||
versionCode: number;
|
||||
changelog?: { locale: string; text: string };
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
): Promise<void> {
|
||||
await client.putAsync(
|
||||
'/androidpublisher/v3/applications/:packageName/edits/:editId/tracks/:track',
|
||||
{
|
||||
track,
|
||||
releases: [
|
||||
{
|
||||
...release,
|
||||
versionCodes: [String(versionCode)],
|
||||
...(changelog
|
||||
? { releaseNotes: [{ language: changelog.locale, text: changelog.text }] }
|
||||
: {}),
|
||||
},
|
||||
],
|
||||
},
|
||||
{ packageName, editId, track },
|
||||
signal
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteEditAsync(
|
||||
client: GooglePlayClient,
|
||||
{ packageName, editId, signal }: { packageName: string; editId: string; signal?: AbortSignal }
|
||||
): Promise<void> {
|
||||
await client.deleteAsync(
|
||||
'/androidpublisher/v3/applications/:packageName/edits/:editId',
|
||||
{ packageName, editId },
|
||||
signal
|
||||
);
|
||||
}
|
||||
|
||||
export async function commitEditAsync(
|
||||
client: GooglePlayClient,
|
||||
{
|
||||
packageName,
|
||||
editId,
|
||||
changesNotSentForReview,
|
||||
logger,
|
||||
signal,
|
||||
}: {
|
||||
packageName: string;
|
||||
editId: string;
|
||||
changesNotSentForReview: boolean;
|
||||
logger: bunyan;
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
): Promise<void> {
|
||||
const commitOnceAsync = async ({
|
||||
changesNotSentForReview,
|
||||
}: {
|
||||
changesNotSentForReview?: boolean;
|
||||
}): Promise<void> => {
|
||||
signal?.throwIfAborted();
|
||||
try {
|
||||
const committed = await client.postAsync(
|
||||
'/androidpublisher/v3/applications/:packageName/edits/:editId:commit',
|
||||
{},
|
||||
{ packageName, editId },
|
||||
{ query: { changesNotSentForReview }, signal }
|
||||
);
|
||||
if (committed?.id !== editId) {
|
||||
throw new SystemError('Google did not confirm the committed edit.');
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof GooglePlayAuthRequestError) {
|
||||
throw error;
|
||||
}
|
||||
if (
|
||||
!(error instanceof GooglePlayApiError) ||
|
||||
error.status >= 500 ||
|
||||
error.status === 408 ||
|
||||
error.status === 429
|
||||
) {
|
||||
throw new GooglePlayCommitOutcomeUnknownError(
|
||||
'Google Play commit outcome is unknown. Check the release in Play Console before you submit again. The commit was not retried.',
|
||||
{ cause: error }
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
try {
|
||||
// Omit the optional parameter for normal review submission. Some app states
|
||||
// reject its presence, even when false. True saves changes for review in Console.
|
||||
await commitOnceAsync({ changesNotSentForReview: changesNotSentForReview || undefined });
|
||||
} catch (error) {
|
||||
if (!(error instanceof GooglePlayApiError) || error.status !== 400) {
|
||||
throw error;
|
||||
}
|
||||
// Like Fastlane, retry only an explicit rejection of the review setting.
|
||||
if (
|
||||
changesNotSentForReview &&
|
||||
error.apiMessage.includes('The query parameter changesNotSentForReview must not be set')
|
||||
) {
|
||||
logger.warn(
|
||||
'Google does not allow changesNotSentForReview for this app right now. Retrying commit once without it. The changes will be sent for review.'
|
||||
);
|
||||
await commitOnceAsync({});
|
||||
} else if (
|
||||
!changesNotSentForReview &&
|
||||
error.apiMessage.includes('Please set the query parameter changesNotSentForReview to true')
|
||||
) {
|
||||
logger.warn(
|
||||
'Google requires changesNotSentForReview=true. Retrying commit once. Send the saved changes for review from Play Console.'
|
||||
);
|
||||
await commitOnceAsync({ changesNotSentForReview: true });
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function mapGooglePlayError(error: unknown): unknown {
|
||||
if (
|
||||
(error instanceof GooglePlayApiError || error instanceof GooglePlayAuthRequestError) &&
|
||||
(error.status === 408 || error.status === 429 || error.status >= 500)
|
||||
) {
|
||||
return new SystemError(
|
||||
`Google Play is temporarily unavailable or rate limited (HTTP ${error.status}). Try again later.`,
|
||||
{ cause: error }
|
||||
);
|
||||
}
|
||||
if (
|
||||
error instanceof GooglePlayAuthRequestError &&
|
||||
error.status >= 400 &&
|
||||
error.status < 500 &&
|
||||
error.status !== 408 &&
|
||||
error.status !== 429
|
||||
) {
|
||||
return new UserError(
|
||||
'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
|
||||
`Google rejected the service-account key (${error.errorCode ?? `HTTP ${error.status}`}). Check that the key is valid and the service account is enabled.`,
|
||||
{ cause: error }
|
||||
);
|
||||
}
|
||||
if (!(error instanceof GooglePlayApiError)) {
|
||||
return error;
|
||||
}
|
||||
const message = error.apiMessage;
|
||||
const reasons = new Set(error.reasons);
|
||||
let code = 'EAS_GOOGLE_PLAY_REQUEST_FAILED';
|
||||
let detail = `Google Play rejected the request (HTTP ${error.status}; reasons: ${error.reasons.join(', ') || 'unspecified'}). Check the app and release settings in Play Console. Concurrent edits or Console changes can invalidate an edit.`;
|
||||
if (message.includes('Package not found')) {
|
||||
code = 'EAS_GOOGLE_PLAY_FIRST_UPLOAD';
|
||||
detail =
|
||||
'Google Play cannot find the app. Check the package name and upload the first version manually in Play Console.';
|
||||
} else if (
|
||||
/version code.*already (?:been )?used/i.test(message) ||
|
||||
reasons.has('apkNotificationMessageKeyUpgradeVersionConflict') ||
|
||||
message.includes('apkNotificationMessageKeyUpgradeVersionConflict')
|
||||
) {
|
||||
code = 'EAS_GOOGLE_PLAY_VERSION_CODE_USED';
|
||||
detail =
|
||||
'This version code was already uploaded. Increase the Android version code and build a new binary.';
|
||||
} else if (
|
||||
/privacy policy/i.test(message) ||
|
||||
reasons.has('apkNotificationMessageKeyPermissionsRequirePrivacyPolicy') ||
|
||||
message.includes('apkNotificationMessageKeyPermissionsRequirePrivacyPolicy')
|
||||
) {
|
||||
code = 'EAS_GOOGLE_PLAY_PRIVACY_POLICY_REQUIRED';
|
||||
detail = 'This app requires a privacy policy. Add it in Play Console before you submit.';
|
||||
} else if (message.includes('Only releases with status draft may be created on draft app')) {
|
||||
code = 'EAS_GOOGLE_PLAY_DRAFT_APP';
|
||||
detail =
|
||||
'This app is a draft in Play Console. Complete its required metadata or submit with release_status: draft.';
|
||||
} else if (error.status === 409 || /edit.*(?:expired|invalid|not found)/i.test(message)) {
|
||||
code = 'EAS_GOOGLE_PLAY_EDIT_INVALID';
|
||||
detail =
|
||||
'The Google Play edit is no longer valid. A concurrent edit or Play Console change can invalidate it. Check the app in Play Console before you submit again.';
|
||||
} else if (error.status === 401 || message.includes('The caller does not have permission')) {
|
||||
code = 'EAS_GOOGLE_PLAY_PERMISSION_DENIED';
|
||||
detail =
|
||||
'The Google service account cannot submit this app. Check its key and app permissions in Play Console.';
|
||||
} else if (error.status === 400) {
|
||||
code = 'EAS_GOOGLE_PLAY_INVALID_RELEASE';
|
||||
detail =
|
||||
'Google Play rejected the release or review settings. Check the track, release status, rollout, and review settings in Play Console.';
|
||||
}
|
||||
return new UserError(code, message ? `${detail} Google Play said: ${message}` : detail, {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -109,3 +109,19 @@ it.each(['network failure', 'malformed JSON'])('returns a system error for %s',
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it.each([429, 503])('retries temporary OAuth HTTP %s responses', async status => {
|
||||
nock('https://oauth2.googleapis.com')
|
||||
.post('/token', request)
|
||||
.reply(status)
|
||||
.post('/token', request)
|
||||
.reply(200, { access_token: 'recovered', expires_in: 3600, token_type: 'Bearer' });
|
||||
await expect(client.postAsync('/token', request)).resolves.toMatchObject({
|
||||
access_token: 'recovered',
|
||||
});
|
||||
});
|
||||
|
||||
it('stops after three OAuth retries', async () => {
|
||||
nock('https://oauth2.googleapis.com').post('/token', request).times(4).reply(503);
|
||||
await expect(client.postAsync('/token', request)).rejects.toMatchObject({ status: 503 });
|
||||
}, 15000);
|
||||
@@ -0,0 +1,122 @@
|
||||
import { SystemError, UserError } from '@expo/eas-build-job';
|
||||
import nock from 'nock';
|
||||
|
||||
import { api, editPath, mockToken, packageName, serviceAccount } from './googlePlayTestUtils';
|
||||
import { createMockLogger } from '../../../../__tests__/utils/logger';
|
||||
import { GooglePlayAuthRequestError } from '../GooglePlayAuthClient';
|
||||
import { GooglePlayApiError, GooglePlayClient } from '../GooglePlayClient';
|
||||
import { GooglePlayUtils } from '../GooglePlayUtils';
|
||||
|
||||
jest.unmock('node-fetch');
|
||||
beforeEach(() => nock.disableNetConnect());
|
||||
afterEach(() => {
|
||||
const pending = nock.pendingMocks();
|
||||
nock.cleanAll();
|
||||
nock.enableNetConnect();
|
||||
expect(pending).toEqual([]);
|
||||
});
|
||||
function commit({
|
||||
signal,
|
||||
changesNotSentForReview = false,
|
||||
}: {
|
||||
signal?: AbortSignal;
|
||||
changesNotSentForReview?: boolean;
|
||||
} = {}) {
|
||||
return GooglePlayUtils.commitEditAsync(new GooglePlayClient(serviceAccount), {
|
||||
packageName,
|
||||
editId: 'edit',
|
||||
changesNotSentForReview,
|
||||
logger: createMockLogger(),
|
||||
signal,
|
||||
});
|
||||
}
|
||||
it.each([
|
||||
[false, {}],
|
||||
[true, { changesNotSentForReview: 'true' }],
|
||||
] as const)(
|
||||
'commits with changesNotSentForReview=%s without a failed first request',
|
||||
async (changesNotSentForReview, query) => {
|
||||
mockToken();
|
||||
api().post(`${editPath}:commit`).query(query).reply(200, { id: 'edit' });
|
||||
await expect(commit({ changesNotSentForReview })).resolves.toBeUndefined();
|
||||
}
|
||||
);
|
||||
it.each([
|
||||
[
|
||||
true,
|
||||
{ changesNotSentForReview: 'true' },
|
||||
'The query parameter changesNotSentForReview must not be set',
|
||||
{},
|
||||
],
|
||||
[
|
||||
false,
|
||||
{},
|
||||
'Please set the query parameter changesNotSentForReview to true',
|
||||
{ changesNotSentForReview: 'true' },
|
||||
],
|
||||
] as const)(
|
||||
'retries the rejected review setting (requested=%s)',
|
||||
async (changesNotSentForReview, initialQuery, message, retryQuery) => {
|
||||
mockToken();
|
||||
api().post(`${editPath}:commit`).query(initialQuery).reply(400, { error: { message } });
|
||||
api().post(`${editPath}:commit`).query(retryQuery).reply(200, { id: 'edit' });
|
||||
await expect(commit({ changesNotSentForReview })).resolves.toBeUndefined();
|
||||
}
|
||||
);
|
||||
it.each([408, 429, 503])('does not retry an uncertain HTTP %s commit', async status => {
|
||||
mockToken();
|
||||
api().post(`${editPath}:commit`).query(true).reply(status);
|
||||
await expect(commit()).rejects.toMatchObject({ cause: expect.objectContaining({ status }) });
|
||||
});
|
||||
it('preserves cancellation before commit is sent', async () => {
|
||||
const controller = new AbortController();
|
||||
const reason = new Error('cancelled before commit');
|
||||
controller.abort(reason);
|
||||
await expect(commit({ signal: controller.signal })).rejects.toBe(reason);
|
||||
});
|
||||
it('preserves OAuth rejection before commit is sent', async () => {
|
||||
nock('https://oauth2.googleapis.com').post('/token').reply(400, { error: 'invalid_grant' });
|
||||
await expect(commit()).rejects.toBeInstanceOf(GooglePlayAuthRequestError);
|
||||
});
|
||||
it.each([
|
||||
[404, 'Package not found', 'EAS_GOOGLE_PLAY_FIRST_UPLOAD'],
|
||||
[403, 'Version code 144 has already been used', 'EAS_GOOGLE_PLAY_VERSION_CODE_USED'],
|
||||
[403, 'The caller does not have permission', 'EAS_GOOGLE_PLAY_PERMISSION_DENIED'],
|
||||
[403, 'privacy policy required', 'EAS_GOOGLE_PLAY_PRIVACY_POLICY_REQUIRED'],
|
||||
[403, 'wrong signing key', 'EAS_GOOGLE_PLAY_REQUEST_FAILED'],
|
||||
[400, 'privacy policy required', 'EAS_GOOGLE_PLAY_PRIVACY_POLICY_REQUIRED'],
|
||||
[400, 'Only releases with status draft may be created on draft app', 'EAS_GOOGLE_PLAY_DRAFT_APP'],
|
||||
[409, 'edit invalid', 'EAS_GOOGLE_PLAY_EDIT_INVALID'],
|
||||
[400, 'unknown track', 'EAS_GOOGLE_PLAY_INVALID_RELEASE'],
|
||||
] as const)('keeps the Google error behind %s %s', (status, message, code) => {
|
||||
const original = new GooglePlayApiError(status, message, []);
|
||||
const mapped = GooglePlayUtils.mapGooglePlayError(original);
|
||||
expect(mapped).toBeInstanceOf(UserError);
|
||||
expect(mapped).toMatchObject({
|
||||
errorCode: code,
|
||||
message: expect.stringContaining(`Google Play said: ${message}`),
|
||||
cause: original,
|
||||
});
|
||||
});
|
||||
it('maps a rejected OAuth key to a credential error', () => {
|
||||
const original = new GooglePlayAuthRequestError(400, 'invalid_grant');
|
||||
expect(GooglePlayUtils.mapGooglePlayError(original)).toMatchObject({
|
||||
errorCode: 'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
|
||||
cause: original,
|
||||
});
|
||||
});
|
||||
it.each([408, 429, 500, 503])('classifies temporary HTTP %s errors as system errors', status => {
|
||||
for (const original of [
|
||||
new GooglePlayApiError(status, 'temporary failure', []),
|
||||
new GooglePlayAuthRequestError(status, 'temporarily_unavailable'),
|
||||
]) {
|
||||
const mapped = GooglePlayUtils.mapGooglePlayError(original);
|
||||
expect(mapped).toBeInstanceOf(SystemError);
|
||||
expect(mapped).toMatchObject({ cause: original });
|
||||
expect((mapped as Error).message).not.toContain('settings');
|
||||
}
|
||||
});
|
||||
it('keeps non-Google errors unchanged', () => {
|
||||
const error = new SystemError('file failure');
|
||||
expect(GooglePlayUtils.mapGooglePlayError(error)).toBe(error);
|
||||
});
|
||||
@@ -0,0 +1,366 @@
|
||||
import nock from 'nock';
|
||||
import { truncateSync } from 'node:fs';
|
||||
import fs from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
import { api, editPath, mockToken, packageName, serviceAccount } from './googlePlayTestUtils';
|
||||
import { GooglePlayClient } from '../GooglePlayClient';
|
||||
import { GooglePlayUtils } from '../GooglePlayUtils';
|
||||
|
||||
jest.unmock('node-fetch');
|
||||
jest.unmock('fs');
|
||||
jest.unmock('node:fs');
|
||||
jest.unmock('fs/promises');
|
||||
jest.unmock('node:fs/promises');
|
||||
jest.mock('promise-retry', () => {
|
||||
const promiseRetry = jest.requireActual('promise-retry');
|
||||
return (fn: Parameters<typeof promiseRetry>[0], options: object) =>
|
||||
promiseRetry(fn, { ...options, minTimeout: 0, maxTimeout: 0 });
|
||||
});
|
||||
|
||||
let directory: string;
|
||||
let artifactPath: string;
|
||||
let client: GooglePlayClient;
|
||||
const session = '/upload/session';
|
||||
const chunkSize = 8 * 1024 * 1024;
|
||||
beforeEach(async () => {
|
||||
nock.disableNetConnect();
|
||||
directory = await fs.mkdtemp(path.join(os.tmpdir(), 'play-client-test-'));
|
||||
artifactPath = path.join(directory, 'binary');
|
||||
await fs.writeFile(artifactPath, Buffer.alloc(12));
|
||||
client = new GooglePlayClient(serviceAccount);
|
||||
});
|
||||
afterEach(async () => {
|
||||
const pending = nock.pendingMocks();
|
||||
nock.cleanAll();
|
||||
nock.enableNetConnect();
|
||||
jest.restoreAllMocks();
|
||||
await fs.rm(directory, { recursive: true, force: true });
|
||||
expect(pending).toEqual([]);
|
||||
});
|
||||
function mockStart(location = `https://androidpublisher.googleapis.com${session}`): void {
|
||||
api()
|
||||
.post(`/upload${editPath}/apks`)
|
||||
.query({ uploadType: 'resumable' })
|
||||
.reply(200, '', { Location: location });
|
||||
}
|
||||
function upload(signal?: AbortSignal, onProgress = jest.fn()) {
|
||||
return GooglePlayUtils.uploadApplicationAsync(client, {
|
||||
packageName,
|
||||
editId: 'edit',
|
||||
artifactPath,
|
||||
artifactType: 'apk',
|
||||
signal,
|
||||
onProgress,
|
||||
}).then(result => result.versionCode);
|
||||
}
|
||||
function uploadApi(): nock.Scope {
|
||||
return nock('https://androidpublisher.googleapis.com', { badheaders: ['authorization'] });
|
||||
}
|
||||
|
||||
function status(total = 12): nock.Interceptor {
|
||||
return uploadApi()
|
||||
.put(session)
|
||||
.matchHeader('content-length', '0')
|
||||
.matchHeader('content-range', `bytes */${total}`);
|
||||
}
|
||||
|
||||
it('uploads aligned chunks and reports server-confirmed progress', async () => {
|
||||
await fs.writeFile(artifactPath, Buffer.alloc(chunkSize + 12));
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi()
|
||||
.put(session)
|
||||
.matchHeader('content-length', String(chunkSize))
|
||||
.matchHeader('content-range', `bytes 0-${chunkSize - 1}/${chunkSize + 12}`)
|
||||
.reply(308, '', { Range: `bytes=0-${chunkSize - 1}` });
|
||||
uploadApi()
|
||||
.put(session)
|
||||
.matchHeader('content-length', '12')
|
||||
.matchHeader('content-range', `bytes ${chunkSize}-${chunkSize + 11}/${chunkSize + 12}`)
|
||||
.reply(200, { versionCode: 42 });
|
||||
const progress = jest.fn();
|
||||
await expect(upload(undefined, progress)).resolves.toBe(42);
|
||||
expect(progress.mock.calls).toEqual([
|
||||
[0, chunkSize + 12],
|
||||
[chunkSize, chunkSize + 12],
|
||||
[chunkSize + 12, chunkSize + 12],
|
||||
]);
|
||||
});
|
||||
|
||||
it.each(['network', 429, 503])(
|
||||
'recovers the accepted offset after a %s interruption',
|
||||
async failure => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
const interrupted = uploadApi().put(session).matchHeader('content-range', 'bytes 0-11/12');
|
||||
if (failure === 'network') {
|
||||
interrupted.replyWithError('connection reset');
|
||||
} else {
|
||||
interrupted.reply(failure as number, { error: { message: 'retry' } });
|
||||
}
|
||||
status().reply(308, '', { Range: 'bytes=0-5' });
|
||||
uploadApi()
|
||||
.put(session)
|
||||
.matchHeader('content-range', 'bytes 6-11/12')
|
||||
.reply(200, { versionCode: 42 });
|
||||
const progress = jest.fn();
|
||||
await expect(upload(undefined, progress)).resolves.toBe(42);
|
||||
expect(progress.mock.calls).toEqual([
|
||||
[0, 12],
|
||||
[6, 12],
|
||||
[12, 12],
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
||||
it('recovers a completed upload when the final upload response is lost', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi()
|
||||
.put(session)
|
||||
.matchHeader('content-length', '12')
|
||||
.replyWithError('lost final response');
|
||||
status().reply(200, { versionCode: 42 });
|
||||
await expect(upload()).resolves.toBe(42);
|
||||
});
|
||||
|
||||
it('recovers completion after a damaged response body', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi().put(session).matchHeader('content-length', '12').reply(200, '{invalid JSON');
|
||||
status().reply(200, { versionCode: 42 });
|
||||
await expect(upload()).resolves.toBe(42);
|
||||
});
|
||||
|
||||
it('sanitizes a malformed session URL', async () => {
|
||||
mockToken();
|
||||
mockStart('INVALID SECRET URL');
|
||||
const error = await upload().catch(error => error);
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect(String(error)).toContain('invalid upload URL');
|
||||
expect(JSON.stringify(error)).not.toContain('SECRET');
|
||||
expect(String(error)).not.toContain('SECRET');
|
||||
});
|
||||
|
||||
it('retries status recovery after a transient Google error', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi().put(session).matchHeader('content-length', '12').reply(503);
|
||||
status().reply(429);
|
||||
status().reply(308);
|
||||
uploadApi().put(session).matchHeader('content-length', '12').reply(200, { versionCode: 42 });
|
||||
await expect(upload()).resolves.toBe(42);
|
||||
});
|
||||
|
||||
it.each([404, 410])('restarts an expired %s upload session within the same edit', async expired => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi().put(session).reply(expired);
|
||||
mockStart();
|
||||
uploadApi().put(session).reply(200, { versionCode: 42 });
|
||||
const progress = jest.fn();
|
||||
await expect(upload(undefined, progress)).resolves.toBe(42);
|
||||
expect(progress.mock.calls).toEqual([
|
||||
[0, 12],
|
||||
[0, 12],
|
||||
[12, 12],
|
||||
]);
|
||||
});
|
||||
|
||||
it('stops after the upload retry limit', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi().put(session).matchHeader('content-length', '12').reply(503);
|
||||
status().times(5).reply(503);
|
||||
await expect(upload()).rejects.toThrow('HTTP 503');
|
||||
});
|
||||
|
||||
it('stops after the upload session restart limit', async () => {
|
||||
mockToken();
|
||||
for (let i = 0; i < 3; i++) {
|
||||
mockStart();
|
||||
uploadApi().put(session).reply(410);
|
||||
}
|
||||
await expect(upload()).rejects.toThrow('HTTP 410');
|
||||
});
|
||||
|
||||
it('cancels before upload and does not request credentials', async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
await expect(upload(controller.signal)).rejects.toBe(controller.signal.reason);
|
||||
});
|
||||
|
||||
it('cancels between chunks without sending the next chunk', async () => {
|
||||
await fs.writeFile(artifactPath, Buffer.alloc(chunkSize + 12));
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi()
|
||||
.put(session)
|
||||
.reply(308, '', { Range: `bytes=0-${chunkSize - 1}` });
|
||||
const controller = new AbortController();
|
||||
const reason = new Error('Upload cancelled');
|
||||
await expect(
|
||||
upload(
|
||||
controller.signal,
|
||||
jest.fn((bytes: number) => {
|
||||
if (bytes > 0) {
|
||||
controller.abort(reason);
|
||||
}
|
||||
})
|
||||
)
|
||||
).rejects.toBe(reason);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'https://attacker.example/upload?secret=signed',
|
||||
'http://androidpublisher.googleapis.com/upload',
|
||||
'https://androidpublisher.googleapis.com.attacker.example/upload',
|
||||
'https://user:[email protected]/upload',
|
||||
])('rejects an unsafe session URL: %s', async location => {
|
||||
mockToken();
|
||||
mockStart(location);
|
||||
await expect(upload()).rejects.toThrow('unsafe upload URL');
|
||||
});
|
||||
|
||||
it('does not follow an upload redirect', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi().put(session).reply(302, '', { Location: 'https://attacker.example/upload' });
|
||||
await expect(upload()).rejects.toThrow('HTTP 302');
|
||||
});
|
||||
|
||||
it.each(['bytes=0-100', 'invalid', 'bytes=5-8'])(
|
||||
'rejects an invalid acknowledged range: %s',
|
||||
async range => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi().put(session).reply(308, '', { Range: range });
|
||||
await expect(upload()).rejects.toThrow('invalid upload range');
|
||||
}
|
||||
);
|
||||
|
||||
it('stops when uploads and status checks repeatedly confirm no progress', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi().put(session).matchHeader('content-length', '12').times(6).reply(308);
|
||||
status().times(5).reply(308);
|
||||
await expect(upload()).rejects.toThrow('confirmed 0 of 12 bytes');
|
||||
});
|
||||
|
||||
it('preserves Google upload error details', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
uploadApi()
|
||||
.put(session)
|
||||
.reply(403, {
|
||||
error: {
|
||||
message: 'Version code has already been used.',
|
||||
errors: [{ reason: 'apkNotificationMessageKeyUpgradeVersionConflict' }],
|
||||
},
|
||||
});
|
||||
await expect(upload()).rejects.toMatchObject({
|
||||
status: 403,
|
||||
apiMessage: 'Version code has already been used.',
|
||||
reasons: ['apkNotificationMessageKeyUpgradeVersionConflict'],
|
||||
});
|
||||
});
|
||||
|
||||
it('resets the retry budget after confirmed progress', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
for (let offset = 0; offset < 6; offset++) {
|
||||
uploadApi().put(session).matchHeader('content-range', `bytes ${offset}-11/12`).reply(503);
|
||||
status().reply(308, '', { Range: `bytes=0-${offset}` });
|
||||
}
|
||||
uploadApi()
|
||||
.put(session)
|
||||
.matchHeader('content-range', 'bytes 6-11/12')
|
||||
.reply(200, { versionCode: 42 });
|
||||
await expect(upload()).resolves.toBe(42);
|
||||
});
|
||||
|
||||
it('retries a network failure during session creation', async () => {
|
||||
mockToken();
|
||||
api()
|
||||
.post(`/upload${editPath}/apks`)
|
||||
.query({ uploadType: 'resumable' })
|
||||
.replyWithError('connection reset');
|
||||
mockStart();
|
||||
uploadApi().put(session).reply(200, { versionCode: 42 });
|
||||
await expect(upload()).resolves.toBe(42);
|
||||
});
|
||||
|
||||
it.each(['session', 'chunk', 'body', 'status'])('recovers a stalled %s request', async stalled => {
|
||||
const timeout = AbortSignal.timeout.bind(AbortSignal);
|
||||
const guard = timeout(1500);
|
||||
jest.spyOn(AbortSignal, 'timeout').mockImplementation(() => timeout(100));
|
||||
mockToken();
|
||||
if (stalled === 'session') {
|
||||
api()
|
||||
.post(`/upload${editPath}/apks`)
|
||||
.query({ uploadType: 'resumable' })
|
||||
.delayConnection(300)
|
||||
.reply(200, '', { Location: `https://androidpublisher.googleapis.com${session}` });
|
||||
mockStart();
|
||||
uploadApi().put(session).reply(200, { versionCode: 42 });
|
||||
} else if (stalled === 'status') {
|
||||
mockStart();
|
||||
uploadApi().put(session).matchHeader('content-length', '12').reply(503);
|
||||
status().delayConnection(300).reply(308);
|
||||
status().reply(200, { versionCode: 42 });
|
||||
} else {
|
||||
mockStart();
|
||||
const request = uploadApi().put(session).matchHeader('content-length', '12');
|
||||
if (stalled === 'chunk') {
|
||||
request.delayConnection(300);
|
||||
} else {
|
||||
request.delayBody(300);
|
||||
}
|
||||
request.reply(200, { versionCode: 42 });
|
||||
status().reply(200, { versionCode: 42 });
|
||||
}
|
||||
await expect(upload(guard)).resolves.toBe(42);
|
||||
});
|
||||
|
||||
it('stops when the binary becomes shorter during upload', async () => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
await expect(
|
||||
upload(
|
||||
undefined,
|
||||
jest.fn(() => truncateSync(artifactPath, 0))
|
||||
)
|
||||
).rejects.toThrow('expected 12 bytes at offset 0, got 0');
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ completes: true, finalResponse: 'lost' },
|
||||
{ completes: false, finalResponse: 'lost' },
|
||||
{ completes: true, finalResponse: 'stored' },
|
||||
{ completes: false, finalResponse: 'stored' },
|
||||
])(
|
||||
'bounds completion checks (completes: $completes, final response: $finalResponse)',
|
||||
async ({ completes, finalResponse }) => {
|
||||
mockToken();
|
||||
mockStart();
|
||||
const finalChunk = uploadApi().put(session).matchHeader('content-length', '12');
|
||||
if (finalResponse === 'lost') {
|
||||
finalChunk.replyWithError('lost final response');
|
||||
} else {
|
||||
finalChunk.reply(308, '', { Range: 'bytes=0-11' });
|
||||
}
|
||||
status()
|
||||
.times(completes ? 1 : 5)
|
||||
.reply(308, '', { Range: 'bytes=0-11' });
|
||||
if (completes) {
|
||||
status().reply(200, { versionCode: 42 });
|
||||
await expect(upload()).resolves.toBe(42);
|
||||
} else {
|
||||
await expect(upload()).rejects.toThrow(
|
||||
'Google stored all 12 bytes but has not completed the upload.'
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
import nock from 'nock';
|
||||
import { generateKeyPairSync } from 'node:crypto';
|
||||
|
||||
export const packageName = 'dev.expo.submitfixture';
|
||||
export const editPath = `/androidpublisher/v3/applications/${packageName}/edits/edit`;
|
||||
export const serviceAccount = {
|
||||
client_email: '[email protected]',
|
||||
private_key_id: 'test-key',
|
||||
private_key: generateKeyPairSync('rsa', { modulusLength: 2048 }).privateKey,
|
||||
};
|
||||
export const api = (): nock.Scope =>
|
||||
nock('https://androidpublisher.googleapis.com', {
|
||||
reqheaders: { authorization: 'Bearer test-access-token' },
|
||||
});
|
||||
export function mockToken(times = 1): nock.Scope {
|
||||
return nock('https://oauth2.googleapis.com').post('/token').times(times).reply(200, {
|
||||
access_token: 'test-access-token',
|
||||
expires_in: 3600,
|
||||
token_type: 'Bearer',
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type bunyan } from '@expo/logger';
|
||||
import { asyncResult } from '@expo/results';
|
||||
import { BuildRuntimePlatform, type BuildStepEnv } from '@expo/steps';
|
||||
import spawn from '@expo/turtle-spawn';
|
||||
import spawn, { type SpawnOptions } from '@expo/turtle-spawn';
|
||||
import { graphql } from 'gql.tada';
|
||||
import fetch from 'node-fetch';
|
||||
import { createWriteStream } from 'node:fs';
|
||||
@@ -11,6 +11,7 @@ import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
import { type CustomBuildContext } from '../../customBuildContext';
|
||||
import { killProcessGroup } from '../../utils/processes';
|
||||
|
||||
const PREVIEW_INTERVAL_MS = 60_000;
|
||||
const PREVIEW_MAX_DIMENSION = 320;
|
||||
@@ -146,18 +147,47 @@ export function startDeviceRunSessionPreview({
|
||||
export async function ensureMacosPreviewEncoderInstalledAsync({
|
||||
env,
|
||||
logger,
|
||||
signal,
|
||||
}: {
|
||||
env: BuildStepEnv;
|
||||
logger: bunyan;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<void> {
|
||||
if ((await asyncResult(spawn('cwebp', ['-version'], { env, stdio: 'pipe' }))).ok) {
|
||||
const probe = await asyncResult(
|
||||
runEncoderCommandAsync('cwebp', ['-version'], { env, stdio: 'pipe' }, signal)
|
||||
);
|
||||
if (probe.ok) {
|
||||
return;
|
||||
}
|
||||
signal?.throwIfAborted();
|
||||
logger.info('Installing webp with Homebrew for the session preview.');
|
||||
await spawn('brew', ['install', 'webp'], {
|
||||
env: { ...env, HOMEBREW_NO_AUTO_UPDATE: '1' },
|
||||
logger,
|
||||
});
|
||||
await runEncoderCommandAsync(
|
||||
'brew',
|
||||
['install', 'webp'],
|
||||
{ env: { ...env, HOMEBREW_NO_AUTO_UPDATE: '1' }, logger },
|
||||
signal
|
||||
);
|
||||
}
|
||||
|
||||
async function runEncoderCommandAsync(
|
||||
command: string,
|
||||
args: string[],
|
||||
options: SpawnOptions,
|
||||
signal?: AbortSignal
|
||||
): Promise<void> {
|
||||
signal?.throwIfAborted();
|
||||
const task = spawn(command, args, { ...options, detached: true });
|
||||
const abort = (): void => killProcessGroup(task.child, 'SIGKILL');
|
||||
signal?.addEventListener('abort', abort, { once: true });
|
||||
if (signal?.aborted) {
|
||||
abort();
|
||||
}
|
||||
try {
|
||||
await task;
|
||||
signal?.throwIfAborted();
|
||||
} finally {
|
||||
signal?.removeEventListener('abort', abort);
|
||||
}
|
||||
}
|
||||
|
||||
export async function captureDeviceRunSessionPreviewAsync({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SystemError, UserError } from '@expo/eas-build-job';
|
||||
import { BuildPhaseResult, SystemError, UserError } from '@expo/eas-build-job';
|
||||
import type { bunyan } from '@expo/logger';
|
||||
import { BuildRuntimePlatform, type BuildStepEnv } from '@expo/steps';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
@@ -45,6 +45,7 @@ import {
|
||||
SERVE_SIM_STOP_GRACE_PERIOD_MS,
|
||||
} from './IosSimulatorRecordingUtils';
|
||||
import { SERVE_SIM_STATE_DIR, readServeSimServersAsync } from './serveSimMetricsRecorder';
|
||||
import { startLogPhase } from '../../utils/logPhase';
|
||||
|
||||
const WEB_PREVIEW_HOST = '127.0.0.1';
|
||||
const SERVE_SIM_PACKAGE_NAME = '@expo/serve-sim';
|
||||
@@ -273,7 +274,43 @@ type AndroidSessionRecording = {
|
||||
env: BuildStepEnv;
|
||||
};
|
||||
|
||||
type DeviceSessionHostOptions = {
|
||||
runtimePlatform: BuildRuntimePlatform;
|
||||
env: BuildStepEnv;
|
||||
logger: bunyan;
|
||||
timeoutMs: number;
|
||||
separateLogPhase?: boolean;
|
||||
packageVersion?: string;
|
||||
networkCapture?: boolean;
|
||||
networkCaptureFields?: string[];
|
||||
} & ServeSimLaunchOptions;
|
||||
|
||||
export async function startDeviceSessionHostAsync(
|
||||
ctx: CustomBuildContext,
|
||||
options: DeviceSessionHostOptions
|
||||
): Promise<DeviceSessionHost> {
|
||||
if (!options.separateLogPhase) {
|
||||
return await startDeviceSessionHostInternalAsync(ctx, options, () => {}, options.logger);
|
||||
}
|
||||
const phase = startLogPhase(options.logger, 'Simulator preview');
|
||||
let ready = false;
|
||||
try {
|
||||
const host = await startDeviceSessionHostInternalAsync(
|
||||
ctx,
|
||||
{ ...options, logger: phase.logger },
|
||||
successful =>
|
||||
phase.end(ready && successful ? BuildPhaseResult.SUCCESS : BuildPhaseResult.FAIL),
|
||||
options.logger
|
||||
);
|
||||
ready = true;
|
||||
return host;
|
||||
} catch (error) {
|
||||
phase.end(BuildPhaseResult.FAIL);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function startDeviceSessionHostInternalAsync(
|
||||
ctx: CustomBuildContext,
|
||||
{
|
||||
runtimePlatform,
|
||||
@@ -286,15 +323,9 @@ export async function startDeviceSessionHostAsync(
|
||||
openUrl,
|
||||
networkCapture = false,
|
||||
networkCaptureFields = [],
|
||||
}: {
|
||||
runtimePlatform: BuildRuntimePlatform;
|
||||
env: BuildStepEnv;
|
||||
logger: bunyan;
|
||||
timeoutMs: number;
|
||||
packageVersion?: string;
|
||||
networkCapture?: boolean;
|
||||
networkCaptureFields?: string[];
|
||||
} & ServeSimLaunchOptions
|
||||
}: DeviceSessionHostOptions,
|
||||
onFinished: (successful: boolean) => void,
|
||||
artifactLogger: bunyan
|
||||
): Promise<DeviceSessionHost> {
|
||||
const isAndroid = runtimePlatform === BuildRuntimePlatform.LINUX;
|
||||
// Unreachable from the step functions, which reject a non-Darwin launch while parsing.
|
||||
@@ -355,9 +386,14 @@ export async function startDeviceSessionHostAsync(
|
||||
logger.info(
|
||||
`Launching ${packageSpec} on ${WEB_PREVIEW_HOST}:${port} via ${previewExec.command}.`
|
||||
);
|
||||
// Redact these credentials before forwarding process output to build logs.
|
||||
const secrets = [
|
||||
...turnArgs.filter((_, index) => turnArgs[index - 1] === '--turn-credential'),
|
||||
...(recording ? [recording.controlToken] : []),
|
||||
];
|
||||
const screenshots = await startDeviceRunSessionScreenshotsAsync(ctx, {
|
||||
deviceRunSessionId: getDeviceRunSessionIdOrThrow(env),
|
||||
logger,
|
||||
logger: artifactLogger,
|
||||
});
|
||||
let previewServer: DetachedProcessHandle;
|
||||
try {
|
||||
@@ -373,6 +409,8 @@ export async function startDeviceSessionHostAsync(
|
||||
stopGracePeriodMs: recording
|
||||
? RECORDING_STOP_GRACE_PERIOD_MS
|
||||
: SERVE_SIM_STOP_GRACE_PERIOD_MS,
|
||||
logger,
|
||||
secrets,
|
||||
});
|
||||
} catch (error) {
|
||||
// Nothing was spawned, so nothing can still write into the directory.
|
||||
@@ -385,6 +423,9 @@ export async function startDeviceSessionHostAsync(
|
||||
let finishTask: Promise<void> | null = null;
|
||||
let hostReady = false;
|
||||
let sessionPreview: ReturnType<typeof startDeviceRunSessionPreview> | null = null;
|
||||
const previewSetupController = new AbortController();
|
||||
let previewSetupTask: Promise<void> | undefined;
|
||||
let previewFailed = false;
|
||||
|
||||
const host: DeviceSessionHost = {
|
||||
openPreviewAsync({ baseDomain }) {
|
||||
@@ -413,6 +454,7 @@ export async function startDeviceSessionHostAsync(
|
||||
throw new SystemError('Session host finalized while the preview was opening.');
|
||||
}
|
||||
let closeTask: Promise<void> | null = null;
|
||||
previewFailed = false;
|
||||
return {
|
||||
previewPageUrl,
|
||||
apiUrl: tunnel.url,
|
||||
@@ -433,6 +475,7 @@ export async function startDeviceSessionHostAsync(
|
||||
previewTask = opening;
|
||||
// A failed tunnel may be retried without restarting capture.
|
||||
void opening.catch(() => {
|
||||
previewFailed = true;
|
||||
if (previewTask === opening) {
|
||||
previewTask = null;
|
||||
}
|
||||
@@ -442,7 +485,11 @@ export async function startDeviceSessionHostAsync(
|
||||
finishAsync() {
|
||||
return (finishTask ??= finishDeviceSessionHostAsync(ctx, {
|
||||
previewTask,
|
||||
stopSessionPreviewAsync: async () => await sessionPreview?.stopAsync(),
|
||||
stopSessionPreviewAsync: async () => {
|
||||
previewSetupController.abort();
|
||||
await previewSetupTask;
|
||||
await sessionPreview?.stopAsync();
|
||||
},
|
||||
previewServer,
|
||||
screenshots,
|
||||
serverName,
|
||||
@@ -450,6 +497,11 @@ export async function startDeviceSessionHostAsync(
|
||||
// A host that never answered /readyz has nothing to finalize or upload.
|
||||
recording: hostReady ? recording : null,
|
||||
logger,
|
||||
artifactLogger,
|
||||
onStopped: successful => onFinished(successful && !previewFailed),
|
||||
}).catch(err => {
|
||||
artifactLogger.warn({ err }, 'Could not finish the simulator preview.');
|
||||
onFinished(false);
|
||||
}));
|
||||
},
|
||||
};
|
||||
@@ -472,13 +524,18 @@ export async function startDeviceSessionHostAsync(
|
||||
'report it if it repeats.'
|
||||
);
|
||||
}
|
||||
secrets.push(previewToken);
|
||||
IosSimulatorRecordingUtils.useServeSimPackage(packageSpec);
|
||||
}
|
||||
// Android installed FFmpeg before launching the host. The optional thumbnail must not delay
|
||||
// readiness on macOS, so it starts after its encoder is installed there.
|
||||
void (async () => {
|
||||
previewSetupTask = (async () => {
|
||||
if (!isAndroid) {
|
||||
await ensureMacosPreviewEncoderInstalledAsync({ env, logger });
|
||||
await ensureMacosPreviewEncoderInstalledAsync({
|
||||
env,
|
||||
logger,
|
||||
signal: previewSetupController.signal,
|
||||
});
|
||||
}
|
||||
if (!finishTask) {
|
||||
sessionPreview = startDeviceRunSessionPreview({
|
||||
@@ -495,7 +552,9 @@ export async function startDeviceSessionHostAsync(
|
||||
});
|
||||
}
|
||||
})().catch(err => {
|
||||
logger.warn({ err }, 'Could not start refreshing the session preview.');
|
||||
if (!previewSetupController.signal.aborted) {
|
||||
logger.warn({ err }, 'Could not start refreshing the session preview.');
|
||||
}
|
||||
});
|
||||
return host;
|
||||
} catch (error) {
|
||||
@@ -515,6 +574,8 @@ async function finishDeviceSessionHostAsync(
|
||||
port,
|
||||
recording,
|
||||
logger,
|
||||
artifactLogger,
|
||||
onStopped,
|
||||
}: {
|
||||
previewTask: Promise<DeviceWebPreview> | null;
|
||||
stopSessionPreviewAsync: () => Promise<void>;
|
||||
@@ -524,10 +585,13 @@ async function finishDeviceSessionHostAsync(
|
||||
port: number;
|
||||
recording: AndroidSessionRecording | null;
|
||||
logger: bunyan;
|
||||
artifactLogger: bunyan;
|
||||
onStopped: (successful: boolean) => void;
|
||||
}
|
||||
): Promise<void> {
|
||||
// Stop capturing before the host stops, so the last thumbnail shows the session, not shutdown.
|
||||
await stopSessionPreviewAsync();
|
||||
const hostExited = previewServer.getExitError() !== undefined;
|
||||
// Native ngrok operations have no scoped cancellation. Retire a late listener too.
|
||||
const retirePreview = withDeviceRunSessionTimeoutAsync(
|
||||
{ name: 'Preview tunnel retirement', timeoutMs: 5_000 },
|
||||
@@ -536,9 +600,13 @@ async function finishDeviceSessionHostAsync(
|
||||
const preview = await previewTask?.catch(() => null);
|
||||
await preview?.closeAsync();
|
||||
}
|
||||
).catch(err => {
|
||||
logger.warn({ err }, `Could not close the ${serverName} preview tunnel within its deadline.`);
|
||||
});
|
||||
).then(
|
||||
() => true,
|
||||
err => {
|
||||
logger.warn({ err }, `Could not close the ${serverName} preview tunnel within its deadline.`);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
let finalization: AndroidRecordingFinalization | null = null;
|
||||
if (recording) {
|
||||
// stopAsync signals the whole process group, including capture's encoder.
|
||||
@@ -559,17 +627,21 @@ async function finishDeviceSessionHostAsync(
|
||||
} catch (err) {
|
||||
logger.warn({ err }, `Could not stop the ${serverName} session host.`);
|
||||
}
|
||||
await retirePreview;
|
||||
const previewRetired = await retirePreview;
|
||||
onStopped(hostStopped && !hostExited && previewRetired);
|
||||
await screenshots.finishAsync(hostStopped);
|
||||
// A Hub that never recorded has logged its reason and left nothing to upload.
|
||||
const captured = finalization !== 'not-recording';
|
||||
let uploaded = false;
|
||||
if (recording && captured && hostStopped) {
|
||||
uploaded = await uploadFinishedAndroidRecordingAsync(ctx, { recording, logger });
|
||||
uploaded = await uploadFinishedAndroidRecordingAsync(ctx, {
|
||||
recording,
|
||||
logger: artifactLogger,
|
||||
});
|
||||
}
|
||||
if (recording && captured && (finalization === 'failed' || !uploaded)) {
|
||||
// The Hub reports capture failures on stderr; the stop route answers with only a summary.
|
||||
logger.warn(
|
||||
artifactLogger.warn(
|
||||
{ hostOutput: previewServer.getOutput().slice(-HOST_OUTPUT_TAIL_CHARS) || '<empty>' },
|
||||
'Session host output around the recording failure.'
|
||||
);
|
||||
|
||||
@@ -191,12 +191,14 @@ export async function startChiselServerAsync({
|
||||
controlPort,
|
||||
authfilePath,
|
||||
env,
|
||||
logger,
|
||||
signal,
|
||||
}: {
|
||||
chiselPath: string;
|
||||
controlPort: number;
|
||||
authfilePath: string;
|
||||
env: BuildStepEnv;
|
||||
logger: bunyan;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<{ process: DetachedProcessHandle; fingerprint: string }> {
|
||||
const server = spawnDetached({
|
||||
@@ -244,7 +246,11 @@ export async function startChiselServerAsync({
|
||||
}`
|
||||
);
|
||||
} catch (error) {
|
||||
await server.stopAsync();
|
||||
await server
|
||||
.stopAsync()
|
||||
.catch(err =>
|
||||
logger.warn({ err }, 'Could not stop the reverse tunnel server after it failed to start.')
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { type bunyan } from '@expo/logger';
|
||||
import { type BuildStepEnv } from '@expo/steps';
|
||||
import spawn from '@expo/turtle-spawn';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import { killProcessGroup } from '../../utils/processes';
|
||||
|
||||
export async function preparePreinstalledWdaAsync({
|
||||
runtimeIdentifier,
|
||||
appiumHome,
|
||||
appiumBinPath,
|
||||
appiumEnv,
|
||||
logger,
|
||||
}: {
|
||||
runtimeIdentifier: string | undefined;
|
||||
appiumHome: string;
|
||||
appiumBinPath: string;
|
||||
appiumEnv: BuildStepEnv;
|
||||
logger: bunyan;
|
||||
}): Promise<Record<string, unknown>> {
|
||||
const iosMajor = /^com\.apple\.CoreSimulator\.SimRuntime\.iOS-(\d+)(?:-|$)/.exec(
|
||||
runtimeIdentifier ?? ''
|
||||
)?.[1];
|
||||
// WDA v13+ supports preinstalled launch on iOS 17 and newer.
|
||||
if (!iosMajor || Number(iosMajor) < 17) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const outdir = path.join(appiumHome, 'preinstalled-wda');
|
||||
const runner = path.join(outdir, 'WebDriverAgentRunner-Runner.app');
|
||||
try {
|
||||
// The driver selects the release matching its installed WDA and the host architecture.
|
||||
// Keep the Simulator runner intact; removing its XCTest frameworks breaks launch.
|
||||
const download = spawn(
|
||||
appiumBinPath,
|
||||
[
|
||||
'driver',
|
||||
'run',
|
||||
'xcuitest',
|
||||
'download-wda',
|
||||
'--',
|
||||
'--outdir',
|
||||
outdir,
|
||||
'--platform',
|
||||
'iOS',
|
||||
'--kind',
|
||||
'sim',
|
||||
],
|
||||
{ env: appiumEnv, logger, detached: true }
|
||||
);
|
||||
// Appium's downloader inherits its pipes; killing only Appium leaves spawn's
|
||||
// close event pending. Kill the owned group, then await close before cleanup.
|
||||
const timeout = setTimeout(() => killProcessGroup(download.child, 'SIGKILL'), 60_000);
|
||||
try {
|
||||
await download;
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
if (!(await fs.promises.stat(runner)).isDirectory()) {
|
||||
throw new Error('The downloaded WebDriverAgent runner is not an app directory.');
|
||||
}
|
||||
logger.info('Using preinstalled WebDriverAgent to avoid xcodebuild during session creation.');
|
||||
return {
|
||||
'appium:usePreinstalledWDA': true,
|
||||
'appium:prebuiltWDAPath': runner,
|
||||
};
|
||||
} catch (err) {
|
||||
await fs.promises.rm(outdir, { recursive: true, force: true });
|
||||
logger.warn(
|
||||
{ err },
|
||||
'Could not prepare preinstalled WebDriverAgent; using the default xcodebuild startup.'
|
||||
);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { type bunyan } from '@expo/logger';
|
||||
import { StringDecoder } from 'node:string_decoder';
|
||||
import { stripVTControlCharacters } from 'node:util';
|
||||
|
||||
const MAX_LINE_CHARS = 16 * 1024;
|
||||
const MAX_OUTPUT_CHARS = 64 * 1024;
|
||||
|
||||
export function createProcessOutput(logger?: bunyan, secrets: string[] = []) {
|
||||
const redact = (text: string): string => {
|
||||
text = stripVTControlCharacters(text);
|
||||
for (const secret of secrets.filter(Boolean)) {
|
||||
for (const value of [
|
||||
secret,
|
||||
encodeURIComponent(secret),
|
||||
JSON.stringify(secret).slice(1, -1),
|
||||
]) {
|
||||
text = text.replaceAll(value, '[REDACTED]');
|
||||
}
|
||||
}
|
||||
return text
|
||||
.replace(/([?&]token=)[^\s&#"'<>]+/gi, '$1[REDACTED]')
|
||||
.replace(/(argent:\/\/)[^\s/@]+@/gi, '$1[REDACTED]@')
|
||||
.replace(
|
||||
/("(?:[a-z_]*token|credential|password)"\s*:\s*")(?:\\.|[^"\\\r\n])*(")/gi,
|
||||
'$1[REDACTED]$2'
|
||||
)
|
||||
.replace(/(Bearer\s+)[^\s"'<>]+/gi, '$1[REDACTED]')
|
||||
.replace(
|
||||
/((?:--)?(?:token|credential|password)[=:]\s*|--(?:token|credential|password)\s+)(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^\s,&#"'<>()]+)/gi,
|
||||
'$1[REDACTED]'
|
||||
);
|
||||
};
|
||||
let output = '';
|
||||
const streams = (['stdout', 'stderr'] as const).map(source => {
|
||||
const decoder = new StringDecoder('utf8');
|
||||
let pending = '';
|
||||
let omitted = false;
|
||||
const publish = (): void => {
|
||||
const line = omitted ? '[Overlong output line omitted.]' : redact(pending);
|
||||
output = (output + line + '\n').slice(-MAX_OUTPUT_CHARS);
|
||||
logger?.info({ source }, line);
|
||||
pending = '';
|
||||
omitted = false;
|
||||
};
|
||||
const appendText = (text: string): void => {
|
||||
const parts = text.split('\n');
|
||||
for (const [index, part] of parts.entries()) {
|
||||
if (!omitted) {
|
||||
if (pending.length + part.length > MAX_LINE_CHARS) {
|
||||
pending = '';
|
||||
omitted = true;
|
||||
} else {
|
||||
pending += part;
|
||||
}
|
||||
}
|
||||
if (index < parts.length - 1) {
|
||||
pending = pending.replace(/\r$/, '');
|
||||
publish();
|
||||
}
|
||||
}
|
||||
};
|
||||
return {
|
||||
append(chunk: Buffer | string): void {
|
||||
appendText(decoder.write(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
|
||||
},
|
||||
finish(): void {
|
||||
appendText(decoder.end());
|
||||
if (pending || omitted) {
|
||||
publish();
|
||||
}
|
||||
},
|
||||
getPending: () => (omitted ? '[Overlong output line omitted.]' : redact(pending)),
|
||||
};
|
||||
});
|
||||
return {
|
||||
stdout: streams[0],
|
||||
stderr: streams[1],
|
||||
finish: () => streams.forEach(stream => stream.finish()),
|
||||
getOutput: () =>
|
||||
(
|
||||
redact(output) +
|
||||
streams
|
||||
.map(stream => stream.getPending())
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
).slice(-MAX_OUTPUT_CHARS),
|
||||
};
|
||||
}
|
||||
@@ -30,6 +30,8 @@ import { Sentry } from '../../sentry';
|
||||
import { isProcessGroupRunning } from '../../utils/processes';
|
||||
import { sleepAsync } from '../../utils/retry';
|
||||
import { turtleFetch } from '../../utils/turtleFetch';
|
||||
import { createProcessOutput } from './processOutput';
|
||||
import { withDeviceRunSessionTimeoutAsync } from './deviceRunSessionTimeout';
|
||||
|
||||
const XCODE_DEVELOPER_DIR = '/Applications/Xcode.app/Contents/Developer';
|
||||
|
||||
@@ -647,24 +649,34 @@ export function spawnDetached({
|
||||
cwd,
|
||||
env,
|
||||
stopGracePeriodMs,
|
||||
logger,
|
||||
secrets,
|
||||
}: {
|
||||
command: string;
|
||||
args: string[];
|
||||
cwd?: string;
|
||||
env: BuildStepEnv;
|
||||
stopGracePeriodMs?: number;
|
||||
logger?: bunyan;
|
||||
secrets?: string[];
|
||||
}): DetachedProcessHandle {
|
||||
const promise = spawn(command, args, {
|
||||
cwd,
|
||||
env,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
detached: true,
|
||||
ignoreStdio: true,
|
||||
});
|
||||
const output = createProcessOutput(logger, secrets);
|
||||
const outputDrained = new Promise<void>(resolve =>
|
||||
promise.child.once('close', () => {
|
||||
output.finish();
|
||||
resolve();
|
||||
})
|
||||
);
|
||||
// Observe completion without rejecting in the background. Startup callers can
|
||||
// distinguish a dead process from one that is still preparing its state file.
|
||||
let exitError: Error | undefined;
|
||||
// The spawn promise waits for stdio to close. Descendants may keep those
|
||||
// pipes open after the launcher exits, so observe the exit itself as well.
|
||||
promise.child.once('exit', (code, signal) => {
|
||||
exitError = new Error(
|
||||
signal ? `Process exited with signal ${signal}.` : `Process exited with code ${code}.`
|
||||
@@ -680,19 +692,28 @@ export function spawnDetached({
|
||||
);
|
||||
promise.child.unref();
|
||||
|
||||
let output = '';
|
||||
const appendChunk = (chunk: Buffer | string): void => {
|
||||
output += chunk.toString();
|
||||
};
|
||||
promise.child.stdout?.on('data', appendChunk);
|
||||
promise.child.stderr?.on('data', appendChunk);
|
||||
promise.child.stdout?.on('data', chunk => output.stdout.append(chunk));
|
||||
promise.child.stderr?.on('data', chunk => output.stderr.append(chunk));
|
||||
|
||||
const pid = promise.child.pid;
|
||||
return {
|
||||
pid,
|
||||
getOutput: () => output,
|
||||
getOutput: output.getOutput,
|
||||
getExitError: () => exitError,
|
||||
stopAsync: async () => await stopDetachedProcessAsync(pid, stopGracePeriodMs),
|
||||
stopAsync: async () => {
|
||||
await stopDetachedProcessAsync(pid, stopGracePeriodMs);
|
||||
try {
|
||||
await withDeviceRunSessionTimeoutAsync(
|
||||
{ name: 'Process output drain', timeoutMs: 5_000 },
|
||||
async () => await outputDrained
|
||||
);
|
||||
} catch (err) {
|
||||
promise.child.stdout?.destroy();
|
||||
promise.child.stderr?.destroy();
|
||||
output.finish();
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -826,21 +847,22 @@ export async function startNgrokTunnelAsync({
|
||||
await listener.close();
|
||||
throw new SystemError(`ngrok tunnel for ${domain} did not return a public URL.`);
|
||||
}
|
||||
let stopped = false;
|
||||
let stopTask: Promise<void> | undefined;
|
||||
return {
|
||||
url,
|
||||
subdomainId,
|
||||
stopAsync: async () => {
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
stopped = true;
|
||||
try {
|
||||
await listener.close();
|
||||
} catch (error) {
|
||||
logger.warn({ err: error }, `Could not stop ngrok tunnel ${domain}.`);
|
||||
}
|
||||
},
|
||||
stopAsync: () =>
|
||||
(stopTask ??= (async () => {
|
||||
try {
|
||||
await withDeviceRunSessionTimeoutAsync(
|
||||
{ name: 'Ngrok tunnel stop', timeoutMs: 4_000 },
|
||||
async () => await listener.close()
|
||||
);
|
||||
} catch (error) {
|
||||
logger.warn({ err: error }, `Could not stop ngrok tunnel ${domain}.`);
|
||||
throw error;
|
||||
}
|
||||
})()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BuildPhase, BuildPhaseResult, LogMarker } from '@expo/eas-build-job';
|
||||
|
||||
import { withLogPhaseAsync } from '../logPhase';
|
||||
import { startLogPhase, withLogPhaseAsync } from '../logPhase';
|
||||
|
||||
describe(withLogPhaseAsync.name, () => {
|
||||
const phaseLogger = { info: jest.fn() };
|
||||
@@ -49,3 +49,30 @@ describe(withLogPhaseAsync.name, () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps concurrent phases separate and ends each only once', () => {
|
||||
const first = { info: jest.fn() };
|
||||
const second = { info: jest.fn() };
|
||||
const logger = { child: jest.fn().mockReturnValueOnce(first).mockReturnValueOnce(second) };
|
||||
const tools = startLogPhase(logger as any, 'Argent session');
|
||||
const preview = startLogPhase(logger as any, 'Simulator preview');
|
||||
expect(logger.child.mock.calls[0][0].buildStepId).not.toBe(
|
||||
logger.child.mock.calls[1][0].buildStepId
|
||||
);
|
||||
tools.logger.info('tool output');
|
||||
preview.logger.info('preview output');
|
||||
preview.end(BuildPhaseResult.FAIL);
|
||||
preview.end(BuildPhaseResult.SUCCESS);
|
||||
expect(
|
||||
second.info.mock.calls.filter(([fields]) => fields.marker === LogMarker.END_PHASE)
|
||||
).toHaveLength(1);
|
||||
expect(first.info).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ marker: LogMarker.END_PHASE }),
|
||||
expect.anything()
|
||||
);
|
||||
tools.end(BuildPhaseResult.SUCCESS);
|
||||
expect(first.info).toHaveBeenLastCalledWith(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.SUCCESS },
|
||||
'End phase: Argent session'
|
||||
);
|
||||
});
|
||||
@@ -293,6 +293,63 @@ describe(startUptermHostAsync, () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('downloads through the cache proxy when one is configured', async () => {
|
||||
uptermOnPath = false;
|
||||
|
||||
await startUptermHostAsync(
|
||||
makeCtx({ EAS_BUILD_COCOAPODS_CACHE_URL: 'http://10.0.0.1:8081/repository/proxy' }),
|
||||
{
|
||||
relayServerUrl: 'wss://relay.expo.dev',
|
||||
}
|
||||
);
|
||||
|
||||
expect(mockedDownloadFile).toHaveBeenCalledTimes(1);
|
||||
expect(mockedDownloadFile).toHaveBeenCalledWith(
|
||||
expect.stringMatching(
|
||||
/^http:\/\/10\.0\.0\.1:8081\/repository\/proxy\/storage\.googleapis\.com\/turtle-v2\/upterm\/upterm-/
|
||||
),
|
||||
expect.stringContaining('/tmp/eas-upterm-1'),
|
||||
expect.objectContaining({ retry: 3 })
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to the direct URL when the proxied download fails', async () => {
|
||||
uptermOnPath = false;
|
||||
mockedDownloadFile.mockRejectedValueOnce(new Error('502 Bad Gateway') as never);
|
||||
|
||||
const host = await startUptermHostAsync(
|
||||
makeCtx({ EAS_BUILD_COCOAPODS_CACHE_URL: 'http://10.0.0.1:8081/repository/proxy' }),
|
||||
{ relayServerUrl: 'wss://relay.expo.dev' }
|
||||
);
|
||||
|
||||
expect(host.connectionConfig.secret).toBe('TOKENx');
|
||||
expect(mockedDownloadFile).toHaveBeenCalledTimes(2);
|
||||
expect(mockedDownloadFile).toHaveBeenLastCalledWith(
|
||||
expect.stringMatching(/^https:\/\/storage\.googleapis\.com\/turtle-v2\/upterm\/upterm-/),
|
||||
expect.stringContaining('/tmp/eas-upterm-1'),
|
||||
expect.objectContaining({ retry: 3 })
|
||||
);
|
||||
expect(mockedSpawn).toHaveBeenCalledWith(
|
||||
expect.stringContaining('/tmp/eas-upterm-1'),
|
||||
expect.arrayContaining(['host']),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
||||
it('names the direct URL when both the proxied and the direct download fail', async () => {
|
||||
uptermOnPath = false;
|
||||
mockedDownloadFile.mockRejectedValue(new Error('403 Forbidden') as never);
|
||||
|
||||
await expect(
|
||||
startUptermHostAsync(
|
||||
makeCtx({ EAS_BUILD_COCOAPODS_CACHE_URL: 'http://10.0.0.1:8081/repository/proxy' }),
|
||||
{
|
||||
relayServerUrl: 'wss://r',
|
||||
}
|
||||
)
|
||||
).rejects.toThrow(/could not be downloaded from https:\/\/storage\.googleapis\.com/);
|
||||
});
|
||||
|
||||
it('throws when upterm is missing from PATH and the GCS download fails', async () => {
|
||||
uptermOnPath = false;
|
||||
mockedDownloadFile.mockRejectedValue(new Error('403 Forbidden') as never);
|
||||
|
||||
@@ -2,29 +2,38 @@ import { BuildPhase, BuildPhaseResult, LogMarker } from '@expo/eas-build-job';
|
||||
import { type bunyan } from '@expo/logger';
|
||||
import { BuildStep } from '@expo/steps';
|
||||
|
||||
export async function withLogPhaseAsync<T>(
|
||||
logger: bunyan,
|
||||
name: string,
|
||||
fn: (logger: bunyan) => Promise<T>
|
||||
): Promise<T> {
|
||||
export function startLogPhase(logger: bunyan, name: string) {
|
||||
const phaseLogger = logger.child({
|
||||
phase: BuildPhase.CUSTOM,
|
||||
buildStepId: BuildStep.getNewId(),
|
||||
buildStepDisplayName: name,
|
||||
});
|
||||
phaseLogger.info({ marker: LogMarker.START_PHASE }, `Start phase: ${name}`);
|
||||
let ended = false;
|
||||
return {
|
||||
logger: phaseLogger,
|
||||
end(result: BuildPhaseResult): void {
|
||||
if (ended) {
|
||||
return;
|
||||
}
|
||||
ended = true;
|
||||
phaseLogger.info({ marker: LogMarker.END_PHASE, result }, `End phase: ${name}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function withLogPhaseAsync<T>(
|
||||
logger: bunyan,
|
||||
name: string,
|
||||
fn: (logger: bunyan) => Promise<T>
|
||||
): Promise<T> {
|
||||
const phase = startLogPhase(logger, name);
|
||||
try {
|
||||
const result = await fn(phaseLogger);
|
||||
phaseLogger.info(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.SUCCESS },
|
||||
`End phase: ${name}`
|
||||
);
|
||||
const result = await fn(phase.logger);
|
||||
phase.end(BuildPhaseResult.SUCCESS);
|
||||
return result;
|
||||
} catch (error) {
|
||||
phaseLogger.info(
|
||||
{ marker: LogMarker.END_PHASE, result: BuildPhaseResult.FAIL },
|
||||
`End phase: ${name}`
|
||||
);
|
||||
phase.end(BuildPhaseResult.FAIL);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import { Env, SystemError } from '@expo/eas-build-job';
|
||||
import downloadFile from '@expo/downloader';
|
||||
import { bunyan } from '@expo/logger';
|
||||
import spawn, { SpawnPromise, SpawnResult } from '@expo/turtle-spawn';
|
||||
import fs from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getProxiedDownloadUrl } from './download';
|
||||
import { isChildProcessAlive, killProcessGroup } from './processes';
|
||||
import { sleepAsync } from './retry';
|
||||
import { BuildContext } from '../context';
|
||||
@@ -112,7 +114,7 @@ export function redactSpawnErrorForLog(err: unknown): unknown {
|
||||
};
|
||||
}
|
||||
|
||||
export async function resolveUptermPathAsync(env: Env): Promise<string> {
|
||||
export async function resolveUptermPathAsync(env: Env, logger: bunyan): Promise<string> {
|
||||
try {
|
||||
await spawn('upterm', ['version'], { stdio: 'pipe', env });
|
||||
return 'upterm';
|
||||
@@ -121,14 +123,36 @@ export async function resolveUptermPathAsync(env: Env): Promise<string> {
|
||||
const objectName = resolveUptermGcsObjectName();
|
||||
const downloadDir = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-upterm-'));
|
||||
const uptermPath = path.join(downloadDir, objectName);
|
||||
const url = `${UPTERM_GCS_BASE_URL}/${objectName}`;
|
||||
try {
|
||||
const directUrl = `${UPTERM_GCS_BASE_URL}/${objectName}`;
|
||||
const proxiedUrl = getProxiedDownloadUrl({
|
||||
directUrl,
|
||||
proxyBaseUrl: env.EAS_BUILD_COCOAPODS_CACHE_URL,
|
||||
});
|
||||
|
||||
const downloadAsync = async (url: string): Promise<void> => {
|
||||
await downloadFile(url, uptermPath, { retry: 3, timeout: UPTERM_DOWNLOAD_TIMEOUT_MS });
|
||||
await fs.chmod(uptermPath, 0o755);
|
||||
};
|
||||
|
||||
if (proxiedUrl) {
|
||||
try {
|
||||
await downloadAsync(proxiedUrl);
|
||||
return uptermPath;
|
||||
} catch (err) {
|
||||
logger.debug(
|
||||
{ err },
|
||||
'Failed to download upterm through the cache proxy; falling back to the direct URL.'
|
||||
);
|
||||
await fs.rm(uptermPath, { force: true }).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await downloadAsync(directUrl);
|
||||
} catch (err) {
|
||||
await fs.rm(downloadDir, { recursive: true, force: true }).catch(() => {});
|
||||
throw new SystemError(
|
||||
`The upterm SSH client was not on PATH and could not be downloaded from ${url}. ${
|
||||
`The upterm SSH client was not on PATH and could not be downloaded from ${directUrl}. ${
|
||||
err instanceof Error ? err.message : String(err)
|
||||
}`
|
||||
);
|
||||
@@ -193,7 +217,7 @@ export async function startUptermHostAsync(
|
||||
ctx: BuildContext,
|
||||
{ relayServerUrl }: { relayServerUrl: string }
|
||||
): Promise<UptermHost> {
|
||||
const uptermPath = await resolveUptermPathAsync(ctx.env);
|
||||
const uptermPath = await resolveUptermPathAsync(ctx.env, ctx.logger);
|
||||
|
||||
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-ssh-'));
|
||||
const hostKeyPath = path.join(stateDir, 'id_host');
|
||||
|
||||
+152
-150
File diff suppressed because it is too large.
Load diff
Generated
+590
-5
@@ -17348,7 +17348,7 @@
|
||||
},
|
||||
{
|
||||
"name": "exceptionStacktrace",
|
||||
"description": null,
|
||||
"description": "Symbolicated when a build or update with a matching source map exists; otherwise as reported.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "SCALAR",
|
||||
@@ -17496,7 +17496,7 @@
|
||||
},
|
||||
{
|
||||
"name": "symbolicationBuild",
|
||||
"description": "Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported.",
|
||||
"description": "Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from an update.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "OBJECT",
|
||||
@@ -17506,6 +17506,18 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "symbolicationUpdate",
|
||||
"description": "Update whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from a build.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "OBJECT",
|
||||
"name": "Update",
|
||||
"ofType": null
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "timestamp",
|
||||
"description": null,
|
||||
@@ -18879,7 +18891,7 @@
|
||||
},
|
||||
{
|
||||
"name": "stacktrace",
|
||||
"description": "Symbolicated when a build with a matching source map exists; otherwise as reported.",
|
||||
"description": "Symbolicated when a build or update with a matching source map exists; otherwise as reported.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "SCALAR",
|
||||
@@ -18891,7 +18903,7 @@
|
||||
},
|
||||
{
|
||||
"name": "symbolicationBuild",
|
||||
"description": "Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported.",
|
||||
"description": "Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from an update.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "OBJECT",
|
||||
@@ -18901,6 +18913,18 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "symbolicationUpdate",
|
||||
"description": "Update whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from a build.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "OBJECT",
|
||||
"name": "Update",
|
||||
"ofType": null
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "timestamp",
|
||||
"description": null,
|
||||
@@ -47800,6 +47824,108 @@
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "INPUT_OBJECT",
|
||||
"name": "CreateSandboxArtifactUploadSessionInput",
|
||||
"description": null,
|
||||
"fields": null,
|
||||
"inputFields": [
|
||||
{
|
||||
"name": "filename",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "size",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "ByteSize",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"interfaces": null,
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "OBJECT",
|
||||
"name": "CreateSandboxArtifactUploadSessionResult",
|
||||
"description": null,
|
||||
"fields": [
|
||||
{
|
||||
"name": "artifact",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifact",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "uploadSession",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifactUploadSession",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
"interfaces": [],
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "INPUT_OBJECT",
|
||||
"name": "CreateSandboxInput",
|
||||
@@ -77308,6 +77434,22 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "sandboxArtifacts",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifactQuery",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "sandboxes",
|
||||
"description": null,
|
||||
@@ -79222,6 +79364,30 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "artifacts",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "LIST",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifact",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "createdAt",
|
||||
"description": null,
|
||||
@@ -79348,6 +79514,224 @@
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifact",
|
||||
"description": null,
|
||||
"fields": [
|
||||
{
|
||||
"name": "createdAt",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "DateTime",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "downloadUrl",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "fileSizeBytes",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "SCALAR",
|
||||
"name": "ByteSize",
|
||||
"ofType": null
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "filename",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "ID",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "sandbox",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "Sandbox",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "updatedAt",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "DateTime",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
"interfaces": [],
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifactQuery",
|
||||
"description": null,
|
||||
"fields": [
|
||||
{
|
||||
"name": "byId",
|
||||
"description": null,
|
||||
"args": [
|
||||
{
|
||||
"name": "sandboxArtifactId",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "ID",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifact",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
"interfaces": [],
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifactUploadSession",
|
||||
"description": null,
|
||||
"fields": [
|
||||
{
|
||||
"name": "headers",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "JSONObject",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "url",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
"interfaces": [],
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxConnection",
|
||||
@@ -79478,6 +79862,55 @@
|
||||
"name": "SandboxMutation",
|
||||
"description": null,
|
||||
"fields": [
|
||||
{
|
||||
"name": "createArtifactUploadSession",
|
||||
"description": null,
|
||||
"args": [
|
||||
{
|
||||
"name": "input",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "INPUT_OBJECT",
|
||||
"name": "CreateSandboxArtifactUploadSessionInput",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "sandboxId",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "ID",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "CreateSandboxArtifactUploadSessionResult",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "createSandbox",
|
||||
"description": null,
|
||||
@@ -79511,6 +79944,39 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "finalizeArtifact",
|
||||
"description": null,
|
||||
"args": [
|
||||
{
|
||||
"name": "artifactId",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "ID",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "SandboxArtifact",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "markSandboxReady",
|
||||
"description": null,
|
||||
@@ -101688,6 +102154,26 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "platforms",
|
||||
"description": "Runs whose platform is unknown match no platforms filter.",
|
||||
"type": {
|
||||
"kind": "LIST",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "ENUM",
|
||||
"name": "AppPlatform",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "workflowIds",
|
||||
"description": null,
|
||||
@@ -102062,6 +102548,26 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "platforms",
|
||||
"description": "Runs whose platform is unknown match no platforms filter.",
|
||||
"type": {
|
||||
"kind": "LIST",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "ENUM",
|
||||
"name": "AppPlatform",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultValue": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "statuses",
|
||||
"description": null,
|
||||
@@ -102280,7 +102786,7 @@
|
||||
{
|
||||
"kind": "OBJECT",
|
||||
"name": "WorkflowDeviceTestCaseInsightsTotals",
|
||||
"description": "Raw counts only (paired with previous-window values). Pass rate, flake rate,\nand trends are computed in the frontend from the (currentValue, previousValue)\npair on each metric.\n\ntotalRuns = passedCleanCount + flakyCount + failedCount (over is_final_attempt=1 rows).\ndistinctFlakyTestCount cannot be derived in the frontend from per-test rows\nbecause pagination means the frontend doesn't see all test paths.",
|
||||
"description": "Raw counts only (paired with previous-window values). Pass rate, flake rate,\nand trends are computed in the frontend from the (currentValue, previousValue)\npair on each metric.\n\ntotalRuns = passedCleanCount + flakyCount + failedCount (over is_final_attempt=1 rows).\nplatforms splits totalRuns by platform.\ndistinctFlakyTestCount cannot be derived in the frontend from per-test rows\nbecause pagination means the frontend doesn't see all test paths.",
|
||||
"fields": [
|
||||
{
|
||||
"name": "avgDurationMs",
|
||||
@@ -102378,6 +102884,85 @@
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "platforms",
|
||||
"description": "One entry per platform with runs in the current or previous window, in the order iOS,\nAndroid, unknown.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "LIST",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "WorkflowDeviceTestCasePlatformTotals",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "totalRuns",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "WorkflowDeviceTestCaseInsightsMetric",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
"interfaces": [],
|
||||
"enumValues": null,
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"kind": "OBJECT",
|
||||
"name": "WorkflowDeviceTestCasePlatformTotals",
|
||||
"description": null,
|
||||
"fields": [
|
||||
{
|
||||
"name": "distinctTestCount",
|
||||
"description": null,
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "WorkflowDeviceTestCaseInsightsMetric",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "platform",
|
||||
"description": "Null for runs whose platform could not be derived: Maestro runs in custom jobs, and\nruns ingested before the platform was recorded.",
|
||||
"args": [],
|
||||
"type": {
|
||||
"kind": "ENUM",
|
||||
"name": "AppPlatform",
|
||||
"ofType": null
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "totalRuns",
|
||||
"description": null,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eas-cli",
|
||||
"version": "24.13.0",
|
||||
"version": "24.14.0",
|
||||
"description": "EAS command line tool",
|
||||
"keywords": [
|
||||
"cli",
|
||||
|
||||
@@ -13,7 +13,8 @@ import Log from '../../log';
|
||||
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
|
||||
|
||||
export default class ChannelProtect extends EasCommand {
|
||||
static override description = 'protect a channel so only account admins can publish to it';
|
||||
static override description =
|
||||
'protect a channel so only Release Managers, Admins, and Owners can publish to it';
|
||||
|
||||
static override args = {
|
||||
name: Args.string({
|
||||
|
||||
@@ -14,7 +14,7 @@ import { toggleConfirmAsync } from '../../prompts';
|
||||
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
|
||||
|
||||
export default class ChannelUnprotect extends EasCommand {
|
||||
static override description = "remove a channel's admin-only publishing restriction";
|
||||
static override description = "remove a channel's protected publishing restriction";
|
||||
|
||||
static override args = {
|
||||
name: Args.string({
|
||||
|
||||
@@ -42,6 +42,13 @@ const totals: any = {
|
||||
distinctFlakyTestCount: metric(3, 2),
|
||||
avgDurationMs: { currentValue: 42100, previousValue: 45000 },
|
||||
p90DurationMs: { currentValue: 72000, previousValue: null },
|
||||
platforms: [
|
||||
{
|
||||
platform: 'IOS',
|
||||
totalRuns: metric(120, 100),
|
||||
distinctTestCount: metric(8, 8),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const timeSeries: any[] = [
|
||||
@@ -175,6 +182,8 @@ describe(WorkflowInsightsMaestro, () => {
|
||||
'FLAKY',
|
||||
'--tag',
|
||||
'smoke',
|
||||
'--platform',
|
||||
'ios',
|
||||
'--git-ref',
|
||||
'main',
|
||||
'--search',
|
||||
@@ -196,6 +205,7 @@ describe(WorkflowInsightsMaestro, () => {
|
||||
workflowIds: ['id-of-e2e.yml'],
|
||||
statuses: ['PASSED_CLEAN', 'FLAKY'],
|
||||
tags: ['smoke'],
|
||||
platforms: ['IOS'],
|
||||
gitRefs: ['refs/heads/main'],
|
||||
},
|
||||
search: 'login',
|
||||
@@ -206,7 +216,7 @@ describe(WorkflowInsightsMaestro, () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('queries one flow history with --flow, keeping only the workflow and git ref filters', async () => {
|
||||
it('queries one flow history with --flow, keeping the workflow, git ref, and platform filters', async () => {
|
||||
const { command } = createCommand([
|
||||
'--flow',
|
||||
'flows/login.yaml',
|
||||
@@ -214,6 +224,8 @@ describe(WorkflowInsightsMaestro, () => {
|
||||
'e2e.yml',
|
||||
'--git-ref',
|
||||
'main',
|
||||
'--platform',
|
||||
'android',
|
||||
]);
|
||||
await command.runAsync();
|
||||
|
||||
@@ -222,7 +234,11 @@ describe(WorkflowInsightsMaestro, () => {
|
||||
path: 'flows/login.yaml',
|
||||
startTime: '2026-09-01T00:00:00.000Z',
|
||||
endTime: '2026-09-09T00:00:00.000Z',
|
||||
filters: { workflowIds: ['id-of-e2e.yml'], gitRefs: ['refs/heads/main'] },
|
||||
filters: {
|
||||
workflowIds: ['id-of-e2e.yml'],
|
||||
gitRefs: ['refs/heads/main'],
|
||||
platforms: ['ANDROID'],
|
||||
},
|
||||
granularity: 'DAY',
|
||||
errorPatternsFirst: 5,
|
||||
recentRunsFirst: 50,
|
||||
@@ -241,6 +257,11 @@ describe(WorkflowInsightsMaestro, () => {
|
||||
await expect(command.runAsync()).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('rejects unknown platforms', async () => {
|
||||
const { command } = createCommand(['--platform', 'web']);
|
||||
await expect(command.runAsync()).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('skips the project directory when --project-id is given', async () => {
|
||||
const { command, getContextAsync } = createCommand(['--project-id', 'other-app']);
|
||||
await command.runAsync();
|
||||
@@ -264,6 +285,13 @@ describe(WorkflowInsightsMaestro, () => {
|
||||
expect(json.project).toBe('@acme/app');
|
||||
expect(json.totals.passRatePercent).toEqual({ current: 90, previous: 90 });
|
||||
expect(json.totals.avgDurationMs).toEqual({ current: 42100, previous: 45000 });
|
||||
expect(json.totals.platforms).toEqual([
|
||||
{
|
||||
platform: 'IOS',
|
||||
totalRuns: { current: 120, previous: 100 },
|
||||
distinctFlows: { current: 8, previous: 8 },
|
||||
},
|
||||
]);
|
||||
expect(json.flows[0].path).toBe('flows/login.yaml');
|
||||
expect(json.sort).toEqual({ field: 'fails', direction: 'desc' });
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Platform } from '@expo/eas-build-job';
|
||||
import { Flags } from '@oclif/core';
|
||||
|
||||
import EasCommand from '../../../commandUtils/EasCommand';
|
||||
@@ -48,6 +49,11 @@ export default class WorkflowInsightsMaestro extends EasCommand {
|
||||
|
||||
static override flags = {
|
||||
...WorkflowsInsightsSharedFilterFlags,
|
||||
platform: Flags.option({
|
||||
description: 'Only include flow runs on this platform (can be specified multiple times).',
|
||||
options: [Platform.IOS, Platform.ANDROID] as const,
|
||||
multiple: true,
|
||||
})(),
|
||||
status: Flags.option({
|
||||
description:
|
||||
'Only include flow runs with this status (can be specified multiple times). PASSED means passed on the first attempt.',
|
||||
|
||||
+85
-4
@@ -2702,6 +2702,7 @@ export type AppObserveCustomEvent = {
|
||||
errorSource?: Maybe<Scalars['String']['output']>;
|
||||
eventName: Scalars['String']['output'];
|
||||
exceptionMessage?: Maybe<Scalars['String']['output']>;
|
||||
/** Symbolicated when a build or update with a matching source map exists; otherwise as reported. */
|
||||
exceptionStacktrace?: Maybe<Scalars['String']['output']>;
|
||||
/** Error fields below are populated only for exception events (eventName: exception). */
|
||||
exceptionType?: Maybe<Scalars['String']['output']>;
|
||||
@@ -2714,8 +2715,10 @@ export type AppObserveCustomEvent = {
|
||||
sessionId?: Maybe<Scalars['String']['output']>;
|
||||
severityNumber?: Maybe<Scalars['Int']['output']>;
|
||||
severityText?: Maybe<Scalars['String']['output']>;
|
||||
/** Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported. */
|
||||
/** Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from an update. */
|
||||
symbolicationBuild?: Maybe<Build>;
|
||||
/** Update whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from a build. */
|
||||
symbolicationUpdate?: Maybe<Update>;
|
||||
timestamp: Scalars['DateTime']['output'];
|
||||
};
|
||||
|
||||
@@ -2870,10 +2873,12 @@ export type AppObserveError = AppObserveLog & {
|
||||
severityNumber?: Maybe<Scalars['Int']['output']>;
|
||||
severityText?: Maybe<Scalars['String']['output']>;
|
||||
source?: Maybe<Scalars['String']['output']>;
|
||||
/** Symbolicated when a build with a matching source map exists; otherwise as reported. */
|
||||
/** Symbolicated when a build or update with a matching source map exists; otherwise as reported. */
|
||||
stacktrace?: Maybe<Scalars['String']['output']>;
|
||||
/** Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported. */
|
||||
/** Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from an update. */
|
||||
symbolicationBuild?: Maybe<Build>;
|
||||
/** Update whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from a build. */
|
||||
symbolicationUpdate?: Maybe<Update>;
|
||||
timestamp: Scalars['DateTime']['output'];
|
||||
type?: Maybe<Scalars['String']['output']>;
|
||||
};
|
||||
@@ -6729,6 +6734,18 @@ export type CreatePostHogDeepLinkInput = {
|
||||
purpose?: InputMaybe<PostHogDeepLinkPurpose>;
|
||||
};
|
||||
|
||||
export type CreateSandboxArtifactUploadSessionInput = {
|
||||
filename: Scalars['String']['input'];
|
||||
name: Scalars['String']['input'];
|
||||
size: Scalars['ByteSize']['input'];
|
||||
};
|
||||
|
||||
export type CreateSandboxArtifactUploadSessionResult = {
|
||||
__typename?: 'CreateSandboxArtifactUploadSessionResult';
|
||||
artifact: SandboxArtifact;
|
||||
uploadSession: SandboxArtifactUploadSession;
|
||||
};
|
||||
|
||||
export type CreateSandboxInput = {
|
||||
agentRunId?: InputMaybe<Scalars['ID']['input']>;
|
||||
appId: Scalars['ID']['input'];
|
||||
@@ -11030,6 +11047,7 @@ export type RootQuery = {
|
||||
posthogIntegration: PostHogIntegrationQuery;
|
||||
/** Top-level query object for querying Runtimes. */
|
||||
runtimes: RuntimeQuery;
|
||||
sandboxArtifacts: SandboxArtifactQuery;
|
||||
sandboxes: SandboxQuery;
|
||||
snack: SnackQuery;
|
||||
/** Top-level query object for querying Expo status page services. */
|
||||
@@ -11279,6 +11297,7 @@ export type SsoUserDataInput = {
|
||||
export type Sandbox = {
|
||||
__typename?: 'Sandbox';
|
||||
app: App;
|
||||
artifacts: Array<SandboxArtifact>;
|
||||
createdAt: Scalars['DateTime']['output'];
|
||||
finishedAt?: Maybe<Scalars['DateTime']['output']>;
|
||||
id: Scalars['ID']['output'];
|
||||
@@ -11289,6 +11308,34 @@ export type Sandbox = {
|
||||
updatedAt: Scalars['DateTime']['output'];
|
||||
};
|
||||
|
||||
export type SandboxArtifact = {
|
||||
__typename?: 'SandboxArtifact';
|
||||
createdAt: Scalars['DateTime']['output'];
|
||||
downloadUrl?: Maybe<Scalars['String']['output']>;
|
||||
fileSizeBytes?: Maybe<Scalars['ByteSize']['output']>;
|
||||
filename: Scalars['String']['output'];
|
||||
id: Scalars['ID']['output'];
|
||||
name: Scalars['String']['output'];
|
||||
sandbox: Sandbox;
|
||||
updatedAt: Scalars['DateTime']['output'];
|
||||
};
|
||||
|
||||
export type SandboxArtifactQuery = {
|
||||
__typename?: 'SandboxArtifactQuery';
|
||||
byId: SandboxArtifact;
|
||||
};
|
||||
|
||||
|
||||
export type SandboxArtifactQuery_ByIdArgs = {
|
||||
sandboxArtifactId: Scalars['ID']['input'];
|
||||
};
|
||||
|
||||
export type SandboxArtifactUploadSession = {
|
||||
__typename?: 'SandboxArtifactUploadSession';
|
||||
headers: Scalars['JSONObject']['output'];
|
||||
url: Scalars['String']['output'];
|
||||
};
|
||||
|
||||
export type SandboxConnection = {
|
||||
__typename?: 'SandboxConnection';
|
||||
edges: Array<SandboxEdge>;
|
||||
@@ -11307,18 +11354,31 @@ export type SandboxFilterInput = {
|
||||
|
||||
export type SandboxMutation = {
|
||||
__typename?: 'SandboxMutation';
|
||||
createArtifactUploadSession: CreateSandboxArtifactUploadSessionResult;
|
||||
createSandbox: Sandbox;
|
||||
finalizeArtifact: SandboxArtifact;
|
||||
markSandboxReady: Sandbox;
|
||||
stopSandbox: Sandbox;
|
||||
touchSandbox: Sandbox;
|
||||
};
|
||||
|
||||
|
||||
export type SandboxMutation_CreateArtifactUploadSessionArgs = {
|
||||
input: CreateSandboxArtifactUploadSessionInput;
|
||||
sandboxId: Scalars['ID']['input'];
|
||||
};
|
||||
|
||||
|
||||
export type SandboxMutation_CreateSandboxArgs = {
|
||||
input: CreateSandboxInput;
|
||||
};
|
||||
|
||||
|
||||
export type SandboxMutation_FinalizeArtifactArgs = {
|
||||
artifactId: Scalars['ID']['input'];
|
||||
};
|
||||
|
||||
|
||||
export type SandboxMutation_MarkSandboxReadyArgs = {
|
||||
sandboxId: Scalars['ID']['input'];
|
||||
};
|
||||
@@ -14434,6 +14494,8 @@ export type WorkflowDeviceTestCaseHistory_TimeSeriesArgs = {
|
||||
|
||||
export type WorkflowDeviceTestCaseHistoryFiltersInput = {
|
||||
gitRefs?: InputMaybe<Array<Scalars['String']['input']>>;
|
||||
/** Runs whose platform is unknown match no platforms filter. */
|
||||
platforms?: InputMaybe<Array<AppPlatform>>;
|
||||
workflowIds?: InputMaybe<Array<Scalars['ID']['input']>>;
|
||||
};
|
||||
|
||||
@@ -14482,6 +14544,8 @@ export type WorkflowDeviceTestCaseInsightsFacets = {
|
||||
|
||||
export type WorkflowDeviceTestCaseInsightsFiltersInput = {
|
||||
gitRefs?: InputMaybe<Array<Scalars['String']['input']>>;
|
||||
/** Runs whose platform is unknown match no platforms filter. */
|
||||
platforms?: InputMaybe<Array<AppPlatform>>;
|
||||
statuses?: InputMaybe<Array<WorkflowDeviceTestCaseStatusFilter>>;
|
||||
tags?: InputMaybe<Array<Scalars['String']['input']>>;
|
||||
workflowIds?: InputMaybe<Array<Scalars['ID']['input']>>;
|
||||
@@ -14531,6 +14595,7 @@ export type WorkflowDeviceTestCaseInsightsTimespanInput = {
|
||||
* pair on each metric.
|
||||
*
|
||||
* totalRuns = passedCleanCount + flakyCount + failedCount (over is_final_attempt=1 rows).
|
||||
* platforms splits totalRuns by platform.
|
||||
* distinctFlakyTestCount cannot be derived in the frontend from per-test rows
|
||||
* because pagination means the frontend doesn't see all test paths.
|
||||
*/
|
||||
@@ -14542,6 +14607,22 @@ export type WorkflowDeviceTestCaseInsightsTotals = {
|
||||
flakyCount: WorkflowDeviceTestCaseInsightsMetric;
|
||||
p90DurationMs: WorkflowDeviceTestCaseInsightsNullableMetric;
|
||||
passedCleanCount: WorkflowDeviceTestCaseInsightsMetric;
|
||||
/**
|
||||
* One entry per platform with runs in the current or previous window, in the order iOS,
|
||||
* Android, unknown.
|
||||
*/
|
||||
platforms: Array<WorkflowDeviceTestCasePlatformTotals>;
|
||||
totalRuns: WorkflowDeviceTestCaseInsightsMetric;
|
||||
};
|
||||
|
||||
export type WorkflowDeviceTestCasePlatformTotals = {
|
||||
__typename?: 'WorkflowDeviceTestCasePlatformTotals';
|
||||
distinctTestCount: WorkflowDeviceTestCaseInsightsMetric;
|
||||
/**
|
||||
* Null for runs whose platform could not be derived: Maestro runs in custom jobs, and
|
||||
* runs ingested before the platform was recorded.
|
||||
*/
|
||||
platform?: Maybe<AppPlatform>;
|
||||
totalRuns: WorkflowDeviceTestCaseInsightsMetric;
|
||||
};
|
||||
|
||||
@@ -17308,7 +17389,7 @@ export type WorkflowDeviceTestCaseInsightsByAppIdQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type WorkflowDeviceTestCaseInsightsByAppIdQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, fullName: string, workflowDeviceTestCaseInsights: { __typename?: 'WorkflowDeviceTestCaseInsights', totals: { __typename?: 'WorkflowDeviceTestCaseInsightsTotals', totalRuns: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, passedCleanCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, flakyCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, distinctFlakyTestCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, avgDurationMs: { __typename?: 'WorkflowDeviceTestCaseInsightsNullableMetric', currentValue?: number | null, previousValue?: number | null } }, timeSeries: Array<{ __typename?: 'WorkflowDeviceTestCaseInsightsBucket', bucketStartAt: any, passedClean: number, flaky: number, failed: number }>, tests: { __typename?: 'WorkflowDeviceTestCaseStatConnection', totalCount: number, edges: Array<{ __typename?: 'WorkflowDeviceTestCaseStatEdge', node: { __typename?: 'WorkflowDeviceTestCaseStat', path: string, name: string, totalRuns: number, passedCleanCount: number, flakyCount: number, failedCount: number, p90DurationMs?: number | null, lastRunAt: any, lastRunStatus: WorkflowDeviceTestCaseStatus, lastRunIsFlaky: boolean } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean } } } } } };
|
||||
export type WorkflowDeviceTestCaseInsightsByAppIdQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, fullName: string, workflowDeviceTestCaseInsights: { __typename?: 'WorkflowDeviceTestCaseInsights', totals: { __typename?: 'WorkflowDeviceTestCaseInsightsTotals', totalRuns: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, passedCleanCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, flakyCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, distinctFlakyTestCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, avgDurationMs: { __typename?: 'WorkflowDeviceTestCaseInsightsNullableMetric', currentValue?: number | null, previousValue?: number | null }, platforms: Array<{ __typename?: 'WorkflowDeviceTestCasePlatformTotals', platform?: AppPlatform | null, totalRuns: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, distinctTestCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number } }> }, timeSeries: Array<{ __typename?: 'WorkflowDeviceTestCaseInsightsBucket', bucketStartAt: any, passedClean: number, flaky: number, failed: number }>, tests: { __typename?: 'WorkflowDeviceTestCaseStatConnection', totalCount: number, edges: Array<{ __typename?: 'WorkflowDeviceTestCaseStatEdge', node: { __typename?: 'WorkflowDeviceTestCaseStat', path: string, name: string, totalRuns: number, passedCleanCount: number, flakyCount: number, failedCount: number, p90DurationMs?: number | null, lastRunAt: any, lastRunStatus: WorkflowDeviceTestCaseStatus, lastRunIsFlaky: boolean } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean } } } } } };
|
||||
|
||||
export type WorkflowDeviceTestCaseHistoryByAppIdQueryVariables = Exact<{
|
||||
appId: Scalars['String']['input'];
|
||||
|
||||
@@ -89,6 +89,17 @@ export const WorkflowDeviceTestCaseInsightsQuery = {
|
||||
currentValue
|
||||
previousValue
|
||||
}
|
||||
platforms {
|
||||
platform
|
||||
totalRuns {
|
||||
currentValue
|
||||
previousValue
|
||||
}
|
||||
distinctTestCount {
|
||||
currentValue
|
||||
previousValue
|
||||
}
|
||||
}
|
||||
}
|
||||
timeSeries(granularity: $granularity) {
|
||||
bucketStartAt
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
AppPlatform,
|
||||
WorkflowDeviceTestCaseInsightsTimeSeriesGranularity,
|
||||
WorkflowDeviceTestCaseStatus,
|
||||
} from '../../../graphql/generated';
|
||||
@@ -39,8 +40,34 @@ const timeSeries = [
|
||||
},
|
||||
];
|
||||
|
||||
const platformTotals = [
|
||||
{
|
||||
__typename: 'WorkflowDeviceTestCasePlatformTotals' as const,
|
||||
platform: AppPlatform.Ios,
|
||||
totalRuns: metric(120, 100),
|
||||
distinctTestCount: metric(8, 8),
|
||||
},
|
||||
{
|
||||
__typename: 'WorkflowDeviceTestCasePlatformTotals' as const,
|
||||
platform: AppPlatform.Android,
|
||||
totalRuns: metric(70, 60),
|
||||
distinctTestCount: metric(6, 5),
|
||||
},
|
||||
{
|
||||
__typename: 'WorkflowDeviceTestCasePlatformTotals' as const,
|
||||
platform: null,
|
||||
totalRuns: metric(10, 0),
|
||||
distinctTestCount: metric(2, 0),
|
||||
},
|
||||
];
|
||||
|
||||
function makeApp(
|
||||
overrides: { flows?: any[]; hasNextPage?: boolean; timeSeries?: typeof timeSeries } = {}
|
||||
overrides: {
|
||||
flows?: any[];
|
||||
hasNextPage?: boolean;
|
||||
timeSeries?: typeof timeSeries;
|
||||
platformTotals?: typeof platformTotals;
|
||||
} = {}
|
||||
): AppWithMaestroInsightsObject {
|
||||
return {
|
||||
__typename: 'App',
|
||||
@@ -59,6 +86,7 @@ function makeApp(
|
||||
currentValue: 42100,
|
||||
previousValue: null,
|
||||
},
|
||||
platforms: overrides.platformTotals ?? platformTotals,
|
||||
},
|
||||
timeSeries: overrides.timeSeries ?? timeSeries,
|
||||
tests: {
|
||||
@@ -206,6 +234,23 @@ describe(toMaestroInsightsSummary, () => {
|
||||
passRatePercent: { current: 90, previous: 90 },
|
||||
distinctFlakyFlows: { current: 3, previous: 2 },
|
||||
avgDurationMs: { current: 42100, previous: null },
|
||||
platforms: [
|
||||
{
|
||||
platform: 'IOS',
|
||||
totalRuns: { current: 120, previous: 100 },
|
||||
distinctFlows: { current: 8, previous: 8 },
|
||||
},
|
||||
{
|
||||
platform: 'ANDROID',
|
||||
totalRuns: { current: 70, previous: 60 },
|
||||
distinctFlows: { current: 6, previous: 5 },
|
||||
},
|
||||
{
|
||||
platform: null,
|
||||
totalRuns: { current: 10, previous: 0 },
|
||||
distinctFlows: { current: 2, previous: 0 },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -256,6 +301,7 @@ describe(buildMaestroInsightsJson, () => {
|
||||
'passRatePercent',
|
||||
'distinctFlakyFlows',
|
||||
'avgDurationMs',
|
||||
'platforms',
|
||||
]);
|
||||
expect(json.runsOverTime.granularity).toBe('DAY');
|
||||
expect(json.flows).toHaveLength(2);
|
||||
@@ -291,6 +337,25 @@ describe(buildMaestroInsightsTable, () => {
|
||||
expect(table).toContain('FLAKY');
|
||||
});
|
||||
|
||||
it('lists runs and flows per platform', () => {
|
||||
const table = stripAnsi(buildMaestroInsightsTable(makeSummary()));
|
||||
|
||||
expect(table).toContain('By platform (compared with the previous period):');
|
||||
expect(table).toMatch(/iOS runs\s+120 \(\+20\.0%\)/);
|
||||
expect(table).toMatch(/iOS flows\s+8 \(0\.0%\)/);
|
||||
expect(table).toMatch(/Android runs\s+70 \(\+16\.7%\)/);
|
||||
expect(table).toMatch(/Android flows\s+6 \(\+20\.0%\)/);
|
||||
expect(table).toMatch(/Unknown runs\s+10 \(n\/a\)/);
|
||||
expect(table).toMatch(/Unknown flows\s+2 \(n\/a\)/);
|
||||
expect(table.indexOf('By platform')).toBeLessThan(table.indexOf('Runs over time'));
|
||||
});
|
||||
|
||||
it('skips the platform section when there are no platform entries', () => {
|
||||
const table = buildMaestroInsightsTable(makeSummary({ platformTotals: [] }));
|
||||
|
||||
expect(table).not.toContain('By platform');
|
||||
});
|
||||
|
||||
it('omits buckets with no runs and says so in the heading', () => {
|
||||
const bucket = (day: string, passedClean: number): (typeof timeSeries)[number] => ({
|
||||
__typename: 'WorkflowDeviceTestCaseInsightsBucket',
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Platform } from '@expo/eas-build-job';
|
||||
|
||||
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { AppQuery } from '../../../graphql/queries/AppQuery';
|
||||
import {
|
||||
@@ -31,6 +33,7 @@ describe(resolveMaestroInsightsFiltersInputAsync, () => {
|
||||
workflow: ['e2e.yml'],
|
||||
status: ['PASSED', 'FLAKY', 'FAILED'],
|
||||
tag: ['smoke'],
|
||||
platform: [Platform.IOS, Platform.ANDROID],
|
||||
'git-ref': 'main',
|
||||
});
|
||||
|
||||
@@ -38,6 +41,7 @@ describe(resolveMaestroInsightsFiltersInputAsync, () => {
|
||||
workflowIds: ['id-of-e2e.yml'],
|
||||
statuses: ['PASSED_CLEAN', 'FLAKY', 'FAILED'],
|
||||
tags: ['smoke'],
|
||||
platforms: ['IOS', 'ANDROID'],
|
||||
gitRefs: ['refs/heads/main'],
|
||||
});
|
||||
});
|
||||
@@ -51,16 +55,21 @@ describe(resolveMaestroHistoryFiltersInputAsync, () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('resolves only the workflow and git ref filters', async () => {
|
||||
it('resolves the workflow, git ref, and platform filters', async () => {
|
||||
await expect(
|
||||
resolveMaestroHistoryFiltersInputAsync(graphqlClient, 'app-1', {
|
||||
workflow: ['e2e.yml'],
|
||||
'git-ref': 'main',
|
||||
platform: [Platform.ANDROID],
|
||||
})
|
||||
).resolves.toEqual({ workflowIds: ['id-of-e2e.yml'], gitRefs: ['refs/heads/main'] });
|
||||
).resolves.toEqual({
|
||||
workflowIds: ['id-of-e2e.yml'],
|
||||
gitRefs: ['refs/heads/main'],
|
||||
platforms: ['ANDROID'],
|
||||
});
|
||||
});
|
||||
|
||||
it('is undefined when neither is set', async () => {
|
||||
it('is undefined when no filter is set', async () => {
|
||||
await expect(
|
||||
resolveMaestroHistoryFiltersInputAsync(graphqlClient, 'app-1', {})
|
||||
).resolves.toBeUndefined();
|
||||
@@ -74,7 +83,17 @@ describe(getAppliedMaestroInsightsFilters, () => {
|
||||
|
||||
it('keeps the values as given, with the git ref normalized', () => {
|
||||
expect(
|
||||
getAppliedMaestroInsightsFilters({ status: ['PASSED'], tag: ['smoke'], 'git-ref': 'main' })
|
||||
).toEqual({ statuses: ['PASSED'], tags: ['smoke'], gitRef: 'refs/heads/main' });
|
||||
getAppliedMaestroInsightsFilters({
|
||||
status: ['PASSED'],
|
||||
tag: ['smoke'],
|
||||
platform: [Platform.IOS],
|
||||
'git-ref': 'main',
|
||||
})
|
||||
).toEqual({
|
||||
statuses: ['PASSED'],
|
||||
tags: ['smoke'],
|
||||
platforms: ['IOS'],
|
||||
gitRef: 'refs/heads/main',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import chalk from 'chalk';
|
||||
import indentString from 'indent-string';
|
||||
|
||||
import {
|
||||
AppPlatform,
|
||||
WorkflowDeviceTestCaseInsightsTimeSeriesGranularity,
|
||||
WorkflowDeviceTestCaseStatus,
|
||||
} from '../../graphql/generated';
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
toTimespanJson,
|
||||
} from '../../insights/formatTimespan';
|
||||
import { formatAppliedFilters } from '../../insights/formatFilters';
|
||||
import { appPlatformDisplayNames } from '../../platform';
|
||||
import formatFields, { FormatFieldsItem } from '../../utils/formatFields';
|
||||
import renderTextTable from '../../utils/renderTextTable';
|
||||
import { sanitizeTerminalText, truncate } from '../../utils/terminalText';
|
||||
@@ -34,12 +36,20 @@ import {
|
||||
toNullableMetricSummary,
|
||||
} from '../../insights/metrics';
|
||||
|
||||
/** Runs on one platform; `platform` is null for runs whose platform is not recorded. */
|
||||
export interface MaestroPlatformTotals {
|
||||
platform: AppPlatform | null;
|
||||
totalRuns: InsightsMetricSummary;
|
||||
distinctFlows: InsightsMetricSummary;
|
||||
}
|
||||
|
||||
/** The Maestro tab's overview tiles. */
|
||||
export interface MaestroInsightsTotals {
|
||||
totalRuns: InsightsMetricSummary;
|
||||
passRatePercent: InsightsMetricSummary;
|
||||
distinctFlakyFlows: InsightsMetricSummary;
|
||||
avgDurationMs: NullableMetricSummary;
|
||||
platforms: MaestroPlatformTotals[];
|
||||
}
|
||||
|
||||
/** The tiles of one flow's detail view, which shows no previous-period comparison. */
|
||||
@@ -103,7 +113,7 @@ export interface MaestroFlowHistorySummary extends InsightsTimespanFields {
|
||||
appFullName: string;
|
||||
flowPath: string;
|
||||
granularity: WorkflowDeviceTestCaseInsightsTimeSeriesGranularity;
|
||||
filters?: Pick<AppliedMaestroInsightsFilters, 'workflows' | 'gitRef'>;
|
||||
filters?: Pick<AppliedMaestroInsightsFilters, 'workflows' | 'gitRef' | 'platforms'>;
|
||||
totals: MaestroFlowTotals;
|
||||
runsOverTime: MaestroInsightsBucket[];
|
||||
errorPatterns: MaestroErrorPatternSummary[];
|
||||
@@ -213,6 +223,11 @@ function toOverviewTotals(totals: OverviewTotalsObject): MaestroInsightsTotals {
|
||||
},
|
||||
distinctFlakyFlows: toMetricSummary(totals.distinctFlakyTestCount),
|
||||
avgDurationMs: toNullableMetricSummary(totals.avgDurationMs),
|
||||
platforms: totals.platforms.map(entry => ({
|
||||
platform: entry.platform ?? null,
|
||||
totalRuns: toMetricSummary(entry.totalRuns),
|
||||
distinctFlows: toMetricSummary(entry.distinctTestCount),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -281,6 +296,8 @@ export function buildMaestroInsightsTable(summary: MaestroInsightsSummary): stri
|
||||
sections.push(chalk.bold('Overview (compared with the previous period):'));
|
||||
sections.push(formatFields(buildOverviewTotalsFields(summary.totals)));
|
||||
|
||||
sections.push(...buildPlatformTotalsSection(summary.totals.platforms));
|
||||
|
||||
sections.push(...buildMaestroRunsOverTimeSection(summary.runsOverTime, summary.granularity));
|
||||
|
||||
sections.push('');
|
||||
@@ -365,6 +382,25 @@ function buildOverviewTotalsFields(totals: MaestroInsightsTotals): FormatFieldsI
|
||||
];
|
||||
}
|
||||
|
||||
function buildPlatformTotalsSection(platforms: MaestroPlatformTotals[]): string[] {
|
||||
if (platforms.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
'',
|
||||
chalk.bold('By platform (compared with the previous period):'),
|
||||
formatFields(
|
||||
platforms.flatMap(entry => {
|
||||
const name = entry.platform === null ? 'Unknown' : appPlatformDisplayNames[entry.platform];
|
||||
return [
|
||||
{ label: `${name} runs`, value: formatCountWithTrend(entry.totalRuns) },
|
||||
{ label: `${name} flows`, value: formatCountWithTrend(entry.distinctFlows) },
|
||||
];
|
||||
})
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
function buildFlowTotalsFields(totals: MaestroFlowTotals): FormatFieldsItem[] {
|
||||
return [
|
||||
{ label: 'Maestro runs', value: totals.totalRuns.toLocaleString() },
|
||||
@@ -446,6 +482,7 @@ function formatFilters(filters: AppliedMaestroInsightsFilters): string {
|
||||
['workflows', filters.workflows],
|
||||
['statuses', filters.statuses],
|
||||
['tags', filters.tags],
|
||||
['platforms', filters.platforms?.map(platform => appPlatformDisplayNames[platform])],
|
||||
['search', filters.search],
|
||||
['git ref', filters.gitRef],
|
||||
]);
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { Platform } from '@expo/eas-build-job';
|
||||
|
||||
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import {
|
||||
AppPlatform,
|
||||
WorkflowDeviceTestCaseHistoryFiltersInput,
|
||||
WorkflowDeviceTestCaseInsightsFiltersInput,
|
||||
WorkflowDeviceTestCaseStatusFilter,
|
||||
} from '../../graphql/generated';
|
||||
import { toAppPlatform } from '../../graphql/types/AppPlatform';
|
||||
import { normalizeGitRef, resolveWorkflowIdsAsync } from './filters';
|
||||
|
||||
/** Statuses as the dashboard names them; `PASSED` means passed on the first attempt. */
|
||||
@@ -20,15 +24,16 @@ export interface MaestroInsightsFilterFlags {
|
||||
workflow?: string[];
|
||||
status?: MaestroStatusOption[];
|
||||
tag?: string[];
|
||||
platform?: Platform[];
|
||||
search?: string;
|
||||
'git-ref'?: string;
|
||||
}
|
||||
|
||||
/** The filters as the user typed them, before workflow file names are resolved to IDs. */
|
||||
export interface AppliedMaestroInsightsFilters {
|
||||
workflows?: string[];
|
||||
statuses?: MaestroStatusOption[];
|
||||
tags?: string[];
|
||||
platforms?: AppPlatform[];
|
||||
search?: string;
|
||||
gitRef?: string;
|
||||
}
|
||||
@@ -36,7 +41,7 @@ export interface AppliedMaestroInsightsFilters {
|
||||
export async function resolveMaestroHistoryFiltersInputAsync(
|
||||
graphqlClient: ExpoGraphqlClient,
|
||||
appId: string,
|
||||
flags: Pick<MaestroInsightsFilterFlags, 'workflow' | 'git-ref'>
|
||||
flags: Pick<MaestroInsightsFilterFlags, 'workflow' | 'git-ref' | 'platform'>
|
||||
): Promise<WorkflowDeviceTestCaseHistoryFiltersInput | undefined> {
|
||||
const input: WorkflowDeviceTestCaseHistoryFiltersInput = {};
|
||||
if (flags.workflow?.length) {
|
||||
@@ -45,6 +50,9 @@ export async function resolveMaestroHistoryFiltersInputAsync(
|
||||
if (flags['git-ref']) {
|
||||
input.gitRefs = [normalizeGitRef(flags['git-ref'])];
|
||||
}
|
||||
if (flags.platform?.length) {
|
||||
input.platforms = flags.platform.map(toAppPlatform);
|
||||
}
|
||||
return Object.keys(input).length === 0 ? undefined : input;
|
||||
}
|
||||
|
||||
@@ -72,6 +80,7 @@ export function getAppliedMaestroInsightsFilters(
|
||||
...(flags.workflow?.length ? { workflows: flags.workflow } : {}),
|
||||
...(flags.status?.length ? { statuses: flags.status } : {}),
|
||||
...(flags.tag?.length ? { tags: flags.tag } : {}),
|
||||
...(flags.platform?.length ? { platforms: flags.platform.map(toAppPlatform) } : {}),
|
||||
...(flags.search ? { search: flags.search } : {}),
|
||||
...(flags['git-ref'] ? { gitRef: normalizeGitRef(flags['git-ref']) } : {}),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eas-cli-local-build-plugin",
|
||||
"version": "24.13.0",
|
||||
"version": "24.14.0",
|
||||
"description": "Tool for running EAS compatible builds on a local machine.",
|
||||
"bugs": "https://github.com/expo/eas-cli/issues",
|
||||
"license": "BUSL-1.1",
|
||||
@@ -26,7 +26,7 @@
|
||||
"clean": "rimraf node_modules dist coverage \"*.tsbuildinfo\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@expo/build-tools": "24.13.0",
|
||||
"@expo/build-tools": "24.14.0",
|
||||
"@expo/bunyan": "^4.0.1",
|
||||
"@expo/eas-build-job": "24.13.0",
|
||||
"@expo/logger": "24.13.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/worker",
|
||||
"version": "24.13.0",
|
||||
"version": "24.14.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "yarn watch",
|
||||
@@ -19,7 +19,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "7.24.7",
|
||||
"@expo/build-tools": "24.13.0",
|
||||
"@expo/build-tools": "24.14.0",
|
||||
"@expo/config-plugins": "55.0.7",
|
||||
"@expo/config-types": "55.0.5",
|
||||
"@expo/eas-build-job": "24.13.0",
|
||||
|
||||
@@ -71,6 +71,16 @@ async function waitForStreamFlush(): Promise<void> {
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
}
|
||||
|
||||
function captureStdout(): { output: string[]; write: jest.SpyInstance } {
|
||||
const output: string[] = [];
|
||||
// Never call the write callback, like a stdout that has not flushed yet.
|
||||
const write = jest.spyOn(process.stdout, 'write').mockImplementation(chunk => {
|
||||
output.push(String(chunk));
|
||||
return true;
|
||||
});
|
||||
return { output, write };
|
||||
}
|
||||
|
||||
const { HttpLogStream, RemoteLoggerStream } = jest.requireMock('@expo/build-tools') as {
|
||||
HttpLogStream: {
|
||||
instances: Array<{
|
||||
@@ -135,6 +145,107 @@ describe('logger', () => {
|
||||
expect(logs[1].msg).toBe('another ****** in base64 is ********************');
|
||||
});
|
||||
|
||||
it('masks stdout and stderr messages before writing process output and the log buffer', async () => {
|
||||
const { logger, logBuffer } = await createBuildLoggerWithSecretsFilter({
|
||||
environmentSecrets: [
|
||||
{ name: 'TOKEN', value: 'fake-provider-token', type: EnvironmentSecretType.STRING },
|
||||
],
|
||||
});
|
||||
const { output, write } = captureStdout();
|
||||
try {
|
||||
logger.child({ source: 'stdout' }).info('stdout: fake-provider-token');
|
||||
logger.child({ source: 'stderr' }).error('stderr: fake-provider-token');
|
||||
await waitForStreamFlush();
|
||||
|
||||
expect(output.map(line => JSON.parse(line).msg)).toEqual([
|
||||
'stdout: *******************',
|
||||
'stderr: *******************',
|
||||
]);
|
||||
expect(logBuffer.getLogs()).toEqual([
|
||||
'stdout: *******************',
|
||||
'stderr: *******************',
|
||||
]);
|
||||
} finally {
|
||||
write.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it('masks secrets in every field except logger metadata', async () => {
|
||||
const { logger, outputStream } = await createBuildLoggerWithSecretsFilter({
|
||||
environmentSecrets: [
|
||||
{ name: 'TOKEN', value: 'fake-provider-token', type: EnvironmentSecretType.STRING },
|
||||
{ name: 'SOURCE', value: 'stdout', type: EnvironmentSecretType.STRING },
|
||||
],
|
||||
});
|
||||
const logs: any[] = [];
|
||||
outputStream.on('data', log => logs.push(log));
|
||||
|
||||
const err = new Error('request with fake-provider-token failed');
|
||||
logger
|
||||
.child({ source: 'stdout', buildStepDisplayName: 'Use fake-provider-token' })
|
||||
.error({ err, request: { headers: ['Bearer fake-provider-token'] } }, 'failed');
|
||||
await waitForStreamFlush();
|
||||
|
||||
expect(logs).toHaveLength(1);
|
||||
expect(JSON.stringify(logs[0])).not.toContain('fake-provider-token');
|
||||
expect(logs[0].err.message).toBe('request with ******************* failed');
|
||||
expect(logs[0].err.stack).toContain('request with ******************* failed');
|
||||
expect(logs[0].request.headers).toEqual(['Bearer *******************']);
|
||||
expect(logs[0].buildStepDisplayName).toBe('Use *******************');
|
||||
expect(logs[0].source).toBe('stdout');
|
||||
expect(typeof logs[0].time).toBe('string');
|
||||
});
|
||||
|
||||
it('writes records JSON.stringify would reject instead of throwing', async () => {
|
||||
const { logger, logBuffer } = await createBuildLoggerWithSecretsFilter({
|
||||
environmentSecrets: [
|
||||
{ name: 'TOKEN', value: 'fake-provider-token', type: EnvironmentSecretType.STRING },
|
||||
],
|
||||
});
|
||||
const { output, write } = captureStdout();
|
||||
try {
|
||||
const circular: Record<string, unknown> = { token: 'fake-provider-token' };
|
||||
circular.self = circular;
|
||||
const throwing = {
|
||||
toJSON() {
|
||||
throw new Error('nope');
|
||||
},
|
||||
};
|
||||
|
||||
expect(() => {
|
||||
logger.child({ source: 'stdout' }).info({ circular, count: 1n }, 'circular');
|
||||
logger.child({ source: 'stdout' }).info({ throwing }, 'throwing fake-provider-token');
|
||||
}).not.toThrow();
|
||||
await waitForStreamFlush();
|
||||
|
||||
const records = output.map(line => JSON.parse(line));
|
||||
expect(records).toHaveLength(2);
|
||||
expect(records[0].circular).toEqual({ token: '*******************', self: '[Circular]' });
|
||||
expect(records[0].count).toBe('1');
|
||||
expect(records[1].msg).toBe('throwing *******************');
|
||||
expect(records[1].throwing).toBeUndefined();
|
||||
expect(logBuffer.getLogs()).toEqual(['circular', 'throwing *******************']);
|
||||
} finally {
|
||||
write.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not hold other destinations back while stdout flushes', async () => {
|
||||
const { logger, logBuffer } = await createBuildLoggerWithSecretsFilter({});
|
||||
const write = jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
||||
try {
|
||||
await waitForStreamFlush();
|
||||
const stdoutLogger = logger.child({ source: 'stdout' });
|
||||
for (let i = 0; i < 100; i++) {
|
||||
stdoutLogger.info(`line ${i}`);
|
||||
}
|
||||
|
||||
expect(logBuffer.getLogs()).toHaveLength(100);
|
||||
} finally {
|
||||
write.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it('adds logId to each log', async () => {
|
||||
const { logger, outputStream } = await createBuildLoggerWithSecretsFilter({});
|
||||
|
||||
|
||||
@@ -62,43 +62,108 @@ function createTransformStream(secrets: EnvironmentSecret[]): Transform {
|
||||
...secretValues,
|
||||
...secretValues.map(maybeStringBase64Decode).filter((i): i is string => !!i),
|
||||
].filter(i => i.length > 1 && !simpleSecretsWhitelist.includes(i));
|
||||
const maskSecrets = (value: string): string =>
|
||||
secretList.reduce((acc: string, pattern: string): string => {
|
||||
return acc.replaceAll(pattern, '*'.repeat(pattern.length));
|
||||
}, value);
|
||||
|
||||
return new Transform({
|
||||
readableObjectMode: true,
|
||||
writableObjectMode: true,
|
||||
transform(_chunk: any, _encoding: BufferEncoding, callback: TransformCallback) {
|
||||
let chunk = _chunk;
|
||||
if (chunk && typeof chunk === 'object') {
|
||||
// Remove hostname from logs since we don't need it.
|
||||
const { hostname: _hostname, ...rest } = chunk;
|
||||
chunk = {
|
||||
...rest,
|
||||
// Add logId to each log.
|
||||
logId: uuidv7(),
|
||||
};
|
||||
}
|
||||
|
||||
if (chunk && typeof chunk === 'object' && chunk.msg) {
|
||||
const msgWithoutSecrets = secretList.reduce((acc: string, pattern: string): string => {
|
||||
return acc.replaceAll(pattern, '*'.repeat(pattern.length));
|
||||
}, chunk.msg as string);
|
||||
|
||||
callback(null, {
|
||||
...chunk,
|
||||
msg: msgWithoutSecrets,
|
||||
});
|
||||
} else {
|
||||
transform(chunk: any, _encoding: BufferEncoding, callback: TransformCallback) {
|
||||
if (!chunk || typeof chunk !== 'object') {
|
||||
callback(null, chunk);
|
||||
return;
|
||||
}
|
||||
// Remove hostname from logs since we don't need it.
|
||||
const { hostname: _hostname, ...rest } = chunk;
|
||||
callback(
|
||||
null,
|
||||
toMaskedJsonRecord(
|
||||
{
|
||||
...rest,
|
||||
// Add logId to each log.
|
||||
logId: uuidv7(),
|
||||
},
|
||||
maskSecrets
|
||||
)
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function createDiscardStream(): Writable {
|
||||
// Set by the logger and build tooling rather than by build output. Masking them could
|
||||
// break grouping and filtering, e.g. a secret equal to "stdout" or part of a timestamp.
|
||||
const UNMASKED_RECORD_FIELDS = new Set([
|
||||
'name',
|
||||
'pid',
|
||||
'level',
|
||||
'time',
|
||||
'v',
|
||||
'logId',
|
||||
'phase',
|
||||
'source',
|
||||
'buildStepId',
|
||||
'buildStepInternalId',
|
||||
'marker',
|
||||
'result',
|
||||
]);
|
||||
|
||||
// Every destination writes records as JSON, so return a plain JSON value with secrets
|
||||
// masked in every string, not only in `msg`. Like bunyan's own stdout stream, tolerate
|
||||
// values JSON.stringify rejects instead of throwing into the code that logged.
|
||||
function toMaskedJsonRecord(
|
||||
record: Record<string, unknown>,
|
||||
maskSecrets: (value: string) => string
|
||||
): Record<string, unknown> {
|
||||
const createReplacer = (seen?: WeakSet<object>) =>
|
||||
function (this: unknown, key: string, value: unknown): unknown {
|
||||
if (typeof value === 'bigint') {
|
||||
value = value.toString();
|
||||
}
|
||||
if (this === record && UNMASKED_RECORD_FIELDS.has(key)) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return maskSecrets(value);
|
||||
}
|
||||
if (seen && value && typeof value === 'object') {
|
||||
if (seen.has(value)) {
|
||||
return '[Circular]';
|
||||
}
|
||||
seen.add(value);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
try {
|
||||
return JSON.parse(JSON.stringify(record, createReplacer()));
|
||||
} catch {}
|
||||
try {
|
||||
return JSON.parse(JSON.stringify(record, createReplacer(new WeakSet())));
|
||||
} catch {}
|
||||
// Something like a throwing toJSON(); keep the top-level values that are safe to log.
|
||||
const fallback: Record<string, unknown> = {};
|
||||
for (const [key, value] of Object.entries(record)) {
|
||||
if (typeof value === 'string') {
|
||||
fallback[key] = UNMASKED_RECORD_FIELDS.has(key) ? value : maskSecrets(value);
|
||||
} else if (typeof value === 'number' || typeof value === 'boolean' || value === null) {
|
||||
fallback[key] = value;
|
||||
} else if (value instanceof Date && !Number.isNaN(value.getTime())) {
|
||||
fallback[key] = value.toISOString();
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function createStdoutStream(): Writable {
|
||||
return new Writable({
|
||||
objectMode: true,
|
||||
write(_chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void) {
|
||||
callback(null);
|
||||
write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void) {
|
||||
// Like bunyan's stdout stream, do not wait for stdout to flush. The other
|
||||
// destinations are piped from the same source and would wait with it.
|
||||
process.stdout.write(`${JSON.stringify(chunk)}\n`);
|
||||
callback();
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -109,17 +174,16 @@ export async function createBuildLoggerWithSecretsFilter(secrets: Job['secrets']
|
||||
logBuffer: WorkerLogBuffer;
|
||||
outputStream: Readable;
|
||||
}> {
|
||||
const buildLogger = defaultLogger.child({ phase: BuildPhase.UNKNOWN });
|
||||
|
||||
const transformStream = createTransformStream(secrets?.environmentSecrets ?? []);
|
||||
const discardStream = createDiscardStream();
|
||||
transformStream.pipe(discardStream);
|
||||
transformStream.pipe(createStdoutStream());
|
||||
|
||||
buildLogger.addStream({
|
||||
type: 'raw',
|
||||
stream: transformStream,
|
||||
reemitErrorEvents: true,
|
||||
level: buildLogger.level(),
|
||||
// Do not inherit defaultLogger's stdout stream: every build-log destination must
|
||||
// receive the filtered record.
|
||||
const buildLogger = createLogger({
|
||||
name: config.loggers.base.name,
|
||||
phase: BuildPhase.UNKNOWN,
|
||||
level: defaultLogger.level(),
|
||||
streams: [{ type: 'raw', stream: transformStream, reemitErrorEvents: true }],
|
||||
});
|
||||
|
||||
let remoteLoggerStream: RemoteLoggerStream | null = null;
|
||||
@@ -137,12 +201,7 @@ export async function createBuildLoggerWithSecretsFilter(secrets: Job['secrets']
|
||||
}
|
||||
|
||||
const logBuffer = new WorkerLogBuffer(MAX_LINES_IN_BUFFER);
|
||||
buildLogger.addStream({
|
||||
type: 'raw',
|
||||
stream: logBuffer,
|
||||
reemitErrorEvents: true,
|
||||
level: buildLogger.level(),
|
||||
});
|
||||
transformStream.pipe(logBuffer);
|
||||
|
||||
let httpLogStream: HttpLogStream | null = null;
|
||||
if (config.loggers.http.baseUrl && secrets?.robotAccessToken) {
|
||||
|
||||
+8
-18
@@ -6,33 +6,23 @@
|
||||
"author": "Expo <[email protected]>",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"changelog-entry": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/changelogEntry.ts",
|
||||
"next-version": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/nextVersion.ts",
|
||||
"lint-changelog": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/lintChangelog.ts",
|
||||
"release": "./src/release.sh",
|
||||
"release-changelog": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/releaseChangelog.ts",
|
||||
"update-local-plugin": "./src/updateLocalPlugin.sh",
|
||||
"release": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/versionPackages.ts",
|
||||
"validate-changesets": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/validateChangesets.ts",
|
||||
"test": "node --no-warnings=ExperimentalWarning --loader ts-node/esm --test src/**/*.test.ts",
|
||||
"typecheck": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "5.2.0",
|
||||
"dateformat": "4.5.1",
|
||||
"fs-extra": "11.2.0",
|
||||
"lodash-es": "4.18.1",
|
||||
"marked": "3.0.4",
|
||||
"semver": "7.5.4",
|
||||
"tslib": "2.6.2"
|
||||
"@changesets/get-release-plan": "5.0.2",
|
||||
"@changesets/git": "4.0.1",
|
||||
"@changesets/parse": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dateformat": "3.0.1",
|
||||
"@types/fs-extra": "11.0.4",
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@changesets/types": "7.0.0",
|
||||
"@types/node": "22.20.5",
|
||||
"@types/semver": "7.5.6",
|
||||
"ts-node": "10.9.2",
|
||||
"typescript": "6.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
"node": ">=22.11.0"
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { URL } from 'node:url';
|
||||
|
||||
import { EntryCategory } from './entry.js';
|
||||
|
||||
export const CHANGELOG_PATH = new URL('../../../CHANGELOG.md', import.meta.url);
|
||||
|
||||
export const CATEGORY_HEADERS: Record<EntryCategory, string> = {
|
||||
[EntryCategory.BreakingChange]: '🛠 Breaking changes',
|
||||
[EntryCategory.NewFeature]: '🎉 New features',
|
||||
[EntryCategory.BugFix]: '🐛 Bug fixes',
|
||||
[EntryCategory.Chore]: '🧹 Chores',
|
||||
};
|
||||
@@ -1,92 +0,0 @@
|
||||
import { nullthrows } from '../nullthrows.js';
|
||||
|
||||
export interface Entry {
|
||||
category: EntryCategory;
|
||||
message: string;
|
||||
author: string;
|
||||
prNumber: number;
|
||||
}
|
||||
|
||||
export enum EntryCategory {
|
||||
BreakingChange = 'breaking-change',
|
||||
NewFeature = 'new-feature',
|
||||
BugFix = 'bug-fix',
|
||||
Chore = 'chore',
|
||||
}
|
||||
|
||||
export function formatEntry({ message, prNumber, author }: Entry): string {
|
||||
const capitalizedMessage = `${message[0].toUpperCase()}${message.slice(1)}`;
|
||||
const messageWithDot = capitalizedMessage.endsWith('.')
|
||||
? capitalizedMessage
|
||||
: `${capitalizedMessage}.`;
|
||||
return `${messageWithDot} ([#${prNumber}](https://github.com/expo/eas-cli/pull/${prNumber}) by [@${author}](https://github.com/${author}))`;
|
||||
}
|
||||
|
||||
const COMMIT_OR_PR_LINK = /\[#?\w+\]\(https:\/\/github\.com\/expo\/eas-cli\/(commit|pull)\/\w+\)/;
|
||||
const COMMIT_OR_PR_LINK_GROUPS =
|
||||
/\[(?<number>#?\w+)\]\(https:\/\/github\.com\/expo\/eas-cli\/(?<path>(commit|pull)\/\w+)\)/;
|
||||
const COMMIT_OR_PR_LINKS = new RegExp(
|
||||
`${COMMIT_OR_PR_LINK.source}(, ${COMMIT_OR_PR_LINK.source})*`
|
||||
);
|
||||
|
||||
const AUTHOR_LINK = /\[@[\w-]+\]\(https:\/\/github\.com\/(apps\/)?[\w-]+\)/;
|
||||
const AUTHOR_LINK_GROUPS =
|
||||
/\[@(?<author1>[\w-]+)\]\(https:\/\/github\.com\/(apps\/)?(?<author2>[\w-]+)\)/;
|
||||
const AUTHORS = new RegExp(`by ${AUTHOR_LINK.source}(, ${AUTHOR_LINK.source})*`);
|
||||
|
||||
const ENTRY_REGEX = new RegExp(
|
||||
`.+ \\(${COMMIT_OR_PR_LINKS.source} ${AUTHORS.source}(, ${COMMIT_OR_PR_LINKS.source} ${AUTHORS.source})*\\)(\n.*)*`
|
||||
);
|
||||
|
||||
export function validateEntry(entry: string): Error[] | void {
|
||||
if (!entry.match(ENTRY_REGEX)) {
|
||||
return [new Error('Invalid changelog entry, check formatting')];
|
||||
}
|
||||
|
||||
const errors: Error[] = [];
|
||||
|
||||
const commitsOrPRs = nullthrows(entry.match(new RegExp(COMMIT_OR_PR_LINK, 'g')));
|
||||
for (const commitOrPR of commitsOrPRs) {
|
||||
const maybeError = validateCommitOrPR(commitOrPR);
|
||||
if (maybeError) {
|
||||
errors.push(maybeError);
|
||||
}
|
||||
}
|
||||
|
||||
const authors = nullthrows(entry.match(new RegExp(AUTHOR_LINK, 'g')));
|
||||
for (const author of authors) {
|
||||
const maybeError = validateAuthor(author);
|
||||
if (maybeError) {
|
||||
errors.push(maybeError);
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
function validateCommitOrPR(commitOrPR: string): Error | void {
|
||||
const matched = commitOrPR.match(COMMIT_OR_PR_LINK_GROUPS);
|
||||
const { number, path } = nullthrows(matched?.groups);
|
||||
if (number.startsWith('#')) {
|
||||
const prNumber = number.slice(1);
|
||||
if (`pull/${prNumber}` !== path) {
|
||||
return new Error('The PR number does not match the URL');
|
||||
}
|
||||
} else {
|
||||
if (!path.startsWith(`commit/${number}`)) {
|
||||
return new Error('The commit hash does not match the URL');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validateAuthor(author: string): Error | void {
|
||||
const matched = author.match(AUTHOR_LINK_GROUPS);
|
||||
const { author1, author2 } = nullthrows(matched?.groups);
|
||||
if (author1 !== author2) {
|
||||
return new Error(
|
||||
`The URL and user handle should point at the same user, ${author1} !== ${author2}`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import { CHANGELOG_PATH } from './consts.js';
|
||||
import * as markdown from '../markdown.js';
|
||||
|
||||
export async function readAndParseChangelogAsync(): Promise<markdown.Tokens> {
|
||||
const contents = await fs.readFile(CHANGELOG_PATH, 'utf8');
|
||||
return markdown.lexify(contents);
|
||||
}
|
||||
|
||||
export async function writeChangelogAsync(tokens: markdown.Tokens): Promise<void> {
|
||||
const newChangelog = markdown.render(tokens);
|
||||
await fs.writeFile(CHANGELOG_PATH, newChangelog);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
import { CATEGORY_HEADERS } from './changelog/consts.js';
|
||||
import { Entry, EntryCategory, formatEntry } from './changelog/entry.js';
|
||||
import { readAndParseChangelogAsync, writeChangelogAsync } from './changelog/file.js';
|
||||
import * as markdown from './markdown.js';
|
||||
import { nullthrows } from './nullthrows.js';
|
||||
|
||||
const [rawCategory, ...rest] = process.argv.slice(2);
|
||||
const message = rest.join(' ');
|
||||
|
||||
(async function main(rawCategory: string, rawMessage: string): Promise<void> {
|
||||
const [category, message] = sanitizeInput(rawCategory, rawMessage);
|
||||
|
||||
const entry: Entry = {
|
||||
category,
|
||||
message,
|
||||
author: nullthrows(process.env.GITHUB_PR_AUTHOR),
|
||||
prNumber: Number(nullthrows(process.env.GITHUB_PR_NUMBER)),
|
||||
};
|
||||
|
||||
const tokens = await readAndParseChangelogAsync();
|
||||
addEntry(tokens, entry);
|
||||
await writeChangelogAsync(tokens);
|
||||
})(rawCategory, message).catch(err => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
function addEntry(tokens: markdown.Tokens, entry: Entry): void {
|
||||
const categoryHeader = CATEGORY_HEADERS[entry.category];
|
||||
|
||||
let i = 0;
|
||||
while (true) {
|
||||
const token = tokens[i];
|
||||
if (
|
||||
token.type === markdown.TokenType.HEADING &&
|
||||
token.depth === 3 &&
|
||||
token.text === categoryHeader
|
||||
) {
|
||||
break;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// i points at the category heading
|
||||
if (tokens[i + 1].type === markdown.TokenType.HEADING) {
|
||||
// no list yet
|
||||
const listToken = markdown.createListToken(0);
|
||||
const spaceToken = markdown.createSpaceToken('\n\n');
|
||||
tokens.splice(i + 1, 0, listToken, spaceToken);
|
||||
}
|
||||
|
||||
// tokens[i + 1] is a list token
|
||||
const listToken = tokens[i + 1] as unknown as markdown.ListToken;
|
||||
const entryMarkdown = formatEntry(entry);
|
||||
const listItemToken = markdown.createListItemToken(entryMarkdown);
|
||||
listToken.items.push(listItemToken);
|
||||
}
|
||||
|
||||
function sanitizeInput(
|
||||
rawCategory: string,
|
||||
rawMessage: string
|
||||
): [category: EntryCategory, message: string] {
|
||||
if (!rawCategory || !rawMessage) {
|
||||
throw new Error(
|
||||
'Usage: yarn changelog-entry [breaking-change|new-feature|bug-fix|chore] [message]'
|
||||
);
|
||||
}
|
||||
|
||||
const category = sanitizeCategory(rawCategory.trim());
|
||||
const message = rawMessage.trim();
|
||||
if (message === '') {
|
||||
throw new Error('Message cannot be empty string');
|
||||
}
|
||||
return [category, message];
|
||||
}
|
||||
|
||||
function sanitizeCategory(rawCategory: string): EntryCategory {
|
||||
if (Object.values(EntryCategory).includes(rawCategory as any)) {
|
||||
return rawCategory as EntryCategory;
|
||||
} else {
|
||||
throw new Error(`Invalid changelog entry category: ${rawCategory}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
|
||||
import { formatEntry } from '../../../.changeset/formatEntry.mjs';
|
||||
|
||||
const ATTRIBUTION =
|
||||
'([#1](https://github.com/expo/eas-cli/pull/1) by [@user](https://github.com/user))';
|
||||
|
||||
describe(formatEntry.name, () => {
|
||||
it('capitalizes the summary, adds a period, and appends the attribution', () => {
|
||||
assert.equal(formatEntry('add a flag', ATTRIBUTION), `Add a flag. ${ATTRIBUTION}`);
|
||||
});
|
||||
|
||||
it('keeps an existing period', () => {
|
||||
assert.equal(formatEntry('Add a flag.', ATTRIBUTION), `Add a flag. ${ATTRIBUTION}`);
|
||||
});
|
||||
|
||||
it('trims surrounding whitespace', () => {
|
||||
assert.equal(formatEntry('\n Add a flag \n\n', ATTRIBUTION), `Add a flag. ${ATTRIBUTION}`);
|
||||
});
|
||||
|
||||
it('indents later lines and keeps blank lines', () => {
|
||||
assert.equal(
|
||||
formatEntry('Add a flag\n\nDetails here.\n- item', ATTRIBUTION),
|
||||
`Add a flag. ${ATTRIBUTION}\n\n Details here.\n - item`
|
||||
);
|
||||
});
|
||||
|
||||
it('throws on an empty summary', () => {
|
||||
assert.throws(() => formatEntry(' \n ', ATTRIBUTION), /summary is empty/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { existsSync } from 'node:fs';
|
||||
import { readFile, readdir } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
export const ROOT_DIR = fileURLToPath(new URL('../../..', import.meta.url));
|
||||
|
||||
export async function readPackageDirsByNameAsync(): Promise<Map<string, string>> {
|
||||
const packagesDir = path.join(ROOT_DIR, 'packages');
|
||||
const dirByPackageName = new Map<string, string>();
|
||||
for (const dir of await readdir(packagesDir)) {
|
||||
const packageJsonPath = path.join(packagesDir, dir, 'package.json');
|
||||
if (!existsSync(packageJsonPath)) {
|
||||
continue;
|
||||
}
|
||||
const { name } = JSON.parse(await readFile(packageJsonPath, 'utf8')) as { name: string };
|
||||
dirByPackageName.set(name, dir);
|
||||
}
|
||||
return dirByPackageName;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import type { ComprehensiveRelease } from '@changesets/types';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
|
||||
import {
|
||||
formatPackagePrefix,
|
||||
getHighestBumpType,
|
||||
getSharedVersion,
|
||||
insertRootSection,
|
||||
renderRootSection,
|
||||
} from './rootChangelog.js';
|
||||
|
||||
function release(
|
||||
name: string,
|
||||
type: ComprehensiveRelease['type'],
|
||||
newVersion: string
|
||||
): ComprehensiveRelease {
|
||||
return { name, type, newVersion, oldVersion: '1.0.0', changesets: [] } as ComprehensiveRelease;
|
||||
}
|
||||
|
||||
describe(getSharedVersion.name, () => {
|
||||
it('returns the one version of the released packages', () => {
|
||||
assert.equal(
|
||||
getSharedVersion([release('a', 'minor', '1.1.0'), release('b', 'minor', '1.1.0')]),
|
||||
'1.1.0'
|
||||
);
|
||||
});
|
||||
|
||||
it('ignores packages that are not released', () => {
|
||||
assert.equal(
|
||||
getSharedVersion([release('a', 'patch', '1.0.1'), release('b', 'none', '1.0.0')]),
|
||||
'1.0.1'
|
||||
);
|
||||
});
|
||||
|
||||
it('throws when no package is released', () => {
|
||||
assert.throws(() => getSharedVersion([release('a', 'none', '1.0.0')]), /release no package/);
|
||||
assert.throws(() => getSharedVersion([]), /release no package/);
|
||||
});
|
||||
|
||||
it('throws when the released packages have different versions', () => {
|
||||
assert.throws(
|
||||
() => getSharedVersion([release('a', 'minor', '1.1.0'), release('b', 'patch', '1.0.1')]),
|
||||
/share one version.*1\.1\.0, 1\.0\.1/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe(getHighestBumpType.name, () => {
|
||||
it('returns the highest bump', () => {
|
||||
assert.equal(
|
||||
getHighestBumpType([
|
||||
{ name: 'a', type: 'patch' },
|
||||
{ name: 'b', type: 'major' },
|
||||
{ name: 'c', type: 'minor' },
|
||||
]),
|
||||
'major'
|
||||
);
|
||||
});
|
||||
|
||||
it('returns none for an empty changeset', () => {
|
||||
assert.equal(getHighestBumpType([]), 'none');
|
||||
});
|
||||
});
|
||||
|
||||
describe(formatPackagePrefix.name, () => {
|
||||
const dirs = new Map([
|
||||
['eas-cli', 'eas-cli'],
|
||||
['@expo/build-tools', 'build-tools'],
|
||||
]);
|
||||
|
||||
it('lists the package directories in changeset order', () => {
|
||||
assert.equal(
|
||||
formatPackagePrefix(
|
||||
[
|
||||
{ name: 'eas-cli', type: 'minor' },
|
||||
{ name: '@expo/build-tools', type: 'patch' },
|
||||
],
|
||||
dirs
|
||||
),
|
||||
'[eas-cli][build-tools]'
|
||||
);
|
||||
});
|
||||
|
||||
it('returns an empty string for an empty changeset', () => {
|
||||
assert.equal(formatPackagePrefix([], dirs), '');
|
||||
});
|
||||
|
||||
it('throws on an unknown package', () => {
|
||||
assert.throws(
|
||||
() => formatPackagePrefix([{ name: 'nope', type: 'patch' }], dirs),
|
||||
/"nope" from a changeset is not in packages/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe(renderRootSection.name, () => {
|
||||
it('groups entries by category in a fixed order and skips empty categories', () => {
|
||||
assert.equal(
|
||||
renderRootSection('2.0.0', '2026-10-08', [
|
||||
{ bumpType: 'none', text: 'Chore.' },
|
||||
{ bumpType: 'patch', text: 'Fix.' },
|
||||
{ bumpType: 'major', text: 'Break.' },
|
||||
{ bumpType: 'patch', text: 'Fix 2.' },
|
||||
]),
|
||||
[
|
||||
'## [2.0.0](https://github.com/expo/eas-cli/releases/tag/v2.0.0) - 2026-10-08',
|
||||
'',
|
||||
'### 🛠 Breaking changes',
|
||||
'',
|
||||
'- Break.',
|
||||
'',
|
||||
'### 🐛 Bug fixes',
|
||||
'',
|
||||
'- Fix.',
|
||||
'- Fix 2.',
|
||||
'',
|
||||
'### 🧹 Chores',
|
||||
'',
|
||||
'- Chore.',
|
||||
'',
|
||||
].join('\n')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe(insertRootSection.name, () => {
|
||||
const section = '## [2.0.0](url) - 2026-10-08\n\n### 🐛 Bug fixes\n\n- Fix.\n';
|
||||
|
||||
it('inserts the section above the newest release', () => {
|
||||
const changelog = '# Changelog\n\nIntro.\n\n## [1.0.0](url) - 2026-01-01\n\n- Old.\n';
|
||||
assert.equal(
|
||||
insertRootSection(changelog, section),
|
||||
`# Changelog\n\nIntro.\n\n${section}\n## [1.0.0](url) - 2026-01-01\n\n- Old.\n`
|
||||
);
|
||||
});
|
||||
|
||||
it('appends the section when there is no release yet', () => {
|
||||
assert.equal(
|
||||
insertRootSection('# Changelog\n\nIntro.\n', section),
|
||||
`# Changelog\n\nIntro.\n\n${section}`
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
import type { ComprehensiveRelease, Release, VersionType } from '@changesets/types';
|
||||
|
||||
export interface RootEntry {
|
||||
bumpType: VersionType;
|
||||
text: string;
|
||||
}
|
||||
|
||||
const CATEGORY_HEADINGS: readonly (readonly [VersionType, string])[] = [
|
||||
['major', '🛠 Breaking changes'],
|
||||
['minor', '🎉 New features'],
|
||||
['patch', '🐛 Bug fixes'],
|
||||
['none', '🧹 Chores'],
|
||||
];
|
||||
|
||||
const BUMP_ORDER: readonly VersionType[] = ['none', 'patch', 'minor', 'major'];
|
||||
|
||||
export function getSharedVersion(releases: readonly ComprehensiveRelease[]): string {
|
||||
const versions = new Set(
|
||||
releases.filter(release => release.type !== 'none').map(release => release.newVersion)
|
||||
);
|
||||
if (versions.size === 0) {
|
||||
throw new Error(
|
||||
'The changesets release no package: all of them are empty or "none". Add a changeset with a patch, minor, or major bump.'
|
||||
);
|
||||
}
|
||||
const [version] = versions;
|
||||
if (versions.size > 1 || !version) {
|
||||
throw new Error(
|
||||
`All packages must share one version, but the release plan has: ${[...versions].join(', ')}. Check "fixed" in .changeset/config.json.`
|
||||
);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
export function getHighestBumpType(releases: readonly Release[]): VersionType {
|
||||
let highest: VersionType = 'none';
|
||||
for (const release of releases) {
|
||||
if (BUMP_ORDER.indexOf(release.type) > BUMP_ORDER.indexOf(highest)) {
|
||||
highest = release.type;
|
||||
}
|
||||
}
|
||||
return highest;
|
||||
}
|
||||
|
||||
export function formatPackagePrefix(
|
||||
releases: readonly Release[],
|
||||
dirByPackageName: ReadonlyMap<string, string>
|
||||
): string {
|
||||
return releases
|
||||
.map(release => {
|
||||
const dir = dirByPackageName.get(release.name);
|
||||
if (!dir) {
|
||||
throw new Error(`Package "${release.name}" from a changeset is not in packages/.`);
|
||||
}
|
||||
return `[${dir}]`;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
export function renderRootSection(version: string, date: string, entries: RootEntry[]): string {
|
||||
const lines = [
|
||||
`## [${version}](https://github.com/expo/eas-cli/releases/tag/v${version}) - ${date}`,
|
||||
];
|
||||
for (const [bumpType, heading] of CATEGORY_HEADINGS) {
|
||||
const categoryEntries = entries.filter(entry => entry.bumpType === bumpType);
|
||||
if (categoryEntries.length === 0) {
|
||||
continue;
|
||||
}
|
||||
lines.push('', `### ${heading}`, '');
|
||||
for (const entry of categoryEntries) {
|
||||
lines.push(`- ${entry.text}`);
|
||||
}
|
||||
}
|
||||
return `${lines.join('\n')}\n`;
|
||||
}
|
||||
|
||||
export function insertRootSection(changelog: string, section: string): string {
|
||||
const firstReleaseIndex = changelog.search(/^## /m);
|
||||
if (firstReleaseIndex === -1) {
|
||||
return `${changelog.trimEnd()}\n\n${section}`;
|
||||
}
|
||||
return `${changelog.slice(0, firstReleaseIndex)}${section}\n${changelog.slice(firstReleaseIndex)}`;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import chalk from 'chalk';
|
||||
|
||||
import { validateEntry } from './changelog/entry.js';
|
||||
import { readAndParseChangelogAsync } from './changelog/file.js';
|
||||
import * as markdown from './markdown.js';
|
||||
interface InvalidEntry {
|
||||
entry: string;
|
||||
errors: Error[];
|
||||
}
|
||||
|
||||
(async function main(): Promise<void> {
|
||||
const invalidEntries: InvalidEntry[] = [];
|
||||
|
||||
const tokens = await readAndParseChangelogAsync();
|
||||
const listTokens = tokens.filter(
|
||||
(token): token is markdown.ListToken => token.type === markdown.TokenType.LIST
|
||||
);
|
||||
for (const listToken of listTokens) {
|
||||
for (const item of listToken.items) {
|
||||
if (item.raw) {
|
||||
const errors = validateEntry(item.raw);
|
||||
if (errors) {
|
||||
invalidEntries.push({
|
||||
entry: item.raw,
|
||||
errors,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (invalidEntries.length === 0) {
|
||||
console.log('CHANGELOG.md is valid');
|
||||
return;
|
||||
}
|
||||
|
||||
console.error('CHANGELOG.md is invalid:');
|
||||
for (const invalidEntry of invalidEntries) {
|
||||
console.error(invalidEntry.entry.trim());
|
||||
for (const error of invalidEntry.errors) {
|
||||
console.error(chalk.red(` ${error}`));
|
||||
}
|
||||
}
|
||||
process.exit(1);
|
||||
})().catch(err => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,309 +0,0 @@
|
||||
// this is mostly copy-pasted from https://github.com/expo/expo/blob/master/tools/src/Markdown.ts
|
||||
|
||||
import { unescape } from 'lodash-es';
|
||||
import marked from 'marked';
|
||||
|
||||
export enum TokenType {
|
||||
HEADING = 'heading',
|
||||
LIST = 'list',
|
||||
LIST_ITEM = 'listItem',
|
||||
PARAGRAPH = 'paragraph',
|
||||
TEXT = 'text',
|
||||
BLOCKQUOTE = 'blockquote',
|
||||
SPACE = 'space',
|
||||
CODE = 'code',
|
||||
}
|
||||
|
||||
type SimpleToken<Type> = { type: Type; raw?: string };
|
||||
|
||||
export type TextToken<Type = TokenType.TEXT> = SimpleToken<Type> & { text: string };
|
||||
|
||||
export type HeadingToken = TextToken<TokenType.HEADING> & {
|
||||
depth: number;
|
||||
tokens: Token[];
|
||||
};
|
||||
|
||||
export type ListToken = SimpleToken<TokenType.LIST> & {
|
||||
depth: number;
|
||||
items: ListItemToken[];
|
||||
ordered?: boolean;
|
||||
start?: string;
|
||||
loose?: boolean;
|
||||
};
|
||||
|
||||
export type ListItemToken = TextToken<TokenType.LIST_ITEM> & {
|
||||
depth: number;
|
||||
tokens: Token[];
|
||||
task?: boolean;
|
||||
checked?: boolean;
|
||||
loose?: boolean;
|
||||
};
|
||||
|
||||
export type ParagraphToken = TextToken<TokenType.PARAGRAPH>;
|
||||
|
||||
export type SpaceToken = SimpleToken<TokenType.SPACE>;
|
||||
|
||||
export type CodeToken = TextToken<TokenType.CODE> & {
|
||||
lang: string;
|
||||
};
|
||||
|
||||
export type BlockquoteToken = TextToken<TokenType.BLOCKQUOTE> & {
|
||||
tokens: Token[];
|
||||
};
|
||||
|
||||
export type Token =
|
||||
| HeadingToken
|
||||
| ListToken
|
||||
| ListItemToken
|
||||
| ParagraphToken
|
||||
| TextToken
|
||||
| SpaceToken
|
||||
| CodeToken
|
||||
| BlockquoteToken;
|
||||
|
||||
export interface Tokens extends Array<Token> {
|
||||
links?: any;
|
||||
}
|
||||
|
||||
export interface Renderer {
|
||||
render(tokens: Token[]): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives markdown text and returns an array of tokens.
|
||||
*/
|
||||
export function lexify(text: string): Tokens {
|
||||
const tokens = marked.lexer(text);
|
||||
recursivelyFixTokens(tokens);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives an array of tokens and renders them to markdown.
|
||||
*/
|
||||
export function render(tokens: Tokens, renderer: Renderer = new MarkdownRenderer()): string {
|
||||
// `marked` module is good enough in terms of lexifying, but its main purpose is to
|
||||
// convert markdown to html, so we need to write our own renderer for changelogs.
|
||||
return unescape(renderer.render(tokens).trim() + EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates heading token with given text and depth.
|
||||
*/
|
||||
export function createHeadingToken(text: string, depth: number = 1): HeadingToken {
|
||||
return {
|
||||
type: TokenType.HEADING,
|
||||
depth,
|
||||
text,
|
||||
tokens: [createTextToken(text)],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a token from given text.
|
||||
*/
|
||||
export function createTextToken(text: string): TextToken {
|
||||
return {
|
||||
type: TokenType.TEXT,
|
||||
text,
|
||||
};
|
||||
}
|
||||
|
||||
export function createListToken(depth: number = 1): ListToken {
|
||||
return {
|
||||
type: TokenType.LIST,
|
||||
depth,
|
||||
items: [],
|
||||
};
|
||||
}
|
||||
|
||||
export function createListItemToken(text: string, depth: number = 0): ListItemToken {
|
||||
return {
|
||||
type: TokenType.LIST_ITEM,
|
||||
depth,
|
||||
text,
|
||||
tokens: [createTextToken(text)],
|
||||
};
|
||||
}
|
||||
|
||||
export function createSpaceToken(text: string): SpaceToken {
|
||||
return {
|
||||
type: TokenType.SPACE,
|
||||
raw: text,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for tokens extending TextToken.
|
||||
*/
|
||||
export function isTextToken(token: Token): token is TextToken {
|
||||
return token?.type === TokenType.TEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for HeadingToken type.
|
||||
*/
|
||||
export function isHeadingToken(token: Token): token is HeadingToken {
|
||||
return token?.type === TokenType.HEADING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for ListToken type.
|
||||
*/
|
||||
export function isListToken(token: Token): token is ListToken {
|
||||
return token?.type === TokenType.LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for ListItemToken type.
|
||||
*/
|
||||
export function isListItemToken(token: Token): token is ListItemToken {
|
||||
return token?.type === TokenType.LIST_ITEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indents subsequent lines in given string.
|
||||
*/
|
||||
export function indentMultilineString(
|
||||
str: string,
|
||||
depth: number = 0,
|
||||
indent: string = ' '
|
||||
): string {
|
||||
return str.replace(/\n/g, '\n' + indent.repeat(depth));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes given tokens in place. We need to know depth of the list
|
||||
*/
|
||||
function recursivelyFixTokens(tokens: Token[], listDepth: number = 0): void {
|
||||
for (const token of tokens) {
|
||||
if (token.type === TokenType.LIST) {
|
||||
token.depth = listDepth;
|
||||
|
||||
for (const item of token.items) {
|
||||
item.type = TokenType.LIST_ITEM;
|
||||
item.depth = listDepth;
|
||||
recursivelyFixTokens(item.tokens, listDepth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const EOL = '\n';
|
||||
|
||||
export type RenderingContext = Partial<{
|
||||
indent: number;
|
||||
orderedList: boolean;
|
||||
itemIndex: number;
|
||||
}>;
|
||||
|
||||
export class MarkdownRenderer implements Renderer {
|
||||
render(tokens: Token[]): string {
|
||||
let output = '';
|
||||
for (const token of tokens) {
|
||||
output += this.renderToken(token, { indent: 0 });
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/* helpers */
|
||||
|
||||
renderToken(token: Token, ctx: RenderingContext): string {
|
||||
switch (token.type) {
|
||||
case TokenType.HEADING:
|
||||
return this.heading(token);
|
||||
case TokenType.LIST:
|
||||
return this.list(token, ctx);
|
||||
case TokenType.LIST_ITEM:
|
||||
return this.listItem(token, ctx);
|
||||
case TokenType.PARAGRAPH:
|
||||
return this.paragraph(token, ctx);
|
||||
case TokenType.TEXT:
|
||||
return this.text(token, ctx);
|
||||
case TokenType.SPACE:
|
||||
return this.space(token);
|
||||
case TokenType.CODE:
|
||||
return this.code(token, ctx);
|
||||
case TokenType.BLOCKQUOTE:
|
||||
return this.blockquote(token, ctx);
|
||||
default:
|
||||
// `marked` provides much more tokens, however we don't need to go so deep.
|
||||
// So far we needed only tokens with above types.
|
||||
throw new Error(`Cannot parse token: ${token}`);
|
||||
}
|
||||
}
|
||||
|
||||
indent(depth?: number, indentStr: string = ' '): string {
|
||||
return depth ? indentStr.repeat(depth) : '';
|
||||
}
|
||||
|
||||
/* tokens */
|
||||
|
||||
heading(token: HeadingToken): string {
|
||||
return this.indent(token.depth, '#') + ' ' + token.text + EOL.repeat(2);
|
||||
}
|
||||
|
||||
list(token: ListToken, ctx: { indent?: number }): string {
|
||||
let output = '';
|
||||
for (let i = 0; i < token.items.length; i++) {
|
||||
output += this.listItem(token.items[i], {
|
||||
...ctx,
|
||||
orderedList: token.ordered,
|
||||
itemIndex: i + 1,
|
||||
});
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
listItem(token: ListItemToken, ctx: RenderingContext): string {
|
||||
const indent = ctx.indent ?? 0;
|
||||
const bullet = ctx.orderedList ? `${ctx.itemIndex ?? 1}.` : '-';
|
||||
let output = this.indent(indent) + bullet + ' ';
|
||||
|
||||
if (token.tokens[0]) {
|
||||
// `renderToken` result is indented by default (e.g. got TextToken), but when dealing with lists
|
||||
// then list items indents are handled in above code instead
|
||||
output += this.renderToken(token.tokens[0], ctx).trim() + EOL;
|
||||
}
|
||||
|
||||
for (const child of token.tokens.slice(1)) {
|
||||
output += this.renderToken(child, { ...ctx, indent: indent + 1 }).trimRight() + EOL;
|
||||
}
|
||||
return output.trimRight() + EOL;
|
||||
}
|
||||
|
||||
paragraph(token: ParagraphToken, ctx: RenderingContext): string {
|
||||
return this.indent(ctx.indent) + token.text + EOL;
|
||||
}
|
||||
|
||||
text(token: TextToken, ctx: RenderingContext): string {
|
||||
// TextToken may have children which we don't really need - they would render to `text` either way.
|
||||
return this.indent(ctx.indent) + token.text;
|
||||
}
|
||||
|
||||
space(_token: SpaceToken): string {
|
||||
// Actually formatting of other tokens is good enough that we don't need to render additional newlines.
|
||||
return EOL;
|
||||
}
|
||||
|
||||
code(token: CodeToken, ctx: RenderingContext): string {
|
||||
const lines = token.text.split(EOL);
|
||||
const indentStr = this.indent(ctx?.indent);
|
||||
|
||||
lines.unshift('```' + (token.lang ?? ''));
|
||||
lines.push('```');
|
||||
|
||||
return indentStr + lines.join(EOL + indentStr);
|
||||
}
|
||||
|
||||
blockquote(token: BlockquoteToken, ctx: RenderingContext): string {
|
||||
const indentStr = this.indent(ctx.indent);
|
||||
|
||||
return (
|
||||
indentStr +
|
||||
token.tokens
|
||||
.map(child => '> ' + this.renderToken(child, { ...ctx, indent: 0 }).trimRight())
|
||||
.join(EOL + indentStr)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 110 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user