@qawolf/ci-sdk 3.5.1 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -13
- package/dist/index.js +300 -21
- package/dist/index.js.map +4 -4
- package/dist/lib/sdk/domain/collectChanges/gitDriver.d.ts +3 -0
- package/dist/lib/sdk/domain/collectChanges/index.d.ts +11 -0
- package/dist/lib/sdk/domain/collectChanges/parseLog.d.ts +12 -0
- package/dist/lib/sdk/domain/collectChanges/summarizeCommits.d.ts +19 -0
- package/dist/lib/sdk/domain/collectChanges/types.d.ts +41 -0
- package/dist/lib/sdk/domain/uploadBuild/types.d.ts +2 -2
- package/dist/lib/sdk/domain/waitForVerdict/testHarness.d.ts +6 -2
- package/dist/lib/sdk/domain/waitForVerdict/waitingForAnswer.d.ts +10 -0
- package/dist/lib/sdk/index.d.ts +37 -1
- package/dist/tests/test-lib.d.ts +26 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ to determine the status of your CI/CD step/job/action.
|
|
|
22
22
|
- [Read a Promotion](#promotion-get)
|
|
23
23
|
- [Upload an App Build](#upload-build)
|
|
24
24
|
- [Notify a Terminated Ephemeral Environment (deprecated)](#notify-terminated-ephemeral-environment)
|
|
25
|
-
- [Upload Run Input Artifacts](#upload-artifacts)
|
|
25
|
+
- [Upload Run Input Artifacts (deprecated for Android and iOS builds)](#upload-artifacts)
|
|
26
26
|
- [Requirements](#requirements)
|
|
27
27
|
- [Versioning](#versioning)
|
|
28
28
|
- [Changelog](#changelog)
|
|
@@ -208,6 +208,31 @@ const detected = detectProviderDeploymentId({
|
|
|
208
208
|
|
|
209
209
|
`deployment.reportStatus` requires `workspaceId` for every key kind; a workspace API key must name its own workspace. See [API Keys and Workspaces](#api-keys).
|
|
210
210
|
|
|
211
|
+
### `changes`
|
|
212
|
+
|
|
213
|
+
A trigger where QA Wolf chooses the flows reads what a deployment changed. Without a pull request, and without QA Wolf's GitHub or GitLab integration, your pipeline can send that summary itself: each merged pull request or pushed commit with its title, and optionally its description and changed file paths, plus release notes. Code is never accepted. `deployment.collectChanges` builds it from the local git history, so you can check or edit it before sending:
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
const collected = await deployment.collectChanges({
|
|
217
|
+
include: ["titles", "paths"],
|
|
218
|
+
since: "v1.2.0", // the commit or tag the environment ran before
|
|
219
|
+
});
|
|
220
|
+
if (
|
|
221
|
+
collected.outcome === "history-unavailable" ||
|
|
222
|
+
collected.outcome === "since-not-found"
|
|
223
|
+
)
|
|
224
|
+
throw Error(collected.fix);
|
|
225
|
+
if (collected.outcome === "git-failed") throw Error(collected.message);
|
|
226
|
+
if (collected.outcome === "collected") {
|
|
227
|
+
await deployment.reportStatus({
|
|
228
|
+
/* ... */ changes: collected.changes,
|
|
229
|
+
status: "success",
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Each commit on the first-parent line after `since` becomes one change. A GitHub or GitLab merge commit, or a GitHub squash-merge commit (its subject ends in `(#123)`), becomes a pull request titled from its message, and any other commit stays a commit. `"descriptions"` adds each change's message body, and `"paths"` adds the file paths it changed, as many as fit beside the other changes. It never reads diffs or file contents. It reads at most the 250 newest commits; older ones, and any left out to fit the API's limits, are counted in `omittedCount`. On a shallow clone it returns `history-unavailable` instead of sending part of the range, and when `since` names no commit it returns `since-not-found`. Send `changes` on the first `success` report or earlier.
|
|
235
|
+
|
|
211
236
|
### Result
|
|
212
237
|
|
|
213
238
|
`deployment.reportStatus` returns a discriminated union and never throws for an outcome you are expected to branch on. Branch on `outcome` alone:
|
|
@@ -264,6 +289,8 @@ Four things move: `deploymentType` becomes `environment.name`; `branch` / `sha`
|
|
|
264
289
|
|
|
265
290
|
`deployment.waitForVerdict` blocks until QA Wolf can say whether a deployment's tests passed. Give it the deployment id [the report](#report-deployment) returned; working out which runs the deployment produced happens inside.
|
|
266
291
|
|
|
292
|
+
On GitHub Actions, [`qawolf/wait-for-verdict-action`](https://github.com/qawolf/wait-for-verdict-action) runs this wait as a workflow step and writes a job summary with a link to each run.
|
|
293
|
+
|
|
267
294
|
> ⚠️ Set `timeout` below your CI job's own ceiling. When the job's ceiling fires first, the job is killed with no run link and no explanation. When ours fires first, you get `timed-out` with the stage, the elapsed time, and every run URL we know about.
|
|
268
295
|
|
|
269
296
|
### Example
|
|
@@ -293,6 +320,7 @@ Like every function here, it never throws. Branch on `outcome` alone:
|
|
|
293
320
|
| `not-tested` | Nothing tested this deployment. Carries `reason` and a `triggers` note per trigger saying why. |
|
|
294
321
|
| `run-canceled` | A run was canceled, so there is no verdict. This is not a pass. Carries `runs`. |
|
|
295
322
|
| `superseded` | A newer deployment to the same branch and environment replaced this run before it finished, so there is no verdict for _this_ deployment. Not a pass. Carries `runs` and `supersededBy` with the replacement's id and URL. The replacement may be testing a later commit. |
|
|
323
|
+
| `needs-review` | Every run finished, and its failures wait for a person on the run page. There is no verdict yet. Not a pass. Carries `runs`, where such a run reads `running`. |
|
|
296
324
|
| `timed-out` | The budget ran out. Carries `elapsedMs`, `lastStage` and any `runs` it had already looked up. |
|
|
297
325
|
| `canceled-by-caller` | The `signal` you passed was aborted. |
|
|
298
326
|
| `unauthorized` | The API key is unknown, or may not read this deployment. Carries `message`. |
|
|
@@ -304,6 +332,8 @@ Like every function here, it never throws. Branch on `outcome` alone:
|
|
|
304
332
|
|
|
305
333
|
`not-tested` is a separate answer from `passed` on purpose. A deployment that no trigger matched was not tested, which is a different fact from tests passing, and you decide what it is worth: exit 0 and keep the log line, or fail the build when you expect a run every time. `run-canceled` likewise means we cannot tell you.
|
|
306
334
|
|
|
335
|
+
`needs-review` means a person must answer before QA Wolf can decide. QA Wolf does not call a run passed or failed while a failure still waits for a diagnosis. The wait returns as soon as only a person can move the run: QA Wolf asked a question about each failure without a diagnosis, or the workspace does not investigate runs. It returns each run's URL, so your build log links to the run page. The example above exits 1 on it. After someone answers, the run settles to `passed` or `failed`.
|
|
336
|
+
|
|
307
337
|
`superseded` is what a `cancel-in-progress` job looks like in your CI: the example above ends within one poll of the supersession, logs the replacement's URL and exits 1, and the later deployment's job carries the verdict. Reserve a distinct exit code for it when your CI should treat the job as skipped rather than failed, for example `continue-on-error` on GitHub Actions, `allow_failure: { exit_codes: [3] }` on GitLab or `soft_fail: [{ exit_status: 3 }]` on Buildkite:
|
|
308
338
|
|
|
309
339
|
```ts
|
|
@@ -742,7 +772,7 @@ A promotion usually settles within a minute or two. The SDK has no wait helper f
|
|
|
742
772
|
|
|
743
773
|
## Upload an App Build
|
|
744
774
|
|
|
745
|
-
`uploadBuild` uploads an Android `.apk` or `.aab`, or an iOS `.ipa` file, up to
|
|
775
|
+
`uploadBuild` uploads an Android `.apk` or `.aab`, or an iOS `.ipa` file, up to 1 GB by default, and registers it as a QA Wolf build. QA Wolf reads the app ID, version and build number from the file, and runs that launch the app install the build.
|
|
746
776
|
|
|
747
777
|
```ts
|
|
748
778
|
import { makeQaWolfSdk } from "@qawolf/ci-sdk";
|
|
@@ -772,12 +802,12 @@ The parameters other than `filePath` are the input of the `build.create` contrac
|
|
|
772
802
|
|
|
773
803
|
`uploadBuild` answers `{ outcome: "uploaded", build }`, where `build` carries the build's `id`, `appId`, `appName`, `platform`, `version`, `buildNumber`, `fileName`, `sizeBytes` and `url`. It never throws.
|
|
774
804
|
|
|
775
|
-
| `outcome` | Meaning
|
|
776
|
-
| ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
777
|
-
| `file-unreadable` | `filePath` does not name a readable file. Nothing was sent to QA Wolf. Carries `filePath`.
|
|
778
|
-
| `upload-rejected` | Storage refused the file's bytes, for example because the upload URL expired. Carries `buildId` and `httpStatus`.
|
|
779
|
-
| `upload-network-error` | The file's bytes never reached storage, or the connection dropped. Carries `buildId`.
|
|
780
|
-
| `invalid-request`, `unauthorized`, `not-found`, `conflict`, `server-error`, `unexpected-status`, `network-error`, `invalid-response-body` | QA Wolf refused or failed one of the two calls. `failedStep` says which: `request-upload` (for `invalid-request`, a file that is not an `.apk`, `.aab` or `.ipa`, or is over
|
|
805
|
+
| `outcome` | Meaning |
|
|
806
|
+
| ----------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
807
|
+
| `file-unreadable` | `filePath` does not name a readable file. Nothing was sent to QA Wolf. Carries `filePath`. |
|
|
808
|
+
| `upload-rejected` | Storage refused the file's bytes, for example because the upload URL expired. Carries `buildId` and `httpStatus`. |
|
|
809
|
+
| `upload-network-error` | The file's bytes never reached storage, or the connection dropped. Carries `buildId`. |
|
|
810
|
+
| `invalid-request`, `unauthorized`, `not-found`, `conflict`, `server-error`, `unexpected-status`, `network-error`, `invalid-response-body` | QA Wolf refused or failed one of the two calls. `failedStep` says which: `request-upload` (for `invalid-request`, a file that is not an `.apk`, `.aab` or `.ipa`, or is over the workspace's limit, 1 GB by default) or `create` (for `invalid-request`, a file that is not an app, which also carries `buildId`). Same meanings as for `deployment.reportStatus`. |
|
|
781
811
|
|
|
782
812
|
A failed call creates no build. To retry, call `uploadBuild` again: each call uploads the file under a new build.
|
|
783
813
|
|
|
@@ -834,12 +864,15 @@ const { notifyTerminatedEphemeralEnvironment } = makeQaWolfSdk({
|
|
|
834
864
|
|
|
835
865
|
## Upload Run Input Artifacts
|
|
836
866
|
|
|
867
|
+
> ⚠️ **Deprecated for Android and iOS builds.** Upload them with [`uploadBuild`](#upload-build) instead, so every run records which build it tested. See [Move from legacy uploads](https://docs.qawolf.com/upload-builds#move-from-legacy-uploads). `generateSignedUrlForRunInputsExecutablesStorage` keeps working and has no removal date. Windows and Linux app files still take this path.
|
|
868
|
+
|
|
837
869
|
```ts
|
|
838
|
-
import { type DeployConfig, makeQaWolfSdk } from "@qawolf/ci-sdk";
|
|
839
870
|
import fs from "fs/promises";
|
|
840
871
|
import path from "path";
|
|
841
872
|
|
|
842
|
-
|
|
873
|
+
import { type DeployConfig, makeQaWolfSdk } from "@qawolf/ci-sdk";
|
|
874
|
+
|
|
875
|
+
const { generateSignedUrlForRunInputsExecutablesStorage, attemptNotifyDeploy } =
|
|
843
876
|
makeQaWolfSdk({
|
|
844
877
|
apiKey: "qawolf_xxxxx",
|
|
845
878
|
});
|
|
@@ -875,9 +908,10 @@ async function uploadRunArtifact(filePath: string): Promise<string> {
|
|
|
875
908
|
|
|
876
909
|
// Organization and user API keys must also pass `workspaceId` here, or the
|
|
877
910
|
// request fails with a 400. See "API Keys and Workspaces" above.
|
|
878
|
-
const signedUrlResponse =
|
|
879
|
-
|
|
880
|
-
|
|
911
|
+
const signedUrlResponse =
|
|
912
|
+
await generateSignedUrlForRunInputsExecutablesStorage({
|
|
913
|
+
destinationFilePath: fileName,
|
|
914
|
+
});
|
|
881
915
|
|
|
882
916
|
if (
|
|
883
917
|
signedUrlResponse?.success &&
|
|
@@ -957,6 +991,16 @@ This package follows the [SemVer](https://semver.org/) versioning scheme. Additi
|
|
|
957
991
|
|
|
958
992
|
# Changelog
|
|
959
993
|
|
|
994
|
+
## v3.6.1
|
|
995
|
+
|
|
996
|
+
- `generateSignedUrlForRunInputsExecutablesStorage` and the [Upload Run Input Artifacts](#upload-artifacts) recipe are deprecated for Android and iOS builds. Use [`uploadBuild`](#upload-build) instead. Both keep working, and Windows and Linux app files still take this path.
|
|
997
|
+
- The [Upload Run Input Artifacts](#upload-artifacts) recipe now calls `generateSignedUrlForRunInputsExecutablesStorage`, the function that uploads app files. It called `generateSignedUrlForTempTeamStorage` before. No code changes.
|
|
998
|
+
|
|
999
|
+
## v3.6.0
|
|
1000
|
+
|
|
1001
|
+
- `deployment.waitForVerdict` answers `needs-review` when a run's failures wait for a person: QA Wolf asked a question about each of them, or the workspace does not investigate runs. Before, such a run read `running`, so the wait polled until `timeout` and answered `timed-out`. `needs-review` carries `runs` with each run's URL, and it is not a pass. A caller that switches exhaustively on `outcome` has one more case to handle. The recipe's `["passed", "not-tested"].includes(...)` check needs no change. See [Wait for a Verdict](#wait-for-verdict).
|
|
1002
|
+
- The `@qawolf/api-contracts` dependency floor is now `0.108.0`, the first version with the `needs-review` verdict.
|
|
1003
|
+
|
|
960
1004
|
## v3.5.1
|
|
961
1005
|
|
|
962
1006
|
- Fix `deployment.waitForVerdict`, `promotion.get` and `environment.promote`, which aborted with `Invalid response ... (expected string, received null)` whenever the answer left a field unset, such as `completedAt` on a run that is still running. The SDK now reads the server's superjson responses in full, so unset fields read as absent.
|
package/dist/index.js
CHANGED
|
@@ -123,7 +123,7 @@ var defaultServiceBase = "https://app.qawolf.com/";
|
|
|
123
123
|
// package.json
|
|
124
124
|
var package_default = {
|
|
125
125
|
name: "@qawolf/ci-sdk",
|
|
126
|
-
version: "3.
|
|
126
|
+
version: "3.6.1",
|
|
127
127
|
private: false,
|
|
128
128
|
description: "A simple SDK for interacting with QAWolf in CI scripts.",
|
|
129
129
|
keywords: [],
|
|
@@ -157,12 +157,12 @@ var package_default = {
|
|
|
157
157
|
"tsc:check": "tsc --noEmit"
|
|
158
158
|
},
|
|
159
159
|
dependencies: {
|
|
160
|
-
"@qawolf/api-contracts": ">=0.
|
|
160
|
+
"@qawolf/api-contracts": ">=0.108.0",
|
|
161
161
|
"@qawolf/ci-utils": "^2.0.0",
|
|
162
162
|
"@sinonjs/fake-timers": "^10.3.0",
|
|
163
163
|
superjson: "^2.2.6",
|
|
164
164
|
tslib: "^2.6.2",
|
|
165
|
-
zod: "^4.
|
|
165
|
+
zod: "^4.6.6"
|
|
166
166
|
},
|
|
167
167
|
devDependencies: {
|
|
168
168
|
"@qawolf/platform-builder": "^1.2.7",
|
|
@@ -506,6 +506,192 @@ async function handleErrorResponse(response, log) {
|
|
|
506
506
|
}
|
|
507
507
|
__name(handleErrorResponse, "handleErrorResponse");
|
|
508
508
|
|
|
509
|
+
// src/lib/sdk/domain/collectChanges/gitDriver.ts
|
|
510
|
+
import { execFile } from "node:child_process";
|
|
511
|
+
var maxBuffer = 64 * 1024 * 1024;
|
|
512
|
+
var defaultGitDriver = /* @__PURE__ */ __name((args, cwd) => new Promise((resolve) => {
|
|
513
|
+
execFile("git", args, { cwd, maxBuffer }, (error, stdout, stderr) => {
|
|
514
|
+
resolve(
|
|
515
|
+
error ? {
|
|
516
|
+
ok: false,
|
|
517
|
+
stderr: stderr && !error.message.includes(stderr) ? `${error.message}
|
|
518
|
+
${stderr}` : error.message
|
|
519
|
+
} : { ok: true, stdout }
|
|
520
|
+
);
|
|
521
|
+
});
|
|
522
|
+
}), "defaultGitDriver");
|
|
523
|
+
|
|
524
|
+
// src/lib/sdk/domain/collectChanges/parseLog.ts
|
|
525
|
+
var logFormat = "%H%x00%s%x00%b%x00";
|
|
526
|
+
var hashPattern = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/u;
|
|
527
|
+
var fieldsBeforePaths = 4;
|
|
528
|
+
function parseLog(stdout) {
|
|
529
|
+
const tokens = stdout.split("\0");
|
|
530
|
+
const starts = tokens.reduce((found, token, index) => {
|
|
531
|
+
const previous = found.at(-1);
|
|
532
|
+
const canStart = previous === void 0 ? index === 0 : index >= previous + fieldsBeforePaths;
|
|
533
|
+
return canStart && hashPattern.test(token) ? [...found, index] : found;
|
|
534
|
+
}, []);
|
|
535
|
+
return starts.map((start, position) => {
|
|
536
|
+
const [, subject = "", body = "", , ...paths] = tokens.slice(
|
|
537
|
+
start,
|
|
538
|
+
starts[position + 1] ?? tokens.length
|
|
539
|
+
);
|
|
540
|
+
return {
|
|
541
|
+
body: body.trim(),
|
|
542
|
+
paths: paths.map((path) => path.replace(/^\n/u, "")).filter((path) => path.length > 0),
|
|
543
|
+
subject: subject.trim()
|
|
544
|
+
};
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
__name(parseLog, "parseLog");
|
|
548
|
+
|
|
549
|
+
// src/lib/sdk/domain/collectChanges/summarizeCommits.ts
|
|
550
|
+
var maxItems = 250;
|
|
551
|
+
var maxTitleLength = 512;
|
|
552
|
+
var maxDescriptionLength = 4e3;
|
|
553
|
+
var maxPathsPerItem = 1e3;
|
|
554
|
+
var maxPathLength = 1024;
|
|
555
|
+
var maxReleaseNotesLength = 16e3;
|
|
556
|
+
var maxBytes = 256 * 1024;
|
|
557
|
+
var maxBytesPerItem = maxBytes / 8;
|
|
558
|
+
var cut = /* @__PURE__ */ __name((text, max) => text.length > max ? text.slice(0, max) : text, "cut");
|
|
559
|
+
var byteLengthOf = /* @__PURE__ */ __name((value) => new TextEncoder().encode(JSON.stringify(value)).length, "byteLengthOf");
|
|
560
|
+
var mergeSubjectPattern = /^Merge (pull request #\d+|branch .+ into )/u;
|
|
561
|
+
var squashSubjectPattern = /\(#\d+\)$/u;
|
|
562
|
+
var mergeRequestTrailerPattern = /^See merge request \S+$/mu;
|
|
563
|
+
function readMessage({ body, subject }) {
|
|
564
|
+
if (mergeSubjectPattern.test(subject) && body.length > 0) {
|
|
565
|
+
const [firstLine = "", ...rest] = body.replace(mergeRequestTrailerPattern, "").trim().split("\n");
|
|
566
|
+
return {
|
|
567
|
+
description: rest.join("\n").trim(),
|
|
568
|
+
kind: "pull-request",
|
|
569
|
+
// A GitLab merge commit can hold only the trailer.
|
|
570
|
+
title: firstLine.trim() || subject
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
description: body,
|
|
575
|
+
kind: squashSubjectPattern.test(subject) ? "pull-request" : "commit",
|
|
576
|
+
title: subject
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
__name(readMessage, "readMessage");
|
|
580
|
+
function toItem(commit, { descriptions, paths }) {
|
|
581
|
+
const { description, kind, title } = readMessage(commit);
|
|
582
|
+
const keptPaths = commit.paths.filter((path) => path.length <= maxPathLength).slice(0, maxPathsPerItem);
|
|
583
|
+
const withPaths = /* @__PURE__ */ __name((count) => ({
|
|
584
|
+
...paths && count > 0 && { changedPaths: keptPaths.slice(0, count) },
|
|
585
|
+
...descriptions && description.length > 0 && {
|
|
586
|
+
description: cut(description, maxDescriptionLength)
|
|
587
|
+
},
|
|
588
|
+
kind,
|
|
589
|
+
title: cut(title, maxTitleLength)
|
|
590
|
+
}), "withPaths");
|
|
591
|
+
const fits = /* @__PURE__ */ __name((count) => byteLengthOf(withPaths(count)) <= maxBytesPerItem, "fits");
|
|
592
|
+
return withPaths(
|
|
593
|
+
fits(keptPaths.length) ? keptPaths.length : largestFittingCount(keptPaths.length, fits)
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
__name(toItem, "toItem");
|
|
597
|
+
function summarizeCommits({
|
|
598
|
+
commits,
|
|
599
|
+
includeDescriptions,
|
|
600
|
+
includePaths,
|
|
601
|
+
releaseNotes,
|
|
602
|
+
totalCount
|
|
603
|
+
}) {
|
|
604
|
+
const items = commits.filter(({ subject }) => subject.length > 0).map(
|
|
605
|
+
(commit) => toItem(commit, {
|
|
606
|
+
descriptions: includeDescriptions,
|
|
607
|
+
paths: includePaths
|
|
608
|
+
})
|
|
609
|
+
);
|
|
610
|
+
const notes = releaseNotes?.trim();
|
|
611
|
+
const summaryOf = /* @__PURE__ */ __name((count) => {
|
|
612
|
+
const omittedCount = Math.max(totalCount, items.length) - count;
|
|
613
|
+
return {
|
|
614
|
+
...count > 0 && { items: items.slice(0, count) },
|
|
615
|
+
...omittedCount > 0 && { omittedCount },
|
|
616
|
+
...notes && { releaseNotes: cut(notes, maxReleaseNotesLength) }
|
|
617
|
+
};
|
|
618
|
+
}, "summaryOf");
|
|
619
|
+
return summaryOf(
|
|
620
|
+
largestFittingCount(
|
|
621
|
+
Math.min(items.length, maxItems),
|
|
622
|
+
(count) => byteLengthOf(summaryOf(count)) <= maxBytes
|
|
623
|
+
)
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
__name(summarizeCommits, "summarizeCommits");
|
|
627
|
+
function largestFittingCount(max, fits) {
|
|
628
|
+
const search = /* @__PURE__ */ __name((low, high) => {
|
|
629
|
+
if (low >= high) return low;
|
|
630
|
+
const middle = Math.ceil((low + high) / 2);
|
|
631
|
+
return fits(middle) ? search(middle, high) : search(low, middle - 1);
|
|
632
|
+
}, "search");
|
|
633
|
+
return search(0, max);
|
|
634
|
+
}
|
|
635
|
+
__name(largestFittingCount, "largestFittingCount");
|
|
636
|
+
|
|
637
|
+
// src/lib/sdk/domain/collectChanges/index.ts
|
|
638
|
+
var historyFix = "Fetch the full history before collecting changes, e.g. `fetch-depth: 0` on actions/checkout, or `git fetch --unshallow`.";
|
|
639
|
+
var sinceFix = /* @__PURE__ */ __name((since) => `Check that ${JSON.stringify(since)} names a commit or tag, and fetch it first if it's a tag, e.g. \`git fetch --tags\`.`, "sinceFix");
|
|
640
|
+
async function collectChanges(git, {
|
|
641
|
+
cwd = process.cwd(),
|
|
642
|
+
include = ["titles"],
|
|
643
|
+
releaseNotes,
|
|
644
|
+
since
|
|
645
|
+
}) {
|
|
646
|
+
const shallow = await git(["rev-parse", "--is-shallow-repository"], cwd);
|
|
647
|
+
if (!shallow.ok) return { message: shallow.stderr, outcome: "git-failed" };
|
|
648
|
+
if (shallow.stdout.trim() === "true")
|
|
649
|
+
return { fix: historyFix, outcome: "history-unavailable" };
|
|
650
|
+
const base = await git(
|
|
651
|
+
[
|
|
652
|
+
"rev-parse",
|
|
653
|
+
"--verify",
|
|
654
|
+
"--quiet",
|
|
655
|
+
"--end-of-options",
|
|
656
|
+
`${since}^{commit}`
|
|
657
|
+
],
|
|
658
|
+
cwd
|
|
659
|
+
);
|
|
660
|
+
if (!base.ok) return { fix: sinceFix(since), outcome: "since-not-found" };
|
|
661
|
+
const range = `${base.stdout.trim()}..HEAD`;
|
|
662
|
+
const count = await git(
|
|
663
|
+
["rev-list", "--count", "--first-parent", range],
|
|
664
|
+
cwd
|
|
665
|
+
);
|
|
666
|
+
if (!count.ok) return { message: count.stderr, outcome: "git-failed" };
|
|
667
|
+
const includePaths = include.includes("paths");
|
|
668
|
+
const log = await git(
|
|
669
|
+
[
|
|
670
|
+
"log",
|
|
671
|
+
"--first-parent",
|
|
672
|
+
`--max-count=${maxItems}`,
|
|
673
|
+
"-z",
|
|
674
|
+
`--format=${logFormat}`,
|
|
675
|
+
// A merge lists the paths its pull request changed.
|
|
676
|
+
...includePaths ? ["--name-only", "-m"] : [],
|
|
677
|
+
range
|
|
678
|
+
],
|
|
679
|
+
cwd
|
|
680
|
+
);
|
|
681
|
+
if (!log.ok) return { message: log.stderr, outcome: "git-failed" };
|
|
682
|
+
return {
|
|
683
|
+
changes: summarizeCommits({
|
|
684
|
+
commits: parseLog(log.stdout),
|
|
685
|
+
includeDescriptions: include.includes("descriptions"),
|
|
686
|
+
includePaths,
|
|
687
|
+
releaseNotes,
|
|
688
|
+
totalCount: Number(count.stdout.trim())
|
|
689
|
+
}),
|
|
690
|
+
outcome: "collected"
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
__name(collectChanges, "collectChanges");
|
|
694
|
+
|
|
509
695
|
// src/lib/sdk/domain/environment/promote.ts
|
|
510
696
|
import { publicContractsV1 } from "@qawolf/api-contracts";
|
|
511
697
|
|
|
@@ -1726,7 +1912,75 @@ async function awaitRuns(ctx) {
|
|
|
1726
1912
|
__name(awaitRuns, "awaitRuns");
|
|
1727
1913
|
|
|
1728
1914
|
// src/lib/sdk/domain/waitForVerdict/awaitVerdict.ts
|
|
1915
|
+
import { publicContractsV1 as publicContractsV18 } from "@qawolf/api-contracts";
|
|
1916
|
+
|
|
1917
|
+
// src/lib/sdk/domain/waitForVerdict/waitingForAnswer.ts
|
|
1729
1918
|
import { publicContractsV1 as publicContractsV17 } from "@qawolf/api-contracts";
|
|
1919
|
+
var findingStatesThatAskAPerson = [
|
|
1920
|
+
"fix-proposed",
|
|
1921
|
+
"question",
|
|
1922
|
+
"report-proposed"
|
|
1923
|
+
];
|
|
1924
|
+
function isAwaitingAnswer(finding) {
|
|
1925
|
+
return findingStatesThatAskAPerson.includes(finding.state) && finding.response === void 0;
|
|
1926
|
+
}
|
|
1927
|
+
__name(isAwaitingAnswer, "isAwaitingAnswer");
|
|
1928
|
+
function isLeftToAPerson({
|
|
1929
|
+
investigation,
|
|
1930
|
+
run
|
|
1931
|
+
}) {
|
|
1932
|
+
if (investigation.status === "not-enabled") return true;
|
|
1933
|
+
if (investigation.status !== "finished") return false;
|
|
1934
|
+
const flowIdsAwaitingAnswer = new Set(
|
|
1935
|
+
investigation.findings.filter(isAwaitingAnswer).flatMap((finding) => finding.flowIds)
|
|
1936
|
+
);
|
|
1937
|
+
const undiagnosedFailures = run.flows.filter(
|
|
1938
|
+
(flow) => flow.status === "failed" && !flow.failure.diagnosis && !flow.failure.optedOutOfInvestigation
|
|
1939
|
+
);
|
|
1940
|
+
return undiagnosedFailures.length > 0 && undiagnosedFailures.every((flow) => flowIdsAwaitingAnswer.has(flow.flowId));
|
|
1941
|
+
}
|
|
1942
|
+
__name(isLeftToAPerson, "isLeftToAPerson");
|
|
1943
|
+
async function requestIsWaitingForAnswer({
|
|
1944
|
+
ctx,
|
|
1945
|
+
run
|
|
1946
|
+
}) {
|
|
1947
|
+
if (run.status !== "running" || !run.needsReview)
|
|
1948
|
+
return { data: false, outcome: "ok" };
|
|
1949
|
+
const result = await callPublicContract(ctx.deps, ctx.apiConfig, {
|
|
1950
|
+
contract: publicContractsV17.investigation.get,
|
|
1951
|
+
input: { runId: run.runId }
|
|
1952
|
+
});
|
|
1953
|
+
if (result.outcome !== "ok") return result;
|
|
1954
|
+
return {
|
|
1955
|
+
data: isLeftToAPerson({ investigation: result.data, run }),
|
|
1956
|
+
outcome: "ok"
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1959
|
+
__name(requestIsWaitingForAnswer, "requestIsWaitingForAnswer");
|
|
1960
|
+
async function requestRunIdsWaitingForAnswer({
|
|
1961
|
+
ctx,
|
|
1962
|
+
runs
|
|
1963
|
+
}) {
|
|
1964
|
+
const answers = await Promise.all(
|
|
1965
|
+
runs.map(async (run) => ({
|
|
1966
|
+
result: await requestIsWaitingForAnswer({ ctx, run }),
|
|
1967
|
+
runId: run.runId
|
|
1968
|
+
}))
|
|
1969
|
+
);
|
|
1970
|
+
const failed = answers.find((answer) => answer.result.outcome !== "ok");
|
|
1971
|
+
if (failed && failed.result.outcome !== "ok") return failed.result;
|
|
1972
|
+
return {
|
|
1973
|
+
data: new Set(
|
|
1974
|
+
answers.filter(
|
|
1975
|
+
(answer) => answer.result.outcome === "ok" && answer.result.data
|
|
1976
|
+
).map((answer) => answer.runId)
|
|
1977
|
+
),
|
|
1978
|
+
outcome: "ok"
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
__name(requestRunIdsWaitingForAnswer, "requestRunIdsWaitingForAnswer");
|
|
1982
|
+
|
|
1983
|
+
// src/lib/sdk/domain/waitForVerdict/awaitVerdict.ts
|
|
1730
1984
|
var settledStatuses = ["passed", "failed", "canceled", "superseded"];
|
|
1731
1985
|
function isSettled(run) {
|
|
1732
1986
|
return settledStatuses.includes(run.status);
|
|
@@ -1744,6 +1998,8 @@ function aggregateRuns(deploymentId, runs) {
|
|
|
1744
1998
|
runs
|
|
1745
1999
|
};
|
|
1746
2000
|
}
|
|
2001
|
+
if (!runs.every(isSettled))
|
|
2002
|
+
return { deploymentId, outcome: "needs-review", runs };
|
|
1747
2003
|
const supersededBy = runs.find(
|
|
1748
2004
|
(run) => run.status === "superseded"
|
|
1749
2005
|
)?.supersededBy;
|
|
@@ -1764,7 +2020,7 @@ async function requestRuns(ctx, matched) {
|
|
|
1764
2020
|
const answers = await Promise.all(
|
|
1765
2021
|
matched.map(async (run) => ({
|
|
1766
2022
|
result: await callPublicContract(ctx.deps, ctx.apiConfig, {
|
|
1767
|
-
contract:
|
|
2023
|
+
contract: publicContractsV18.run.get,
|
|
1768
2024
|
// A suite can hold hundreds of flows and the verdict reads none of
|
|
1769
2025
|
// them, so ask for the smallest list the contract allows.
|
|
1770
2026
|
input: { flowStatuses: ["failed"], runId: run.runId }
|
|
@@ -1774,23 +2030,33 @@ async function requestRuns(ctx, matched) {
|
|
|
1774
2030
|
);
|
|
1775
2031
|
const failed = answers.find((answer) => answer.result.outcome !== "ok");
|
|
1776
2032
|
if (failed && failed.result.outcome !== "ok") return failed.result;
|
|
2033
|
+
const waiting = await requestRunIdsWaitingForAnswer({
|
|
2034
|
+
ctx,
|
|
2035
|
+
runs: answers.flatMap(
|
|
2036
|
+
(answer) => answer.result.outcome === "ok" ? [answer.result.data] : []
|
|
2037
|
+
)
|
|
2038
|
+
});
|
|
2039
|
+
if (waiting.outcome !== "ok") return waiting;
|
|
1777
2040
|
return {
|
|
1778
|
-
data:
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
2041
|
+
data: {
|
|
2042
|
+
runIdsWaitingForAnswer: waiting.data,
|
|
2043
|
+
runs: keepOnePerRun(
|
|
2044
|
+
answers.flatMap(
|
|
2045
|
+
(answer) => answer.result.outcome === "ok" ? [
|
|
2046
|
+
{
|
|
2047
|
+
blockingBugCount: answer.result.data.blockingBugCount,
|
|
2048
|
+
// Differs from the id asked for only when a deploy notification's
|
|
2049
|
+
// pre-allocated id was folded into an earlier run of the same commit.
|
|
2050
|
+
runId: answer.result.data.runId,
|
|
2051
|
+
runUrl: answer.result.data.url,
|
|
2052
|
+
status: answer.result.data.status,
|
|
2053
|
+
supersededBy: answer.result.data.supersededBy,
|
|
2054
|
+
triggerName: answer.triggerName
|
|
2055
|
+
}
|
|
2056
|
+
] : []
|
|
2057
|
+
)
|
|
1792
2058
|
)
|
|
1793
|
-
|
|
2059
|
+
},
|
|
1794
2060
|
outcome: "ok"
|
|
1795
2061
|
};
|
|
1796
2062
|
}
|
|
@@ -1801,9 +2067,10 @@ async function awaitVerdict(ctx, matched) {
|
|
|
1801
2067
|
let lastDescription = void 0;
|
|
1802
2068
|
return pollUntil(ctx, {
|
|
1803
2069
|
deadlineAt: ctx.startedAt + ctx.config.timeout,
|
|
1804
|
-
async onData(runs) {
|
|
2070
|
+
async onData({ runIdsWaitingForAnswer, runs }) {
|
|
1805
2071
|
lastRuns = runs;
|
|
1806
|
-
|
|
2072
|
+
const isSettledOrWaitingForAnswer = /* @__PURE__ */ __name((run) => isSettled(run) || runIdsWaitingForAnswer.has(run.runId), "isSettledOrWaitingForAnswer");
|
|
2073
|
+
if (runs.every(isSettledOrWaitingForAnswer))
|
|
1807
2074
|
return { kind: "done", result: aggregateRuns(deploymentId, runs) };
|
|
1808
2075
|
lastDescription = await reportStage(ctx, lastDescription, {
|
|
1809
2076
|
runs,
|
|
@@ -1846,6 +2113,10 @@ function logVerdict(log, verdict) {
|
|
|
1846
2113
|
return log.error(
|
|
1847
2114
|
`\u274C QA Wolf found ${verdict.blockingBugCount} blocking bug${pluralize(verdict.blockingBugCount)}. ${runUrls(verdict.runs)}`
|
|
1848
2115
|
);
|
|
2116
|
+
case "needs-review":
|
|
2117
|
+
return log.error(
|
|
2118
|
+
`\u2753 The run's failures wait for a person on the run page, so QA Wolf has no verdict yet. ${runUrls(verdict.runs)}`
|
|
2119
|
+
);
|
|
1849
2120
|
case "not-tested": {
|
|
1850
2121
|
log.info(
|
|
1851
2122
|
verdict.reason === "no-trigger-matched" ? "\u26A0\uFE0F QA Wolf: nothing to test for this deployment." : "\u26A0\uFE0F QA Wolf: a trigger matched this deployment but started no run."
|
|
@@ -1917,6 +2188,7 @@ function makeQaWolfSdk({
|
|
|
1917
2188
|
}, {
|
|
1918
2189
|
clock = defaultClock,
|
|
1919
2190
|
fetch = defaultFetch,
|
|
2191
|
+
git = defaultGitDriver,
|
|
1920
2192
|
log = defaultLogDriver
|
|
1921
2193
|
} = {}) {
|
|
1922
2194
|
if (typeof fetch !== "function") {
|
|
@@ -1941,6 +2213,8 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
|
|
|
1941
2213
|
*/
|
|
1942
2214
|
attemptNotifyDeploy: attemptNotifyDeploy.bind(null, deps, apiConfig),
|
|
1943
2215
|
deployment: {
|
|
2216
|
+
/** Builds `changes` for `reportStatus` from the local git history; sends nothing itself. */
|
|
2217
|
+
collectChanges: collectChanges.bind(null, git),
|
|
1944
2218
|
reportStatus: reportDeployment.bind(null, deps, apiConfig),
|
|
1945
2219
|
waitForVerdict: waitForVerdict.bind(null, deps, apiConfig)
|
|
1946
2220
|
},
|
|
@@ -1948,6 +2222,11 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
|
|
|
1948
2222
|
promote: promoteEnvironment.bind(null, deps, apiConfig),
|
|
1949
2223
|
terminate: terminateEnvironment.bind(null, deps, apiConfig)
|
|
1950
2224
|
},
|
|
2225
|
+
/**
|
|
2226
|
+
* Deprecated for Android and iOS builds: use `uploadBuild`, whose runs
|
|
2227
|
+
* record which build they tested. Still the way to upload Windows and
|
|
2228
|
+
* Linux app files.
|
|
2229
|
+
*/
|
|
1951
2230
|
generateSignedUrlForRunInputsExecutablesStorage: generateSignedUrlForRunInputsExecutablesStorage.bind(
|
|
1952
2231
|
null,
|
|
1953
2232
|
deps,
|