200ok-ch / org-parser

org-parser is a parser for the Org mode markup language for Emacs.
GNU Affero General Public License v3.0
320 stars 16 forks source link

How to update README.org and check if building of jar and cljs works? #52

Open schoettl opened 3 years ago

schoettl commented 3 years ago

After changes and before pushing to GitHub, we usually want to:

The README.org already have build instructions and code for samples embedded in babel blocks.

Can we call emacs with org-mode babel to run all source blocks and fail if a shell source block has non-zero exit status?

We could have a Makefile with

update-readme:
    emacs --batch … README.org

Alternatively we could add build rules in the Makefile but that would actually be redundant to the README.org.

What do you think?

munen commented 3 years ago

It is possible to do what you're saying and it would be pretty cool, but it is a bit of work. I'm getting us started with some snippets.

Given this code: https://gist.github.com/munen/4cb3b5493f48e7f032d72b5c3440346a

You can run it like so:

munen@lambda:~/tmp% emacs -l init.el --batch tangle_test.org -f org-babel-execute-src-block
executing Ruby code block...
Code block evaluation complete.

Unfortunately, we're not done, yet.

Firstly, the org-babel-execute-src-block only runs, because the source block starts with the first character in the file. Otherwise it would crash. Secondly, the output is not written anywhere.

I've searched the Interwebs for a finished solution and interestingly couldn't find one so far. The best thing I've found is https://emacs.stackexchange.com/a/28655/17889 which provides a shell script which needs an Org file and a named source block as input. From a first look it looks a bit complicated, though. Maybe that's required.

Starting from my too simple and the probably too complicated script, we could build something that doesn't need a specific named source block, but just walks through the file and executes all source blocks. That could be a sweet little snippet that can be re-used in different places.

schoettl commented 3 years ago

Another idea is to use the easier to use tangle feature of org mode. It's described here, again at EmacsConf2020 ;)

It's not meant to update the README itself but generate source files from babel source blocks which can be executed as tests.

It would be useful for testing the compilation and also the use of the library in a sample clojure script.

schoettl commented 3 years ago

I created a Makefile and made use of tangling

Now, the build and more tests can be executed with:

make build && make test