Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from felixb/latest-link
Browse files Browse the repository at this point in the history
resolve paths with build number `latest` to last available artifact, …
  • Loading branch information
flosell authored Jun 22, 2016
2 parents cfc08e7 + c3ccfd6 commit eec63a3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## next

* resolve paths with build number `latest` to last available artifact

## 0.1.0

First release
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ browser.
(context artifacts-path-context [] (artifacts/artifact-handler-for pipeline)))))
```

Paths to the artifacts will be stored under the `:details` key in the step result and displayed in the UI.
Paths to the artifacts will be stored under the `:details` key in the step result and displayed in the UI.
The latest available artifact is served under `/latest/$step-id/...` as well.

For a full example, see [test/lambdacd_artifacts/sample_pipeline.clj](test/lambdacd_artifacts/sample_pipeline.clj)

Expand Down
12 changes: 11 additions & 1 deletion src/lambdacd_artifacts/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
(:import (java.io File)
(java.nio.file Paths)))

(defn- find-latest-artifact [home-dir step-id path]
(let [home-file (io/file home-dir)
build-directories (.listFiles home-file)
latest-build-directory (last (filter #(.exists (io/file % step-id path)) build-directories))]
(io/file latest-build-directory step-id)))

(defn root-path [home-dir build-number step-id path]
(if (= build-number "latest")
(find-latest-artifact home-dir step-id path)
(io/file home-dir (str build-number) step-id)))

(defn file-result [home-dir build-number step-id path]
(let [root (io/file home-dir (str build-number) step-id)
(let [root (root-path home-dir build-number step-id path)
file-response (response/file-response path {:root (str root)})]
(if file-response
file-response
Expand Down
13 changes: 12 additions & 1 deletion test/lambdacd_artifacts/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
[ring.mock.request :as mock]
[lambdacd.util :as util]))

(deftest root-path-test
(let [home-dir (util/create-temp-dir)]
(spit (file-with-parents home-dir "1" "some-step-id" "some-artifact.txt") "uber content")
(spit (file-with-parents home-dir "2" "some-step-id" "some-artifact.txt") "uber content")
(spit (file-with-parents home-dir "3" "some-step-id" "some-other-artifact.txt") "not so uber content")
(spit (file-with-parents home-dir "4" "some-other-step-id" "some-artifact.txt") "what do you care?")

(testing "that explicit build-number selection works"
(is (= (io/file home-dir "1" "some-step-id") (root-path home-dir 1 "some-step-id" "some-artifact.txt"))))
(testing "that 'latest' picks the latest available artifact"
(is (= (io/file home-dir "2" "some-step-id") (root-path home-dir "latest" "some-step-id" "some-artifact.txt"))))))

(defn map-containing [expected m]
(and (every? (set (keys m)) (keys expected))
(every? #(= (m %)(expected %)) (keys expected))))


(defn- ctx-with [home-dir build-number step-id artifacts-context]
{:config {:home-dir home-dir
:artifacts-path-context artifacts-context}
Expand Down

0 comments on commit eec63a3

Please sign in to comment.