From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: run shell command after publishing project Date: Tue, 19 Dec 2017 12:37:10 +0100 Message-ID: <87r2rrt0d5.fsf@gmx.us> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRGD4-00039H-41 for emacs-orgmode@gnu.org; Tue, 19 Dec 2017 06:37:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRGD3-0002kT-3A for emacs-orgmode@gnu.org; Tue, 19 Dec 2017 06:37:22 -0500 Received: from [195.159.176.226] (port=46671 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eRGD2-0002jE-RF for emacs-orgmode@gnu.org; Tue, 19 Dec 2017 06:37:20 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eRGB0-0006rn-TT for emacs-orgmode@gnu.org; Tue, 19 Dec 2017 12:35:14 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Hi, Matt Price writes: > I'm setting up a new workflow using Kauhsal's ox-hugo. I keep all my > course materials in a few org files & publish to hugo-flavoured markdown. > My source materials live in one git repo, and my website in another. After > exporting any of my my courses to the local hugo directory, I'd like to run > a shell script that I'll keep in my org-files directory. Do you mean commit or publish instead of export? Otherwise you might have to keep track of whether you are exporting to buffer as a buffer still has a default-directory. It would be easier to publish. > That script > - cds to the website repo directory, commits changes to the website master > branch, - runs hugo, > - switches to the "public" directory of compiled html pages, which has a > worktree checked out to the gh-pages branch, > - commits changes there as well, and then > - pushes both branches to github. > > The script seems to work OK, and now I would like to run it every time I > export from the appropriate projects. Is there a good way for me to do > this? I guess a hook that only runs under certain conditions? That is a sane approach with github pages, indeed. I did something similar when I used github pages, but with ox-publish. My ‘:preparation-function’ was (defun project-prep-function () (interactive) (or (zerop (shell-command (format "cd %s && git checkout master" project-main-dir))) (error (format "error checking out master in %s" project-main-dir)))) And my ‘:completion-function’ was as follows where ‘project-tmp-dir’ the ‘:publishing-directory’. (defun project-completion-function () (interactive) (let ((cd (format "cd %s && " project-main-dir))) (shell-command (concat cd "git commit -am \"auto-check-in\"")) (or (zerop (shell-command (concat cd "git checkout gh-pages"))) (error (format "error checking out gh-pages in %s" project-main-dir))) (or (zerop (shell-command (format "mv %s/*.html %s" project-tmp-dir project-main-dir))) (error "error moving files")) (or (zerop (shell-command (concat cd "git add *.html && git commit -am 'updated html'"))) (error "error adding html files")) (or (zerop (shell-command (concat cd "git push origin gh-pages"))) (warn "error pushing gh-pages")) (or (zerop (shell-command (concat cd "git checkout master"))) (error "error checking out master")))) > If I can get this to work, and then also auto export every time I commit > the org-files to master (maybe with a post-commit git hook of ~emacsclient > -e '(org-publish-project "course1"~ ?), then I will maybe be almost happy! If you use ox-publish you could auto-commit whenever you publish a project. But I guess you could also use a hook. I use this to publish: emacs --batch --no-init-file --load publish.el --funcall org-publish-all I do it via Gitlab CI, though, as I only want to keep track of source files. pages: script: - emacs --batch --no-init-file --load publish.el --funcall org-publish-all artifacts: paths: - public Rasmus -- Enough with the blah blah!