Skip to content

Instantly share code, notes, and snippets.

@superstructor
Last active December 30, 2019 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superstructor/fd5b8b21e910cbbc384330d28e722e1d to your computer and use it in GitHub Desktop.
Save superstructor/fd5b8b21e910cbbc384330d28e722e1d to your computer and use it in GitHub Desktop.
lein-git-inject.md
  ;; left matched against [ "v0.0.4" ahead? dirty? ]
  ;; right matched against git describe --tags output "v0.0.4-5-ge2028de"
  :lein-git-inject {[#"v\d+\.\d+\.\d+" false? (constantly true)] #"v(\d+\.\d+\.\d+).*"
                    [#"v\d+\.\d+\.\d+" true?  (constantly true)] [#"v(\d+\.\d+\.\d+-\d+-[a-z0-9][8])" "-SNAPSHOT"]}

  ;; same but with static values instead of fns
  ;; except there is an issue with using `_` which is idiomatic syntax as we cannot write as a macro and:
  ;; WARNING: Can't take value of macro cljs.core/_ at line..
  :lein-git-inject-2 {[#"v\d+\.\d+\.\d+" false _] #"v(\d+\.\d+\.\d+).*"
                      [#"v\d+\.\d+\.\d+" true  _] [#"v(\d+\.\d+\.\d+-\d+-[a-z0-9][8])" "-SNAPSHOT"]}


  ;; simpler right side by providing git describe --tags output "v0.0.4-5-ge2028de" as
  ;; %semver v0.0.4
  ;; %ahead 5
  ;; %hash ge2028de
  :lein-git-inject-3 {[#"v\d+\.\d+\.\d+" false _] "%semver"
                      [#"v\d+\.\d+\.\d+" true  _] "%semver-%ahead-%hash-SNAPSHOT"}
@mike-thompson-day8
Copy link

mike-thompson-day8 commented Dec 17, 2019

 :git-inject {

    ;; Provide a regex which will match the textual structure of the git tags your team is using. 
    ;; You can choose whatever tagging scheme you want, but you need to 
    ;; provide a regex which will:
    ;;    1. match this tag structure
    ;;    2. produce a single capturing group to extract the version from a tag 
    ;;
    ;; The following example regex:
    ;;     1. will match tags with a structure like v12.3.9 
    ;;      2. The capturing group will be 12.3.9  (crop the leading "v")

    :regex-for-tag:  #"v?([0-9]*\.[0-9]*\.[0-9]*)"  
   ;;  Note: the regex above is also the default one used, should you not supply one.

  
    ;; A "git describe XXX" will essentially return the "status of git' as a vectory with four parts
    ;;    - "tag", 
    ;;    - an "ahead-count"
    ;;    - optionally, a "SHA"
   ;;     - "dirty?" flag    
    ;; This section allows you to derive a version string from a four-tuple 
    ;;  XXX
    ;;  The possible version strings are represented by a keyword which must be one of:
    ;;      - :tag - the capture group returned by your regex  (eg:  "12.3.9)
    ;;      - :tag-ahead-sha  - "12.3.9-0-HG56dd"
    ;;  XXX What others should be supported??
    ;; 
    ;; 
    ;; 
    :git-context->version   {
      ;; the keys need to match are "ahead-count" and "dirty" ????
      [:not-ahead?  :not-dirty?]      :tag
      [ :ahead?        :*]                    :tag-ahead-sha }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment