86 lines
3 KiB
EmacsLisp
86 lines
3 KiB
EmacsLisp
(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")
|
|
("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")
|
|
("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)))
|
|
|
|
(defun integration-test-exists-p (module)
|
|
(file-exists-p (format "test/integration/%s.bats" module)))
|
|
|
|
(defun alist-p (lst)
|
|
(and (listp lst)
|
|
(listp (car lst))
|
|
(= (length lst) 2)
|
|
(not (proper-list-p (car lst)))))
|
|
|
|
(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 (directory-files "." nil (rx string-start "oni-")))
|
|
(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")
|
|
("stages" "pre-package-multi-file" "package" "unit-test" "integration-test" "deploy")
|
|
,@(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/")))
|
|
,@(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))
|
|
("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"))))
|