Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Boot tasks and helper functions to create Sentry releases and attach source maps to them
(ns dev.boot-sentry
(:require [boot.util :as util]
[boot.core :as boot]
[clojure.data.json :as json]
[org.httpkit.client :as http]))
(def sentry-key "abc")
(def org "my-org")
(def project "frontend")
(def test-release "test-release-delete-me")
(defn delete-release' [org project version]
@(http/delete
(str "https://sentry.io/api/0/projects/" org "/" project "/releases/" version "/")
{:headers {"Authorization" (str "Bearer " sentry-key)}}))
(defn create-release [org project release]
@(http/post
(str "https://sentry.io/api/0/projects/" org "/" project "/releases/")
{:headers {"Authorization" (str "Bearer " sentry-key)
"Content-Type" "application/json"}
:body (json/write-str {:version release})}))
(defn upload-source-map [org project release file remote]
@(http/post
(str "https://sentry.io/api/0/projects/" org "/" project "/releases/" release "/files/")
{:headers {"Authorization" (str "Bearer " sentry-key)}
:multipart [{:name "name" :content remote}
{:name "file" :content file :filename (.getName file)}]}))
(boot/deftask sentry-release
[o org ORG str "Sentry organization identifier"
p project PROJECT str "The Sentry project slug"
r release RELEASE str "The release identifier to use in Sentry"
f files REMOTE=FILE {str str}"Full path to the source map file inside the fileset"]
(boot/with-pre-wrap fs
(assert org "org option is required")
(assert project "project option is required")
(assert release "release option is required")
(util/info "Creating Sentry release in project %s\n" project)
(util/info "• creating release %s\n" release)
(let [release-resp (create-release org project release)]
(if (= 201 (:status release-resp))
(doseq [[remote file] files]
(util/info "• uploading source map file %s as %s... " file remote)
(let [candidates (boot/output-files fs)
map-file (first (boot/by-path [file] candidates))
res (upload-source-map org project release (boot/tmp-file map-file) remote)]
(util/info "HTTP Status: %s\n" (:status res))
(when-not (= 201 (:status res))
(util/fail "Failed to upload %s\n" res))))
(util/fail "Failed to create release %s\n" release-resp)))
fs))
(boot/deftask delete-release
[o org ORG str "Sentry organization identifier"
p project PROJECT str "The Sentry project slug"
r release RELEASE [str] "The release identifier to use in Sentry"]
(boot/with-pre-wrap fs
(util/info "Deleting Sentry release\n")
(doseq [r release]
(util/info "• deleting release %s\n" r)
(delete-release' org project r))
fs))
(sentry-release :release "0.0.1234" ;app-version
:files {"~/web.js.map" "public/web.js.map"
"~/functions.js.map" "public/functions.js.map"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.