UNPKG

2.91 kBPlain TextView Raw
1/*
2 * Copyright © 2019 Atomist, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {
18 GoalSetter,
19 MachineConfiguration,
20 SoftwareDeliveryMachine,
21 SoftwareDeliveryMachineConfiguration,
22} from "@atomist/sdm";
23import { HandlerBasedSoftwareDeliveryMachine } from "../internal/machine/HandlerBasedSoftwareDeliveryMachine";
24import { infoSupport } from "../pack/info/exposeInfo";
25import { jobSupport } from "../pack/job/job";
26
27/**
28 * Create a **Software Delivery MachineConfiguration** with default predefined goals.
29 * Combines commands and delivery event handling using _goals_.
30 *
31 * Goals and goal "implementations" can be defined by users.
32 * However, certain well known goals are built into the DefaultSoftwareDeliveryMachine
33 * for convenience, with their own associated listeners.
34 *
35 * Well known goal support is based around a delivery process spanning
36 * common goals of fingerprinting, reacting to fingerprint diffs,
37 * code review, build, deployment, endpoint verification and
38 * promotion to a production environment.
39 *
40 * The most important element of a software delivery machine is setting
41 * zero or more _push rules_ in the constructor.
42 * This is normally done using the internal DSL as follows:
43 *
44 * ```
45 * const sdm = createSoftwareDeliveryMachine(
46 * "MyMachine",
47 * options,
48 * whenPushSatisfies(IsMaven, HasSpringBootApplicationClass, not(MaterialChangeToJavaRepo))
49 * .itMeans("No material change to Java")
50 * .setGoals(NoGoals),
51 * whenPushSatisfies(ToDefaultBranch, IsMaven, HasSpringBootApplicationClass, HasCloudFoundryManifest)
52 * .itMeans("Spring Boot service to deploy")
53 * .setGoals(HttpServiceGoals));
54 * ```
55 *
56 * Uses the builder pattern to allow fluent construction. For example:
57 *
58 * ```
59 * softwareDeliveryMachine
60 * .addPushReaction(async pu => ...)
61 * .addNewIssueListener(async i => ...)
62 * .add...;
63 * ```
64 */
65export function createSoftwareDeliveryMachine(config: MachineConfiguration<SoftwareDeliveryMachineConfiguration>,
66 ...goalSetters: Array<GoalSetter | GoalSetter[]>)
67 : SoftwareDeliveryMachine<SoftwareDeliveryMachineConfiguration> {
68 const machine = new HandlerBasedSoftwareDeliveryMachine(config.name, config.configuration,
69 goalSetters);
70 machine.addExtensionPacks(infoSupport(), jobSupport());
71
72 return machine;
73}