Fork me on GitHub
#clojars
<
2022-04-01
>
borkdude19:04:33

Is it possible given a snapshot-derived version like clj-kondo/clj-kondo 2022.03.10-20220331.135739-32 to retrieve the git SHA for this version, e.g. through the clojars API?

borkdude19:04:45

The reason I'm asking, and this may be a case of x-y problem, is that clojure-lsp regularly uses -SNAPSHOT versions for their (binary) (with the date substituted for -SNAPSHOT as clojars produces it after deploying) builds as often they contain analysis updates that are interesting for them, but not so interesting for end users of clj-kondo (so I'd rather wait with a release for that audience until it has more features). I write a file like CLJ_KONDO_VERSION so tools can grab that from the classpath and know the version, but since this has 2022.03-10-SNAPSHOT inside clojure-lsp, it's not very specific. So maybe retrieving the SHA using the 2022.03.10-20220331.135739-32 -shaped version can help.

🙏 1
borkdude19:04:03

@UKFSJSM38 clojure-lsp could include this:

(def kondo-pom (slurp (io/resource "META-INF/maven/clj-kondo/clj-kondo/pom.xml")))

borkdude19:04:32

and then grab the tag from there:

<scm>
    <url></url>
    <connection>scm:git:</connection>
    <developerConnection>scm:git:</developerConnection>
    <tag>8937af7f4372c0d2264735ebc1439d0b61030872</tag>

borkdude19:04:39

and then print this in the version output

ericdallo19:04:19

oh, xml parsing no 🏃 😂

ericdallo19:04:26

yeah, that would probably be a valid workaround

borkdude19:04:13

I know you're not supposed to use regexes for that, but:

user=> (second (re-find #"<tag>(.*)</tag>" xml))
"8937af7f4372c0d2264735ebc1439d0b61030872"

🤯 1
ericdallo19:04:28

yeah, the regex sounds simple, for now 😂 If there is no such way to retrieve that from clojars I think we could try that

phronmophobic19:04:32

but you still have to parse xml

phronmophobic19:04:59

Assuming you've already found this, but the API docs are a little hard to find, https://github.com/clojars/clojars-web/wiki/Data

borkdude19:04:11

Here is a babashka script which prints the github sha given a clojure-lsp version:

$ bb -e "(babashka.deps/add-deps '{:deps {com.github.clojure-lsp/clojure-lsp {:mvn/version \"2022.03.31-20.00.20\"}}})" -e "(require '[ :as io])" -e '(def xml (slurp (io/resource "META-INF/maven/clj-kondo/clj-kondo/pom.xml")))' -e '(second (re-find #"<tag>(.*)</tag>" xml))'
"3973aedec333ef5d773bf6446f36abf8a47cec96"

babashka 1
borkdude19:04:50

since bb also contains clojure.data.xml, you could also do it properly

borkdude19:04:51

@U7RJTCH6J Thanks, I always forget where to find those

tcrawley20:04:53

Clojars doesn't extract the SHAs and store them, so no API call will return them currently. Clojars also doesn't treat individual SNAPSHOT deploys as different versions at the db level - that individuality only exists in the repo. As far as the API docs being hard to find, I agree, that's not great. Maybe I should add a link to them in the footer? Also open to other suggestions.

borkdude20:04:16

yes, footer would be great

borkdude20:04:27

that's where I tried to find them

tcrawley20:04:58

https://github.com/clojars/clojars-web/issues/824 I'll try to get to that this weekend

❤️ 2
eskos07:04:53

The https://github.com/esuomi/lein-git-revisions plugin I made recently deals a lot with stuff like this; in fact the primary reason it has the ability to generate metadata file into project resources is to include the git metadata into generated JAR. Now this is very tangential to what is being asked, of course, but my point is - I wrote the plugin on purpose in such a way that the Leiningen plugin integration is largely irrelevant after the first few lines. Feels free to grab whatever you need from there if you find it useful 🙂