@qawolf/ci-sdk 3.4.1 → 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 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)
@@ -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,11 @@ 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
+
916
965
  ## v3.4.1
917
966
 
918
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`.
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.4.1",
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.89.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",
@@ -1382,8 +1382,96 @@ async function reportDeployment(deps, apiConfig, params) {
1382
1382
  }
1383
1383
  __name(reportDeployment, "reportDeployment");
1384
1384
 
1385
- // src/lib/sdk/domain/waitForVerdict/awaitRuns.ts
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";
1386
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";
1387
1475
 
1388
1476
  // src/lib/sdk/domain/waitForVerdict/failures.ts
1389
1477
  function handleCallFailure(failure, deploymentId) {
@@ -1619,7 +1707,7 @@ async function awaitRuns(ctx) {
1619
1707
  };
1620
1708
  },
1621
1709
  request: /* @__PURE__ */ __name(() => callPublicContract(ctx.deps, ctx.apiConfig, {
1622
- contract: publicContractsV15.deployment.listTriggerEvaluations,
1710
+ contract: publicContractsV16.deployment.listTriggerEvaluations,
1623
1711
  input: { deploymentId }
1624
1712
  }), "request")
1625
1713
  });
@@ -1627,7 +1715,7 @@ async function awaitRuns(ctx) {
1627
1715
  __name(awaitRuns, "awaitRuns");
1628
1716
 
1629
1717
  // src/lib/sdk/domain/waitForVerdict/awaitVerdict.ts
1630
- import { publicContractsV1 as publicContractsV16 } from "@qawolf/api-contracts";
1718
+ import { publicContractsV1 as publicContractsV17 } from "@qawolf/api-contracts";
1631
1719
  var settledStatuses = ["passed", "failed", "canceled", "superseded"];
1632
1720
  function isSettled(run) {
1633
1721
  return settledStatuses.includes(run.status);
@@ -1665,7 +1753,7 @@ async function requestRuns(ctx, matched) {
1665
1753
  const answers = await Promise.all(
1666
1754
  matched.map(async (run) => ({
1667
1755
  result: await callPublicContract(ctx.deps, ctx.apiConfig, {
1668
- contract: publicContractsV16.run.get,
1756
+ contract: publicContractsV17.run.get,
1669
1757
  // A suite can hold hundreds of flows and the verdict reads none of
1670
1758
  // them, so ask for the smallest list the contract allows.
1671
1759
  input: { flowStatuses: ["failed"], runId: run.runId }
@@ -1875,7 +1963,8 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
1875
1963
  pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig),
1876
1964
  promotion: {
1877
1965
  get: getPromotion.bind(null, deps, apiConfig)
1878
- }
1966
+ },
1967
+ uploadBuild: uploadBuild.bind(null, deps, apiConfig)
1879
1968
  };
1880
1969
  }
1881
1970
  __name(makeQaWolfSdk, "makeQaWolfSdk");