Last active
November 2, 2020 18:15
-
-
Save justone/87918a0ca5ab65575d94bc6a127aa48e to your computer and use it in GitHub Desktop.
Script to grab artifacts for a given CircleCI project. Call like this: ./circle-artifacts github borkdude grasp linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(require '[babashka.curl :as curl]) | |
(require '[cheshire.core :as json]) | |
(def recent-build-count 40) | |
(defn recent-builds-url | |
[ci user project limit status] | |
(str "https://circleci.com/api/v1.1/project/" ci "/" user "/" project "?limit=" limit "&filter=" status)) | |
(defn artifacts-url | |
[ci user project build-num] | |
(str "https://circleci.com/api/v1.1/project/" ci "/" user "/" project "/" build-num "/artifacts")) | |
(defn parse-body-json | |
[response] | |
(-> response :body (json/parse-string true))) | |
(defn find-build-num-for | |
[builds job-name] | |
(some->> builds | |
(filter #(= job-name (-> % :workflows :job_name))) | |
first | |
:build_num)) | |
(defn artifacts-for | |
[ci user project job-name] | |
(let [recent-builds (-> (recent-builds-url ci user project recent-build-count "completed") | |
(curl/get) | |
(parse-body-json)) | |
recent-job-build-num (find-build-num-for recent-builds job-name) | |
artifact-urls (when recent-job-build-num | |
(-> (artifacts-url ci user project recent-job-build-num) | |
(curl/get) | |
(parse-body-json)))] | |
artifact-urls)) | |
(when-not (System/getenv "DEV") | |
(if-not (= 4 (count *command-line-args*)) | |
(println "usage: circle-artifacts [ci] [user] [project] [job-name]") | |
(->> (apply artifacts-for *command-line-args*) | |
(map :url) | |
(run! println)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment