File: ci_publish.clj

package info (click to toggle)
pomegranate-clojure 1.2.24-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: xml: 135; sh: 37; makefile: 17
file content (67 lines) | stat: -rw-r--r-- 2,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(ns ci-publish
  "Publish work we invoke from GitHub Actions.
  Separated out here:
  - to make it clear what is happening on ci
  - rate of change here should be less/different than in publish namespace"
  (:require [babashka.tasks :as t]
            [lread.status-line :as status]
            [build-shared]))

(def ^:private changelog-url (format "https://github.com/%s/blob/master/CHANGELOG.adoc" (build-shared/lib-github-coords)))

(defn- assert-on-ci []
  (when (not (System/getenv "CI"))
    (status/die 1 "to be run from continuous integration server only")))

(defn- ci-tag []
  (when (= "tag" (System/getenv "GITHUB_REF_TYPE"))
    (System/getenv "GITHUB_REF_NAME")))

(defn- analyze-ci-tag []
  (let [tag (ci-tag)]
    (if (not tag)
      (status/die 1 "CI tag not found")
      (let [version-from-tag (build-shared/tag->version tag)
            lib-version (build-shared/lib-version)]
        (cond
          (not version-from-tag)
          (status/die 1 "Not recognized as version tag: %s" tag)

          (not= version-from-tag lib-version)
          (status/die 1 "Lib version %s does not match version from tag %s"
                        lib-version version-from-tag)
          :else
          {:tag tag
           :version lib-version})))))

;;
;; Task entry points
;;

(defn clojars-deploy []
  (assert-on-ci)
  (analyze-ci-tag) ;; fail on unexpected version tag
  (t/shell "clojure -T:build deploy"))

(defn github-create-release []
  (assert-on-ci)
  (let [{:keys [tag]} (analyze-ci-tag)]
    (t/shell "gh release create"
             tag
             "--title" tag
             "--notes" (format "[Changelog](%s#%s)" changelog-url tag))))

(defn cljdoc-request-build []
  (assert-on-ci)
  (let [{:keys [version]} (analyze-ci-tag)
        lib (build-shared/lib-artifact-name)]
    (status/line :head "Informing cljdoc of %s version %s" lib version)
    (assert-on-ci)
    (let [exit-code (->  (t/shell {:continue true}
                                  "curl" "-X" "POST"
                                  "-d" (str "project=" lib)
                                  "-d" (str "version=" version)
                                  "https://cljdoc.org/api/request-build2")
                         :exit)]
      (when (not (zero? exit-code))
        (status/line :warn (str  "Informing cljdoc did not seem to work, exited with " exit-code))))))