We provide the @qawolf/ci-sdk
NPM package to handle most of the integration work for you. This script integrates with the two endpoints currently available, and provides one async function for each:
pollCiGreenlightStatus
)attemptNotifyDeploy
)The package features TypeScript definitions, ESM and CJS module interoperability. See the NPM package page for more information.
<aside>
ℹ️ We recommend using the ^
npm range operator to get on-the-fly fixes. The SDK package follows SemVer. Learn more about stability guarantees in the official NPM package page.
</aside>
attemptNotifyDeploy
<aside>
⚠️ Please refer to Choosing Fields Based on Your Setup to properly set up the DeployConfig
object.
</aside>
import { type DeployConfig, makeQaWolfSdk } from "@qawolf/ci-sdk";
// Edit this to your needs.
const deployConfig: DeployConfig = {
sha: undefined, // Recomended
branch: undefined, // Recommended
commitUrl: undefined, // Recommended
deploymentType: undefined, // "accounting"
deduplicationKey: undefined, // Not needed
deploymentUrl: undefined, // Not needed
hostingService: undefined, // Not needed
variables: undefined, // Not needed
};
const { attemptNotifyDeploy } = makeQaWolfSdk({
apiKey: "qawolf_xxxxx"
});
(async () => {
const result = await attemptNotifyDeploy(deployConfig);
if (result.outcome !== "success") {
// Fail the job.
process.exit(1);
}
const runId = result.runId;
// Store the runId as an output of the job to be used in a CI-greenlight job.
// This will depend on the CI platform you are using.
})();
pollCiGreenlightStatus
import { makeQaWolfSdk } from "@qawolf/ci-sdk";
const { pollCiGreenlightStatus } = makeQaWolfSdk({
apiKey: "qawolf_xxxxx",
});
(async () => {
// Retrieve runId from the previous job.
const { outcome } = await pollCiGreenlightStatus({
runId,
// Optional: Callback to be called when the run stage changes.
onRunStageChanged: (current, previous) => {
console.log(current, previous);
},
// Optional: abort the job when a superseding run is encountered.
// Default "false"
abortOnSuperseded: false,
// EXPERIMENTAL!
// Optional: Defaults to "green".
// When set to `"red"`, the job will fail when blocking bugs were
// found in the environment that were affecting workflows not executed
// in the run.
outcomeWhenBlockingBugsInOtherWorkflows: "green",
});
if (outcome !== "success") {
// Fail the job.
// This will depend on the CI platform you are using.
// You can also distinguish between "failed" and "aborted" outcomes.
// Only "failed" outcome indicates bugs were found.
process.exit(1);
}
// Continue CI.
})();
<aside>
ℹ️ You can inspect the outcome.ciGreenlightStatus
object when the outcome is "success"
. It will provide ample details on the results of the run. See 200 Response (CI Greenlight status).
</aside>
experimental_vcsBranchTesting
See the page below: