Config export: make a bit more robust

Because the html and pdf exports start both at the same time,
they both experience a cache miss with the xkcd sqlite db.
Poth processes download the image, and attempt to write to the db
... with the same primary key. Hence, errors.

So, when the xkcd cache isn't populated, we wait for one process to
finish before starting the other
This commit is contained in:
TEC 2021-01-29 23:25:26 +08:00
parent 1d277cb001
commit aec6d5f4e7
Signed by: tec
GPG Key ID: 779591AFDB81F06C
5 changed files with 60 additions and 40 deletions

View File

@ -60,11 +60,13 @@ jobs:
sudo apt install texlive-base texlive-latex-recommended texlive-fonts-extra latexmk
- name: Export config
run: ~/.config/doom/misc/config-publishing/publish.sh
run: |
cd ~/.config/doom/misc/config-publishing
./publish.sh
- name: Debug failure over SSH (tmate)
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3.1
# - name: Debug over SSH (tmate)
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3.1
- name: Deploy
if: ${{ github.event_name != 'pull_request'}}

View File

@ -82,9 +82,14 @@
(defalias 'y-or-n-p #'ignore)
(when (and (featurep 'undo-tree) global-undo-tree-mode)
(advice-add 'ask-user-about-supersession-threat :override #'ignore)
(after! undo-tree
(global-undo-tree-mode -1)
(advice-add 'undo-tree-save-history :override #'ignore)))
(advice-add 'undo-tree-mode :override #'ignore)
(remove-hook 'write-file-functions #'undo-tree-save-history-from-hook)
(remove-hook 'kill-buffer-hook #'undo-tree-save-history-from-hook)
(remove-hook 'find-file-hook #'undo-tree-load-history-from-hook)))
;;; Publishing
@ -112,4 +117,4 @@ Names containing \"*\" are treate as a glob."
publish-dir
(expand-file-name file config-root))))
(ensure-dir-exists target)
(rename-file (expand-file-name file config-root) target t)))))
(copy-file (expand-file-name file config-root) target t)))))

View File

@ -13,6 +13,7 @@
(require 'vc) ; need this for modification-time macro
(require 'org)
(require 'ox-html)
(with-temp-buffer
(let ((default-directory config-root)
@ -26,7 +27,7 @@
(publish "config.html" "misc/*.svg")
(make-symbolic-link (expand-file-name "config.html" publish-dir)
(expand-file-name "index.html" publish-dir))
(expand-file-name "index.html" publish-dir) t)
(message "[1;32] Config export complete!")

View File

@ -13,6 +13,7 @@
(require 'vc) ; need this for modification-time macro
(require 'org)
(require 'ox-latex)
(setq org-mode-hook nil)
(with-temp-buffer

View File

@ -16,37 +16,47 @@
(defvar dependent-processes nil)
(defvar dependent-process-names nil)
(defun wait-for-script (file)
(let ((proc-name (intern (format "%s-process" (file-name-base file)))))
(set proc-name (start-process (file-name-base file) nil (expand-file-name file)))
(push (list :proc (symbol-value proc-name)
:file file
:name (file-name-base file)
:padded-name (format "%-8s" (file-name-base file))) ; max len Active/Complete
dependent-processes)
(watch-process (symbol-value proc-name) file)))
(require 'cl-lib)
(defun watch-process (proc file)
(set-process-sentinel
proc
`(lambda (process _signal)
(when (eq (process-status process) 'exit)
(if (= 0 (process-exit-status process))
(message (format "[1;35] %s finished%s"
(cl-defun wait-for-script (file &key then)
(let ((proc-name (intern (format "%s-process" (file-name-base file))))
proc-info)
(set proc-name (start-process (file-name-base file) nil (expand-file-name file)))
(setq proc-info (list :proc (symbol-value proc-name)
:file file
:name (file-name-base file)
:padded-name (format "%-8s" (file-name-base file)) ; max len Active/Complete
:then (if (listp then) then (list then))))
(push proc-info dependent-processes)
(watch-process proc-info)))
(defun watch-process (proc-info)
(let ((file (plist-get proc-info :file)))
(set-process-sentinel
(plist-get proc-info :proc)
`(lambda (process _signal)
(when (eq (process-status process) 'exit)
(if (= 0 (process-exit-status process))
(progn
(message (format "[1;35] %s finished%s"
,(file-name-base file)
(space-fill-line ,(length (file-name-base file)))))
;; start dependent processes
(when ,(car (plist-get proc-info :then))
(mapcar (lambda (then) (apply #'wait-for-script (if (listp then) then (list then))))
',(plist-get proc-info :then))))
;; non-zero exit code
(message (format "[31] %s process failed!%s"
,(file-name-base (eval file))
(space-fill-line ,(length (file-name-base (eval file))))))
;; non-zero exit code
(message (format "[31] %s process failed!%s"
,(file-name-base (eval file))
(space-fill-line ,(+ 16 (length (file-name-base (eval file)))))))
(message "\033[0;31m %s\033[0m"
'unmodified
(with-temp-buffer
(insert-file-contents-literally (expand-file-name ,(format "%s-log.txt" (file-name-base file))
(file-name-directory load-file-name)))
(buffer-substring-no-properties (point-min) (point-max))))
(message "[1;31] Config publishing aborted%s" (space-fill-line 23))
(kill-emacs 1))))))
(space-fill-line ,(+ 16 (length (file-name-base file))))))
(message "\033[0;31m %s\033[0m"
'unmodified
(with-temp-buffer
(insert-file-contents-literally (expand-file-name ,(format "%s-log.txt" (file-name-base file))
(file-name-directory load-file-name)))
(buffer-substring-no-properties (point-min) (point-max))))
(message "[1;31] Config publishing aborted%s" (space-fill-line 23))
(kill-emacs 1)))))))
(defun space-fill-line (base-length)
"Return whitespace such that the line will be filled to overwrite the status line."
@ -62,9 +72,10 @@
(wait-for-script "htmlize.sh")
(wait-for-script "org-pdf.sh")
(wait-for-script "org-html.sh")
(if (not (file-exists-p (concat user-emacs-directory "xkcd/")))
(wait-for-script "org-html.sh" :then "org-pdf.sh")
(wait-for-script "org-html.sh")
(wait-for-script "org-pdf.sh"))
;;; Status info