|
7 | 7 | (ns ci-release
|
8 | 8 | (:require [clojure.java.io :as io]
|
9 | 9 | [clojure.string :as string]
|
10 |
| - [helper.env :as env] |
11 | 10 | [helper.fs :as fs]
|
| 11 | + [helper.main :as main] |
12 | 12 | [helper.shell :as shell]
|
13 | 13 | [lread.status-line :as status]
|
14 | 14 | [release.version :as version]))
|
|
153 | 153 | (when (not (zero? exit-code))
|
154 | 154 | (status/line :warn (str "Informing cljdoc did not seem to work, exited with " exit-code)))))
|
155 | 155 |
|
156 |
| -(def usage (string/join "\n" |
157 |
| - ["Valid args: <cmd>" |
158 |
| - "" |
159 |
| - "Where cmd can be:" |
160 |
| - " prep update user guide, changelog and create jar" |
161 |
| - " deploy-remote deploy jar to clojars" |
162 |
| - " commit commit changes made back to repo, inform cljdoc of release" |
163 |
| - "" |
164 |
| - "These commands are expected to be run in order from CI." |
165 |
| - "Why the awkward separation?" |
166 |
| - "To restrict the exposure of our CLOJARS secrets during deploy workflow" |
167 |
| - "" |
168 |
| - "Additional commands:" |
169 |
| - " validate verify that change log is good for release" |
170 |
| - " version calculate and report version" |
171 |
| - " --help show this help"])) |
172 |
| - |
173 |
| - |
174 |
| -(defn- validate-args [args] |
175 |
| - (let [cmd (first args)] |
176 |
| - (when (or (not= 1 (count args)) |
177 |
| - (not (some #{cmd} '("prep" "deploy-remote" "commit" "validate" "version" "--help")))) |
178 |
| - (status/die 1 usage)) |
179 |
| - cmd)) |
| 156 | +(def args-usage "Valid args: (prep|deploy-remote|commit|validate|version|--help) |
| 157 | +
|
| 158 | +Commands: |
| 159 | + prep Update user guide, changelog and create jar |
| 160 | + deploy-remote Deploy jar to clojars |
| 161 | + commit Commit changes made back to repo, inform cljdoc of release |
| 162 | +
|
| 163 | +These commands are expected to be run in order from CI. |
| 164 | +Why the awkward separation? |
| 165 | +To restrict the exposure of our CLOJARS secrets during deploy workflow |
| 166 | +
|
| 167 | +Additional commands: |
| 168 | + validate Verify that change log is good for release |
| 169 | + version Calculate and report version |
| 170 | +
|
| 171 | +Options |
| 172 | + --help Show this help") |
180 | 173 |
|
181 | 174 | (defn -main [& args]
|
182 |
| - (let [cmd (validate-args args) |
183 |
| - target-version-filename "target/target-version.txt"] |
184 |
| - (if (= "--help" cmd) |
185 |
| - (status/line :detail usage) |
186 |
| - (do |
187 |
| - (status/line :head (str "Attempting release step: " cmd)) |
188 |
| - (case cmd |
189 |
| - "prep" |
190 |
| - (do (clean!) |
191 |
| - (let [changelog-status (validate-changelog) |
192 |
| - target-version (calculate-version) |
193 |
| - last-version (last-release-tag)] |
194 |
| - (status/line :detail (str "Last version released: " (or last-version "<none>"))) |
195 |
| - (status/line :detail (str "Target version: " target-version)) |
196 |
| - (io/make-parents target-version-filename) |
197 |
| - (spit target-version-filename target-version) |
198 |
| - (update-user-guide! target-version) |
199 |
| - (update-changelog! target-version last-version changelog-status) |
200 |
| - (create-jar! target-version))) |
201 |
| - |
202 |
| - "deploy-remote" |
203 |
| - (deploy-jar!) |
204 |
| - |
205 |
| - "commit" |
206 |
| - (if (not (.exists (io/file target-version-filename))) |
207 |
| - (status/die 1 |
208 |
| - "Target version file not found: %s\nWas prep step run?" |
209 |
| - target-version-filename) |
210 |
| - (let [target-version (slurp target-version-filename)] |
211 |
| - (commit-changes! target-version) |
212 |
| - (inform-cljdoc! target-version))) |
213 |
| - |
214 |
| - "validate" |
215 |
| - (do (validate-changelog) |
216 |
| - nil) |
217 |
| - |
218 |
| - "version" |
219 |
| - (do (calculate-version) |
220 |
| - nil)) |
221 |
| - (status/line :detail (str "Release step done:" cmd)))))) |
222 |
| - |
223 |
| -(env/when-invoked-as-script |
| 175 | + (when-let [opts (main/doc-arg-opt args-usage args)] |
| 176 | + (let [target-version-filename "target/target-version.txt"] |
| 177 | + (cond |
| 178 | + (get opts "prep") |
| 179 | + (do (clean!) |
| 180 | + (let [changelog-status (validate-changelog) |
| 181 | + target-version (calculate-version) |
| 182 | + last-version (last-release-tag)] |
| 183 | + (status/line :detail (str "Last version released: " (or last-version "<none>"))) |
| 184 | + (status/line :detail (str "Target version: " target-version)) |
| 185 | + (io/make-parents target-version-filename) |
| 186 | + (spit target-version-filename target-version) |
| 187 | + (update-user-guide! target-version) |
| 188 | + (update-changelog! target-version last-version changelog-status) |
| 189 | + (create-jar! target-version))) |
| 190 | + |
| 191 | + (get opts "deploy-remote") |
| 192 | + (deploy-jar!) |
| 193 | + |
| 194 | + (get opts "commit") |
| 195 | + (if (not (.exists (io/file target-version-filename))) |
| 196 | + (status/die 1 |
| 197 | + "Target version file not found: %s\nWas prep step run?" |
| 198 | + target-version-filename) |
| 199 | + (let [target-version (slurp target-version-filename)] |
| 200 | + (commit-changes! target-version) |
| 201 | + (inform-cljdoc! target-version))) |
| 202 | + |
| 203 | + (get opts "validate") |
| 204 | + (do (validate-changelog) |
| 205 | + nil) |
| 206 | + |
| 207 | + (get opts "version") |
| 208 | + (do (calculate-version) |
| 209 | + nil))))) |
| 210 | + |
| 211 | +(main/when-invoked-as-script |
224 | 212 | (apply -main *command-line-args*))
|
0 commit comments