aboutsummaryrefslogtreecommitdiff
path: root/.guix
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-07 12:01:55 +0300
committerFrederick Muriuki Muriithi2023-08-07 12:01:55 +0300
commit61d1c03170d8f22ecd67051df56c2a66e83eb502 (patch)
tree279facc558ad82e3a453303bb592d7d15cb157a2 /.guix
parenta112c99cae0c5422a38e3a35e843a82db764316a (diff)
downloadgn-auth-61d1c03170d8f22ecd67051df56c2a66e83eb502.tar.gz
Enable automatic fetching of version information.
Diffstat (limited to '.guix')
-rw-r--r--.guix/modules/guix-package.scm32
1 files changed, 30 insertions, 2 deletions
diff --git a/.guix/modules/guix-package.scm b/.guix/modules/guix-package.scm
index 38c4a33..80f29c6 100644
--- a/.guix/modules/guix-package.scm
+++ b/.guix/modules/guix-package.scm
@@ -5,6 +5,7 @@
#:use-module ((guix licenses) #:prefix license:)
#:use-module (git oid)
+ #:use-module (git tag)
#:use-module (git bindings)
#:use-module (git reference)
#:use-module (git repository)
@@ -37,10 +38,37 @@
commit))
"NOTAREPOSITORY"))
+(define (list-last lst)
+ (let ((len (length lst)))
+ (if (> len 0)
+ (list-ref lst (- len 1)))))
+
+(define (process-version repo-head tag-vals)
+ (let ((version-prefix (list-last (string-split (car tag-vals) #\/)))
+ (repo-head-str (oid->string repo-head)))
+ (if (zero? (oid-cmp repo-head
+ (tag-target-id (cdr tag-vals))))
+ version-prefix
+ (string-append version-prefix "-" (substring repo-head-str 0 8)))))
+
(define (get-latest-version)
"Get latest version tag from repository."
- ;; TODO: Implement
- "v0.0.0")
+ (let ((%repo #f)
+ (%tags (list))
+ (%repo-head #f))
+ (begin (libgit2-init!)
+ (set! %repo (repository-open %source-dir))
+ (set! %repo-head (reference-target (repository-head %repo)))
+ (tag-foreach %repo
+ (lambda (tname tref)
+ (set! %tags (list (cons tname (tag-lookup %repo tref))))
+ 0))
+ (libgit2-shutdown!)
+ (if (zero? (length %tags))
+ (string-append "v0.0.0-" (substring (oid->string %repo-head) 0 8))
+ (process-version
+ %repo-head
+ (list-last (sort-list %tags (lambda (item) (error item)))))))))
(define vcs-file?
(or (git-predicate %source-dir)