UNPKG

@jameslnewell/buildkite-pipelines

Version:
343 lines 14.9 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var _CommandStep_commands, _CommandStep_plugins, _CommandStep_keyHelper, _CommandStep_labelHelper, _CommandStep_conditionHelper, _CommandStep_branchesHelper, _CommandStep_dependenciesHelper, _CommandStep_skipHelper, _CommandStep_agentsHelper, _CommandStep_envHelper, _CommandStep_concurrency, _CommandStep_concurrencyGroup, _CommandStep_parallelism, _CommandStep_softFail, _CommandStep_timeoutInMinutes, _CommandStep_automaticRetries, _CommandStep_manualRetry; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandStep = void 0; const key_1 = require("./helpers/key"); const label_1 = require("./helpers/label"); const condition_1 = require("./helpers/condition"); const branches_1 = require("./helpers/branches"); const dependencies_1 = require("./helpers/dependencies"); const skip_1 = require("./helpers/skip"); const isPluginBuilder_1 = require("./isPluginBuilder"); const agents_1 = require("./helpers/agents"); const env_1 = require("./helpers/env"); class CommandStep { constructor() { _CommandStep_commands.set(this, void 0); _CommandStep_plugins.set(this, []); _CommandStep_keyHelper.set(this, new key_1.KeyHelper()); _CommandStep_labelHelper.set(this, new label_1.LabelHelper()); _CommandStep_conditionHelper.set(this, new condition_1.ConditionHelper()); _CommandStep_branchesHelper.set(this, new branches_1.BranchFilterHelper()); _CommandStep_dependenciesHelper.set(this, new dependencies_1.DependenciesHelper()); _CommandStep_skipHelper.set(this, new skip_1.SkipHelper()); _CommandStep_agentsHelper.set(this, new agents_1.AgentsHelper()); _CommandStep_envHelper.set(this, new env_1.EnvironmentHelper()); _CommandStep_concurrency.set(this, void 0); _CommandStep_concurrencyGroup.set(this, void 0); _CommandStep_parallelism.set(this, void 0); _CommandStep_softFail.set(this, void 0); _CommandStep_timeoutInMinutes.set(this, void 0); _CommandStep_automaticRetries.set(this, []); _CommandStep_manualRetry.set(this, void 0); } getCommands() { var _a; return [...((_a = __classPrivateFieldGet(this, _CommandStep_commands, "f")) !== null && _a !== void 0 ? _a : [])]; } /** * @deprecated Use .addCommand() instead */ command(command) { return this.addCommand(command); } addCommand(command) { if (!__classPrivateFieldGet(this, _CommandStep_commands, "f")) { __classPrivateFieldSet(this, _CommandStep_commands, [], "f"); } __classPrivateFieldGet(this, _CommandStep_commands, "f").push(command); return this; } getKey() { return __classPrivateFieldGet(this, _CommandStep_keyHelper, "f").getKey(); } /** * @deprecated Use .setKey() instead */ key(key) { return this.setKey(key); } setKey(key) { __classPrivateFieldGet(this, _CommandStep_keyHelper, "f").setKey(key); return this; } getLabel() { return __classPrivateFieldGet(this, _CommandStep_labelHelper, "f").getLabel(); } /** * @deprecated Use .setLabel() instead */ label(label) { return this.setLabel(label); } setLabel(label) { __classPrivateFieldGet(this, _CommandStep_labelHelper, "f").setLabel(label); return this; } getCondition() { return __classPrivateFieldGet(this, _CommandStep_conditionHelper, "f").getCondition(); } /** * @deprecated Use .setCondition() instead */ condition(condition) { return this.setCondition(condition); } setCondition(condition) { __classPrivateFieldGet(this, _CommandStep_conditionHelper, "f").setCondition(condition); return this; } getBranches() { return __classPrivateFieldGet(this, _CommandStep_branchesHelper, "f").getBranches(); } /** * @deprecated Use .addBranch() instead */ branch(branch) { return this.addBranch(branch); } addBranch(branch) { __classPrivateFieldGet(this, _CommandStep_branchesHelper, "f").addBranch(branch); return this; } getDependencies() { return __classPrivateFieldGet(this, _CommandStep_dependenciesHelper, "f").getDependencies(); } /** * @deprecated Use .addDependency() instead */ dependOn(dependency) { return this.addDependency(dependency); } addDependency(dependency) { __classPrivateFieldGet(this, _CommandStep_dependenciesHelper, "f").addDependency(dependency); return this; } /** * @deprecated Use .addDependency() instead */ allowDependencyFailure(allow) { return this.setAllowDependencyFailure(allow); } setAllowDependencyFailure(allow) { __classPrivateFieldGet(this, _CommandStep_dependenciesHelper, "f").setAllowDependencyFailure(allow); return this; } getSkip() { return __classPrivateFieldGet(this, _CommandStep_skipHelper, "f").getSkip(); } /** * @deprecated Use .setSkip() instead */ skip(skip) { return this.setSkip(skip); } setSkip(skip) { __classPrivateFieldGet(this, _CommandStep_skipHelper, "f").setSkip(skip); return this; } getPlugins() { // 🤔 not sure we want to allow mutation of the plugins yet return [...__classPrivateFieldGet(this, _CommandStep_plugins, "f")]; } /** * @deprecated Use .addPlugin() instead */ plugin(plugin) { return this.addPlugin(plugin); } addPlugin(plugin) { __classPrivateFieldGet(this, _CommandStep_plugins, "f").push(plugin); return this; } /** * @deprecated Use .addPlugins() instead */ plugins(plugins) { return this.addPlugins(plugins); } addPlugins(plugins) { __classPrivateFieldGet(this, _CommandStep_plugins, "f").push(...plugins); return this; } getParallelism() { return __classPrivateFieldGet(this, _CommandStep_parallelism, "f"); } /** * @deprecated Use .setParallelism() instead */ parallelism(parallelism) { return this.setParallelism(parallelism); } setParallelism(parallelism) { if (parallelism === 0) { throw new Error('Parallelism of zero will result in step being omitted'); } __classPrivateFieldSet(this, _CommandStep_parallelism, parallelism, "f"); return this; } getEnv() { return __classPrivateFieldGet(this, _CommandStep_envHelper, "f").getEnv(); } /** * @deprecated Use .addEnv() instead */ env(name, value) { return this.addEnv(name, value); } addEnv(name, value) { __classPrivateFieldGet(this, _CommandStep_envHelper, "f").addEnv(name, value); return this; } /** * @see https://buildkite.com/docs/pipelines/configure/workflows/controlling-concurrency#concurrency-limits */ getConcurrency() { return __classPrivateFieldGet(this, _CommandStep_concurrency, "f"); } /** * @deprecated Use .setConcurrency() instead */ concurrency(group, jobs) { return this.setConcurrency(group, jobs); } setConcurrency(concurrencyGroupOrConcurrency, concurrency) { if (typeof concurrencyGroupOrConcurrency === 'string' && typeof concurrency === 'number') { if (concurrency === 0) { throw new Error('Concurrency of zero will result in step which never starts'); } __classPrivateFieldSet(this, _CommandStep_concurrencyGroup, concurrencyGroupOrConcurrency, "f"); __classPrivateFieldSet(this, _CommandStep_concurrency, concurrency, "f"); } else if (typeof concurrencyGroupOrConcurrency === 'number') { if (concurrencyGroupOrConcurrency === 0) { throw new Error('Concurrency of zero will result in step which never starts'); } __classPrivateFieldSet(this, _CommandStep_concurrency, concurrencyGroupOrConcurrency, "f"); } else { throw new Error('Invalid arguments for setConcurrency'); } return this; } /** * * @see https://buildkite.com/docs/pipelines/configure/workflows/controlling-concurrency#concurrency-groups */ getConcurrencyGroup() { return __classPrivateFieldGet(this, _CommandStep_concurrencyGroup, "f"); } /** * @see https://buildkite.com/docs/pipelines/configure/workflows/controlling-concurrency#concurrency-groups */ setConcurrencyGroup(group) { __classPrivateFieldSet(this, _CommandStep_concurrencyGroup, group, "f"); return this; } getSoftFail() { return __classPrivateFieldGet(this, _CommandStep_softFail, "f"); } /** * @deprecated Use .setSoftFail() instead */ softFail(fail = true) { return this.setSoftFail(fail); } setSoftFail(fail) { __classPrivateFieldSet(this, _CommandStep_softFail, fail, "f"); return this; } getTimeout() { return __classPrivateFieldGet(this, _CommandStep_timeoutInMinutes, "f"); } /** * @deprecated Use .setTimeout() instead */ timeout(minutes) { return this.setTimeout(minutes); } setTimeout(minutes) { __classPrivateFieldSet(this, _CommandStep_timeoutInMinutes, minutes, "f"); return this; } getAgents() { return __classPrivateFieldGet(this, _CommandStep_agentsHelper, "f").getAgents(); } /** * @deprecated Use .addAgent() instead */ agent(tag, value) { return this.addAgent(tag, value); } addAgent(tag, value) { __classPrivateFieldGet(this, _CommandStep_agentsHelper, "f").addAgent(tag, value); return this; } getManualRetry() { return __classPrivateFieldGet(this, _CommandStep_manualRetry, "f"); } setManualRetry(retry) { __classPrivateFieldSet(this, _CommandStep_manualRetry, retry, "f"); return this; } getAutomaticRetries() { return __classPrivateFieldGet(this, _CommandStep_automaticRetries, "f"); } addAutomaticRetry(retry) { __classPrivateFieldGet(this, _CommandStep_automaticRetries, "f").push(retry); return this; } async build() { const object = { ...{ commands: __classPrivateFieldGet(this, _CommandStep_commands, "f") }, ...__classPrivateFieldGet(this, _CommandStep_keyHelper, "f").build(), ...__classPrivateFieldGet(this, _CommandStep_labelHelper, "f").build(), ...__classPrivateFieldGet(this, _CommandStep_conditionHelper, "f").build(), ...__classPrivateFieldGet(this, _CommandStep_branchesHelper, "f").build(), ...__classPrivateFieldGet(this, _CommandStep_dependenciesHelper, "f").build(), ...__classPrivateFieldGet(this, _CommandStep_skipHelper, "f").build(), ...(__classPrivateFieldGet(this, _CommandStep_parallelism, "f") ? { parallelism: __classPrivateFieldGet(this, _CommandStep_parallelism, "f") } : {}), ...(__classPrivateFieldGet(this, _CommandStep_concurrency, "f") ? { concurrency: __classPrivateFieldGet(this, _CommandStep_concurrency, "f") } : {}), ...(__classPrivateFieldGet(this, _CommandStep_concurrencyGroup, "f") ? { concurrency_group: __classPrivateFieldGet(this, _CommandStep_concurrencyGroup, "f") } : {}), ...__classPrivateFieldGet(this, _CommandStep_envHelper, "f").build(), ...(__classPrivateFieldGet(this, _CommandStep_softFail, "f") ? { soft_fail: __classPrivateFieldGet(this, _CommandStep_softFail, "f") } : {}), ...(__classPrivateFieldGet(this, _CommandStep_timeoutInMinutes, "f") ? { timeout_in_minutes: __classPrivateFieldGet(this, _CommandStep_timeoutInMinutes, "f") } : {}), ...__classPrivateFieldGet(this, _CommandStep_agentsHelper, "f").build(), }; if (__classPrivateFieldGet(this, _CommandStep_manualRetry, "f") !== undefined) { object.retry = { ...object.retry, manual: __classPrivateFieldGet(this, _CommandStep_manualRetry, "f"), }; } if (__classPrivateFieldGet(this, _CommandStep_automaticRetries, "f").length) { object.retry = { ...object.retry, automatic: __classPrivateFieldGet(this, _CommandStep_automaticRetries, "f"), }; } if (__classPrivateFieldGet(this, _CommandStep_plugins, "f").length > 0) { object.plugins = await Promise.all(__classPrivateFieldGet(this, _CommandStep_plugins, "f").map(async (plugin) => (0, isPluginBuilder_1.isPluginBuilder)(plugin) ? await plugin.build() : plugin)); } return object; } } exports.CommandStep = CommandStep; _CommandStep_commands = new WeakMap(), _CommandStep_plugins = new WeakMap(), _CommandStep_keyHelper = new WeakMap(), _CommandStep_labelHelper = new WeakMap(), _CommandStep_conditionHelper = new WeakMap(), _CommandStep_branchesHelper = new WeakMap(), _CommandStep_dependenciesHelper = new WeakMap(), _CommandStep_skipHelper = new WeakMap(), _CommandStep_agentsHelper = new WeakMap(), _CommandStep_envHelper = new WeakMap(), _CommandStep_concurrency = new WeakMap(), _CommandStep_concurrencyGroup = new WeakMap(), _CommandStep_parallelism = new WeakMap(), _CommandStep_softFail = new WeakMap(), _CommandStep_timeoutInMinutes = new WeakMap(), _CommandStep_automaticRetries = new WeakMap(), _CommandStep_manualRetry = new WeakMap(); //# sourceMappingURL=CommandStep.js.map