Skip to content

Instantly share code, notes, and snippets.

@flosell
Last active August 3, 2016 19:22
Show Gist options
  • Save flosell/ed829b8b554c3f7af897de918e3d4e44 to your computer and use it in GitHub Desktop.
Save flosell/ed829b8b554c3f7af897de918e3d4e44 to your computer and use it in GitHub Desktop.
LambdaCD as a CLI - Minimal example
(ns my-first-pipeline.core
(:require
[lambdacd.util :as util]
[lambdacd.core :as lambdacd]
[clojure.tools.logging :as log]
[lambdacd.internal.execution :as execution]
[lambdacd.steps.shell :as shell]
[lambdacd-git.core :as lambdacd-git]
[lambdacd.steps.control-flow :refer [with-workspace]]
[lambdacd.event-bus :as event-bus]
[clojure.core.async :as async])
(:gen-class))
; --- pipeline code ---
(def repo-uri "https://github.com/flosell/lambdacd.git")
(def repo-branch "master")
(defn clone [args ctx]
(lambdacd-git/clone ctx repo-uri repo-branch (:cwd args)))
(defn run-some-tests [args ctx]
(shell/bash ctx (:cwd args) "./go test-clj"))
(def pipeline-def
`((with-workspace
clone
run-some-tests)))
; --- utility to log all step updates ---
(defn log-all-step-result-updates [{ctx :context}]
(let [step-updates-channel (event-bus/only-payload
(event-bus/subscribe ctx :step-result-updated))]
(async/go-loop []
(if-let [step-result-update (async/<! step-updates-channel)]
(do
(log/info step-result-update)
(recur))))))
; --- main function to wire it all together ---
(defn -main [& args]
(let [home-dir (util/create-temp-dir)
config {:home-dir home-dir
:name "my first pipeline"}
pipeline (lambdacd/assemble-pipeline pipeline-def config)]
(log-all-step-result-updates pipeline)
(execution/run (:pipeline-def pipeline) (:context pipeline))))
(defproject my-first-pipeline "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[lambdacd "0.9.3"]
[lambdacd-git "0.1.6"]
[org.clojure/clojure "1.7.0"]
[org.clojure/tools.logging "0.3.0"]
[org.slf4j/slf4j-api "1.7.5"]
[ch.qos.logback/logback-core "1.0.13"]
[ch.qos.logback/logback-classic "1.0.13"]]
:profiles {:uberjar {:aot :all}}
:main my-first-pipeline.core)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment