1
0
Fork 0
emacs-config/generate.el

85 lines
3.1 KiB
EmacsLisp
Raw Normal View History

2020-10-16 09:15:12 +02:00
(require 'libyaml)
(require 'cl-lib)
(defun directory-name->package-name (dir)
(format "package-%s" dir))
(defun directory->prepackage (module)
`(,(directory-name->package-name module)
("stage" . "pre-package-multifile")
("before_script" ,(format "rm -rf %s/dist" module))
("script" ,(format "cask --path %s package" module))
("artifacts"
("paths" ,(format "%s/dist" module)))))
(defun module->unit-test (module)
`(,(format "unit-test-%s" module)
("stage" . "unit-test")
("dependencies" "package")
("before_script" "mkdir -p ~/documents/org/projects/")
2020-10-16 09:15:12 +02:00
("script" . ,(format "make unit-test-%s TEST_ARCHIVE=$(realpath bin/)" module))))
(defun module->integration-test (module)
`(,(format "integration-test-%s" module)
("stage" . "integration-test")
("dependencies" "package")
("before_script" "mkdir -p ~/.emacs.d/data/ ~/documents/org/projects/")
2020-10-16 09:15:12 +02:00
("script" . ,(format "make integration-test-%s TEST_ARCHIVE=$(realpath bin/)" module))))
(defun unit-test-exists-p (module)
(file-exists-p (format "test/%s-test.el" module)))
2020-10-16 09:15:12 +02:00
(defun integration-test-exists-p (module)
2020-10-16 21:57:26 +02:00
(file-exists-p (format "test/integration/%s.bats" module)))
2020-10-16 09:15:12 +02:00
(defun prepare-value-for-yaml (object)
(pcase object
((and (pred proper-list-p)
lst
(guard (listp (car lst))))
(prepare-for-yaml object))
((pred proper-list-p)
(apply #'vector object))
(_ object)))
(defun prepare-for-yaml (object)
(let ((hash (make-hash-table)))
(dolist (item object)
(puthash (car item) (prepare-value-for-yaml (cdr item)) hash))
hash))
(defun generate ()
(let* ((modules
(mapcar (lambda (file) (string-remove-suffix ".el" file))
(directory-files "." nil (rx string-start "oni-"))))
2020-10-16 09:15:12 +02:00
(directories (cl-remove-if-not #'file-directory-p modules)))
(with-temp-buffer
(insert
(yaml-dump
(prepare-for-yaml
`(("image" . "registry.gitlab.com/ryuslash/emacs-config")
2020-10-16 09:34:35 +02:00
("stages" "pre-package-multifile" "package" "unit-test" "integration-test" "deploy")
2020-10-16 09:15:12 +02:00
,@(mapcar #'directory->prepackage directories)
("package"
("stage" . "package")
("dependencies" ,@(mapcar #'directory-name->package-name directories))
("before_script"
"rm -rf bin/"
"mkdir bin/")
("script" . "make package")
("artifacts"
("paths" "bin/")))
2021-07-23 10:45:19 +02:00
;; ,@(mapcar #'module->unit-test
;; (cl-remove-if-not #'unit-test-exists-p modules))
;; ,@(mapcar #'module->integration-test
;; (cl-remove-if-not #'integration-test-exists-p modules))
2020-10-16 09:15:12 +02:00
("deploy"
("only" "master")
("stage" . "deploy")
("image" . "instrumentisto/rsync-ssh")
("dependencies" "package")
("before_script" "chmod 600 \"$DEPLOY_KEY\"")
("script"
"rsync -e \"ssh -o \\\"UserKnownHostsFile $KNOWN_HOSTS\\\" -p 4511 -i $DEPLOY_KEY\" -v -c -r --delete bin/ \"elpa@ryuslash.org:\""))))))
(write-file "generated-config.yml"))))