@qawolf/ci-sdk 3.4.0 → 3.5.0
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 +63 -10
- package/dist/index.js +122 -21
- package/dist/index.js.map +4 -4
- package/dist/lib/sdk/domain/generateSignedUrls/types.d.ts +3 -3
- package/dist/lib/sdk/domain/uploadBuild/index.d.ts +9 -0
- package/dist/lib/sdk/domain/uploadBuild/testHarness.d.ts +17 -0
- package/dist/lib/sdk/domain/uploadBuild/testSeed.d.ts +23 -0
- package/dist/lib/sdk/domain/uploadBuild/types.d.ts +66 -0
- package/dist/lib/sdk/domain/uploadBuild/withBuildFile.d.ts +4 -0
- package/dist/lib/sdk/index.d.ts +3 -0
- package/dist/lib/sdk/publicApi/callContract.d.ts +2 -0
- package/dist/tests/test-lib.d.ts +237 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ to determine the status of your CI/CD step/job/action.
|
|
|
20
20
|
- [Advanced: Poll with Custom Control (Iterator)](#ci-greenlight-iterator)
|
|
21
21
|
- [Promote or Terminate a Preview Environment](#environment-lifecycle)
|
|
22
22
|
- [Read a Promotion](#promotion-get)
|
|
23
|
+
- [Upload an App Build](#upload-build)
|
|
23
24
|
- [Notify a Terminated Ephemeral Environment (deprecated)](#notify-terminated-ephemeral-environment)
|
|
24
25
|
- [Upload Run Input Artifacts](#upload-artifacts)
|
|
25
26
|
- [Requirements](#requirements)
|
|
@@ -74,17 +75,17 @@ alias is unique within one workspace; `promotion.get` never needs it.
|
|
|
74
75
|
Omitting `workspaceId` with an organization or user API key is handled differently depending on the
|
|
75
76
|
call, so it is worth knowing which behavior to expect:
|
|
76
77
|
|
|
77
|
-
| Function | Behavior when `workspaceId` is omitted
|
|
78
|
-
| ------------------------------------------------- |
|
|
79
|
-
| `generateSignedUrlForTempTeamStorage` |
|
|
80
|
-
| `generateSignedUrlForRunInputsExecutablesStorage` | Same as above
|
|
81
|
-
| `attemptNotifyDeploy` | Succeeds against your organization's first-created workspace and returns a `warning` naming it.
|
|
82
|
-
| `notifyTerminatedEphemeralEnvironment` | Succeeds against your organization's first-created workspace and returns a `warning` naming it.
|
|
83
|
-
| `environment.promote`, `environment.terminate` | Succeeds when `environmentId` is an id. An alias cannot be resolved without a workspace, so it answers `invalid-request`.
|
|
78
|
+
| Function | Behavior when `workspaceId` is omitted |
|
|
79
|
+
| ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
80
|
+
| `generateSignedUrlForTempTeamStorage` | Succeeds when your organization has exactly one enabled workspace. With several, the backend answers HTTP `400` asking for `workspaceId`; with none, HTTP `400` saying the organization has no active workspace. |
|
|
81
|
+
| `generateSignedUrlForRunInputsExecutablesStorage` | Same as above. |
|
|
82
|
+
| `attemptNotifyDeploy` | Succeeds against your organization's first-created workspace and returns a `warning` naming it. |
|
|
83
|
+
| `notifyTerminatedEphemeralEnvironment` | Succeeds against your organization's first-created workspace and returns a `warning` naming it. |
|
|
84
|
+
| `environment.promote`, `environment.terminate` | Succeeds when `environmentId` is an id. An alias cannot be resolved without a workspace, so it answers `invalid-request`. |
|
|
84
85
|
|
|
85
|
-
> ⚠️ The signed-URL functions
|
|
86
|
-
>
|
|
87
|
-
> artifact name are otherwise correct, most often means `workspaceId` was not sent.
|
|
86
|
+
> ⚠️ The signed-URL functions never fall back to the first-created workspace. If your organization has
|
|
87
|
+
> several enabled workspaces, they **require** `workspaceId`; a `400` from either function, especially
|
|
88
|
+
> when the API key and artifact name are otherwise correct, most often means `workspaceId` was not sent.
|
|
88
89
|
|
|
89
90
|
When this happens, the SDK logs the real status before it reports the outcome, so the log line is
|
|
90
91
|
the reliable signal:
|
|
@@ -737,6 +738,49 @@ switch (result.promotion.status) {
|
|
|
737
738
|
|
|
738
739
|
A promotion usually settles within a minute or two. The SDK has no wait helper for it yet, so a pipeline that needs the settled status polls `promotion.get` itself, with `pending` and `resolving` as the states to keep polling on.
|
|
739
740
|
|
|
741
|
+
<a id="upload-build"></a>
|
|
742
|
+
|
|
743
|
+
## Upload an App Build
|
|
744
|
+
|
|
745
|
+
`uploadBuild` uploads an Android `.apk` or `.aab`, or an iOS `.ipa` file, up to 500 MB, 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
|
+
|
|
747
|
+
```ts
|
|
748
|
+
import { makeQaWolfSdk } from "@qawolf/ci-sdk";
|
|
749
|
+
|
|
750
|
+
const { uploadBuild } = makeQaWolfSdk({ apiKey: "qawolf_xxxxx" });
|
|
751
|
+
|
|
752
|
+
const result = await uploadBuild({
|
|
753
|
+
filePath: "app/build/outputs/apk/release/app-release.apk",
|
|
754
|
+
environment: { name: "staging" },
|
|
755
|
+
branch: "main",
|
|
756
|
+
commitSha: "0123abc",
|
|
757
|
+
workspaceId: "your-workspace-id",
|
|
758
|
+
});
|
|
759
|
+
if (result.outcome !== "uploaded") process.exit(1);
|
|
760
|
+
console.log(result.build.id, result.build.appId, result.build.version);
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
Only `filePath` is required. The file is streamed from disk, so a large build is not held in memory.
|
|
764
|
+
|
|
765
|
+
- `environment` is the environment whose runs install the build from now on, until a newer build of the same app and platform arrives. Pass `{ id }` for an existing environment, or `{ name, ephemeral?, baseEphemeralEnvironment? }`, the same selector `deployment.reportStatus` takes, which creates the environment when none matches. Omit it for a build that only runs created with it install.
|
|
766
|
+
- `branch` and `commitSha` are shown with the build.
|
|
767
|
+
- `workspaceId` is required with an organization or user API key. See [API Keys and Workspaces](#api-keys).
|
|
768
|
+
|
|
769
|
+
The parameters other than `filePath` are the input of the `build.create` contract, derived from the published `@qawolf/api-contracts` package.
|
|
770
|
+
|
|
771
|
+
### Result
|
|
772
|
+
|
|
773
|
+
`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
|
+
|
|
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 500 MB) or `create` (for `invalid-request`, a file that is not an app, which also carries `buildId`). Same meanings as for `deployment.reportStatus`. |
|
|
781
|
+
|
|
782
|
+
A failed call creates no build. To retry, call `uploadBuild` again: each call uploads the file under a new build.
|
|
783
|
+
|
|
740
784
|
<a id="notify-terminated-ephemeral-environment"></a>
|
|
741
785
|
|
|
742
786
|
## Notify a Terminated Ephemeral Environment
|
|
@@ -913,6 +957,15 @@ This package follows the [SemVer](https://semver.org/) versioning scheme. Additi
|
|
|
913
957
|
|
|
914
958
|
# Changelog
|
|
915
959
|
|
|
960
|
+
## v3.5.0
|
|
961
|
+
|
|
962
|
+
- New `uploadBuild` function, which uploads an Android `.apk` or `.aab`, or an iOS `.ipa` file of up to 500 MB and registers it as a QA Wolf build through the public `build.requestUpload` and `build.create` APIs. It streams the file from disk, optionally puts the build on an environment, and answers `{ outcome: "uploaded", build }` or one named refusal, with `failedStep` saying whether QA Wolf refused to sign the upload or to create the build. See [Upload an App Build](#upload-build).
|
|
963
|
+
- The `@qawolf/api-contracts` dependency floor is now `0.101.0`, the first version with both the `build` contracts and `builds` on `deployment.reportStatus`.
|
|
964
|
+
|
|
965
|
+
## v3.4.1
|
|
966
|
+
|
|
967
|
+
- Fix `deployment.waitForVerdict` and `promotion.get`, which failed with HTTP `405 Method Not Allowed` on every call. The SDK sent their read requests as `POST`, and now sends them as `GET`.
|
|
968
|
+
|
|
916
969
|
## v3.4.0
|
|
917
970
|
|
|
918
971
|
- New `environment.promote` and `environment.terminate` functions, for a pipeline that manages its own preview environments. `environment.promote` declares the work accepted: the environment's flow changes are merged into its base and the environment is terminated once they land. It returns the promotion in `pending`, since the merge runs in the background. `environment.terminate` discards abandoned work: the flow changes are not promoted and the runs are canceled. The two are not interchangeable. Both derive their parameters from `@qawolf/api-contracts` and answer refusals with the same named outcomes as `deployment.reportStatus`. See [Promote or Terminate a Preview Environment](#environment-lifecycle).
|
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.5.0",
|
|
127
127
|
private: false,
|
|
128
128
|
description: "A simple SDK for interacting with QAWolf in CI scripts.",
|
|
129
129
|
keywords: [],
|
|
@@ -157,7 +157,7 @@ var package_default = {
|
|
|
157
157
|
"tsc:check": "tsc --noEmit"
|
|
158
158
|
},
|
|
159
159
|
dependencies: {
|
|
160
|
-
"@qawolf/api-contracts": ">=0.
|
|
160
|
+
"@qawolf/api-contracts": ">=0.101.0",
|
|
161
161
|
"@qawolf/ci-utils": "^2.0.0",
|
|
162
162
|
"@sinonjs/fake-timers": "^10.3.0",
|
|
163
163
|
tslib: "^2.6.2",
|
|
@@ -560,26 +560,38 @@ async function readHttpError(response, contractName, log) {
|
|
|
560
560
|
};
|
|
561
561
|
}
|
|
562
562
|
__name(readHttpError, "readHttpError");
|
|
563
|
+
function buildRequest(apiConfig, contract, input) {
|
|
564
|
+
const url = new URL(
|
|
565
|
+
`/api/trpc/public.${contract.name}`,
|
|
566
|
+
apiConfig.serviceBase
|
|
567
|
+
);
|
|
568
|
+
const serializedInput = JSON.stringify({ json: input });
|
|
569
|
+
const headers = {
|
|
570
|
+
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
571
|
+
"User-Agent": apiConfig.userAgent
|
|
572
|
+
};
|
|
573
|
+
if (contract.kind === "read") {
|
|
574
|
+
url.searchParams.set("input", serializedInput);
|
|
575
|
+
return { init: { headers, method: "GET" }, url };
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
init: {
|
|
579
|
+
body: serializedInput,
|
|
580
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
581
|
+
method: "POST"
|
|
582
|
+
},
|
|
583
|
+
url
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
__name(buildRequest, "buildRequest");
|
|
563
587
|
async function callPublicContract({ fetch: localFetch, log }, apiConfig, {
|
|
564
588
|
contract,
|
|
565
589
|
input
|
|
566
590
|
}) {
|
|
567
|
-
const
|
|
591
|
+
const { init, url } = buildRequest(apiConfig, contract, input);
|
|
568
592
|
let bodyText;
|
|
569
593
|
try {
|
|
570
|
-
const response = await localFetch(
|
|
571
|
-
new URL(`/api/trpc/${procedurePath}`, apiConfig.serviceBase),
|
|
572
|
-
{
|
|
573
|
-
// The server's superjson transformer reads the input from `json`.
|
|
574
|
-
body: JSON.stringify({ json: input }),
|
|
575
|
-
headers: {
|
|
576
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
577
|
-
"Content-Type": "application/json",
|
|
578
|
-
"User-Agent": apiConfig.userAgent
|
|
579
|
-
},
|
|
580
|
-
method: "POST"
|
|
581
|
-
}
|
|
582
|
-
);
|
|
594
|
+
const response = await localFetch(url, init);
|
|
583
595
|
if (!response.ok) return readHttpError(response, contract.name, log);
|
|
584
596
|
bodyText = await response.text();
|
|
585
597
|
} catch {
|
|
@@ -1370,8 +1382,96 @@ async function reportDeployment(deps, apiConfig, params) {
|
|
|
1370
1382
|
}
|
|
1371
1383
|
__name(reportDeployment, "reportDeployment");
|
|
1372
1384
|
|
|
1373
|
-
// src/lib/sdk/domain/
|
|
1385
|
+
// src/lib/sdk/domain/uploadBuild/index.ts
|
|
1386
|
+
import { openAsBlob } from "node:fs";
|
|
1387
|
+
import { stat } from "node:fs/promises";
|
|
1388
|
+
import { basename } from "node:path";
|
|
1374
1389
|
import { publicContractsV1 as publicContractsV15 } from "@qawolf/api-contracts";
|
|
1390
|
+
var uploadTimeoutMs = 30 * 60 * 1e3;
|
|
1391
|
+
async function openBuildFile(filePath) {
|
|
1392
|
+
try {
|
|
1393
|
+
const stats = await stat(filePath);
|
|
1394
|
+
return stats.isFile() ? await openAsBlob(filePath) : void 0;
|
|
1395
|
+
} catch {
|
|
1396
|
+
return void 0;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
__name(openBuildFile, "openBuildFile");
|
|
1400
|
+
async function putFile({ fetch }, {
|
|
1401
|
+
body,
|
|
1402
|
+
uploadHeaders,
|
|
1403
|
+
uploadUrl
|
|
1404
|
+
}) {
|
|
1405
|
+
try {
|
|
1406
|
+
const response = await fetch(uploadUrl, {
|
|
1407
|
+
body,
|
|
1408
|
+
headers: uploadHeaders,
|
|
1409
|
+
method: "PUT",
|
|
1410
|
+
signal: AbortSignal.timeout(uploadTimeoutMs)
|
|
1411
|
+
});
|
|
1412
|
+
return response.ok ? "ok" : { httpStatus: response.status };
|
|
1413
|
+
} catch {
|
|
1414
|
+
return "network-error";
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
__name(putFile, "putFile");
|
|
1418
|
+
async function uploadBuild(deps, apiConfig, { branch, commitSha, environment, filePath, workspaceId }) {
|
|
1419
|
+
const file = await openBuildFile(filePath);
|
|
1420
|
+
if (file === void 0) {
|
|
1421
|
+
deps.log.error(`\u{1F6AB} ${filePath} is not a readable file, aborting.`);
|
|
1422
|
+
return { filePath, outcome: "file-unreadable" };
|
|
1423
|
+
}
|
|
1424
|
+
const fileSizeBytes = file.size;
|
|
1425
|
+
const requested = await callPublicContract(deps, apiConfig, {
|
|
1426
|
+
contract: publicContractsV15.build.requestUpload,
|
|
1427
|
+
input: { fileName: basename(filePath), fileSizeBytes, workspaceId }
|
|
1428
|
+
});
|
|
1429
|
+
if (requested.outcome !== "ok")
|
|
1430
|
+
return { ...mapPublicApiFailure(requested), failedStep: "request-upload" };
|
|
1431
|
+
const { buildId, uploadHeaders, uploadUrl } = requested.data;
|
|
1432
|
+
deps.log.info(
|
|
1433
|
+
`Uploading ${basename(filePath)} (${fileSizeBytes} bytes) as build ${buildId}.`
|
|
1434
|
+
);
|
|
1435
|
+
const uploaded = await putFile(deps, {
|
|
1436
|
+
body: file,
|
|
1437
|
+
uploadHeaders,
|
|
1438
|
+
uploadUrl
|
|
1439
|
+
});
|
|
1440
|
+
if (uploaded === "network-error") {
|
|
1441
|
+
deps.log.error(`\u{1F6AB} Network error while uploading build ${buildId}.`);
|
|
1442
|
+
return { buildId, outcome: "upload-network-error" };
|
|
1443
|
+
}
|
|
1444
|
+
if (uploaded !== "ok") {
|
|
1445
|
+
deps.log.error(
|
|
1446
|
+
`\u{1F6AB} Storage refused the upload of build ${buildId} (HTTP status ${uploaded.httpStatus}).`
|
|
1447
|
+
);
|
|
1448
|
+
return {
|
|
1449
|
+
buildId,
|
|
1450
|
+
httpStatus: uploaded.httpStatus,
|
|
1451
|
+
outcome: "upload-rejected"
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
const created = await callPublicContract(deps, apiConfig, {
|
|
1455
|
+
contract: publicContractsV15.build.create,
|
|
1456
|
+
input: { branch, buildId, commitSha, environment, workspaceId }
|
|
1457
|
+
});
|
|
1458
|
+
if (created.outcome !== "ok") {
|
|
1459
|
+
return {
|
|
1460
|
+
...mapPublicApiFailure(created),
|
|
1461
|
+
buildId,
|
|
1462
|
+
failedStep: "create"
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
const { build } = created.data;
|
|
1466
|
+
deps.log.info(
|
|
1467
|
+
`\u2705 Build ${build.id} (${build.appId}, ${build.platform}) uploaded: ${build.url}`
|
|
1468
|
+
);
|
|
1469
|
+
return { build, outcome: "uploaded" };
|
|
1470
|
+
}
|
|
1471
|
+
__name(uploadBuild, "uploadBuild");
|
|
1472
|
+
|
|
1473
|
+
// src/lib/sdk/domain/waitForVerdict/awaitRuns.ts
|
|
1474
|
+
import { publicContractsV1 as publicContractsV16 } from "@qawolf/api-contracts";
|
|
1375
1475
|
|
|
1376
1476
|
// src/lib/sdk/domain/waitForVerdict/failures.ts
|
|
1377
1477
|
function handleCallFailure(failure, deploymentId) {
|
|
@@ -1607,7 +1707,7 @@ async function awaitRuns(ctx) {
|
|
|
1607
1707
|
};
|
|
1608
1708
|
},
|
|
1609
1709
|
request: /* @__PURE__ */ __name(() => callPublicContract(ctx.deps, ctx.apiConfig, {
|
|
1610
|
-
contract:
|
|
1710
|
+
contract: publicContractsV16.deployment.listTriggerEvaluations,
|
|
1611
1711
|
input: { deploymentId }
|
|
1612
1712
|
}), "request")
|
|
1613
1713
|
});
|
|
@@ -1615,7 +1715,7 @@ async function awaitRuns(ctx) {
|
|
|
1615
1715
|
__name(awaitRuns, "awaitRuns");
|
|
1616
1716
|
|
|
1617
1717
|
// src/lib/sdk/domain/waitForVerdict/awaitVerdict.ts
|
|
1618
|
-
import { publicContractsV1 as
|
|
1718
|
+
import { publicContractsV1 as publicContractsV17 } from "@qawolf/api-contracts";
|
|
1619
1719
|
var settledStatuses = ["passed", "failed", "canceled", "superseded"];
|
|
1620
1720
|
function isSettled(run) {
|
|
1621
1721
|
return settledStatuses.includes(run.status);
|
|
@@ -1653,7 +1753,7 @@ async function requestRuns(ctx, matched) {
|
|
|
1653
1753
|
const answers = await Promise.all(
|
|
1654
1754
|
matched.map(async (run) => ({
|
|
1655
1755
|
result: await callPublicContract(ctx.deps, ctx.apiConfig, {
|
|
1656
|
-
contract:
|
|
1756
|
+
contract: publicContractsV17.run.get,
|
|
1657
1757
|
// A suite can hold hundreds of flows and the verdict reads none of
|
|
1658
1758
|
// them, so ask for the smallest list the contract allows.
|
|
1659
1759
|
input: { flowStatuses: ["failed"], runId: run.runId }
|
|
@@ -1863,7 +1963,8 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
|
|
|
1863
1963
|
pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig),
|
|
1864
1964
|
promotion: {
|
|
1865
1965
|
get: getPromotion.bind(null, deps, apiConfig)
|
|
1866
|
-
}
|
|
1966
|
+
},
|
|
1967
|
+
uploadBuild: uploadBuild.bind(null, deps, apiConfig)
|
|
1867
1968
|
};
|
|
1868
1969
|
}
|
|
1869
1970
|
__name(makeQaWolfSdk, "makeQaWolfSdk");
|