feat(ci): generalize 'doom ci deploy-hooks'

By default, 'doom ci deploy-hooks' would deploy Doom's git hooks in
$EMACSDIR (~/.emacs.d/.git/hooks). Now it deploys in the local repo its
run in. This is part of an effort to generalize Doom's CI for use
outside this repo.

Ref: 4bae9ffa47
This commit is contained in:
Henrik Lissner 2022-05-05 13:02:52 +02:00
parent 4bae9ffa47
commit f281971206
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 33 additions and 16 deletions

View file

@ -22,20 +22,33 @@
;;;
(defun doom-cli--ci-deploy-hooks (&optional noforce)
(let* ((default-directory doom-emacs-dir)
(dir (cdr (doom-call-process "git" "rev-parse" "--git-path" "hooks"))))
(make-directory dir 'parents)
(dolist (hook '("commit-msg" "pre-push"))
(let ((file (doom-path dir hook)))
(unless (and (file-exists-p file) noforce)
(with-temp-file file
(insert "#!/usr/bin/env sh\n"
(doom-path doom-emacs-dir "bin/doom")
" --nocolor ci hook-" hook
" \"$@\""))
(set-file-modes file #o700)
(print! (success "Created %s") (relpath file)))))))
(defun doom-cli--ci-deploy-hooks (&optional force)
(let* ((repo-path (cdr (doom-call-process "git" "rev-parse" "--show-toplevel")))
(submodule-p (string-empty-p (cdr (doom-call-process "git" "rev-parse" "show-superproject-working-tree"))))
(config-hooks-path (cdr (doom-call-process "git" "config" "core.hooksPath")))
(hooks-path (cdr (doom-call-process "git" "rev-parse" "--git-path" "hooks"))))
(unless (string-empty-p config-hooks-path)
(or force
(y-or-n-p
(format (concat "Detected non-standard core.hookPath: %S\n\n"
"Install Doom's commit-msg and pre-push git hooks anyway?")
hooks-path))
(user-error "Aborted")))
(make-directory hooks-path 'parents)
(print! (start "Deploying git hooks in %S") (path hooks-path))
(print-group!
(dolist (hook '("commit-msg" "pre-push"))
(let* ((hook (doom-path hooks-path hook))
(overwrite-p (file-exists-p hook)))
(with-temp-file hook
(insert "#!/usr/bin/env sh\n"
(doom-path doom-emacs-dir "bin/doom")
" --nocolor ci hook-" (file-name-base hook)
" \"$@\""))
(set-file-modes hook #o700)
(print! (success "%s %s")
(if overwrite-p "Overwrote" "Created")
(path hook)))))))
;;

View file

@ -24,7 +24,7 @@ name. e.g.
DOOMDIR=~/.config/doom doom install"
(print! (green "Installing Doom Emacs!\n"))
(let ((default-directory (doom-path "~")))
(let ((default-directory doom-emacs-dir))
;; Create `doom-private-dir'
(if noconfig-p
(print! (warn "Not copying private config template, as requested"))
@ -77,7 +77,11 @@ name. e.g.
(if nohooks-p
(print! (warn "Not deploying commit-msg and pre-push git hooks, as requested"))
(print! "Deploying commit-msg and pre-push git hooks")
(doom-cli--ci-deploy-hooks))
(print-group!
(condition-case e
(doom-cli--ci-deploy-hooks doom-auto-accept)
('user-error
(print! (warn "%s") (error-message-string e))))))
(cond (nofonts-p)
(IS-WINDOWS