Add github publish action

This commit is contained in:
TEC 2020-11-03 17:53:56 +08:00
parent 0c51d5b5c3
commit db5fcf2c4f
2 changed files with 124 additions and 0 deletions

73
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,73 @@
name: "Publish"
on:
pull_request:
push:
branches: master
jobs:
deploy:
runs-on: ubuntu-20.04 # change to -latest when possible
steps:
- uses: purcell/setup-emacs@master
with:
version: 27.1
- name: Checkout config
uses: actions/checkout@v2
with:
submodules: recursive
- name: Symlink config to expected location
# I could just set DOOMDIR ... but this is also easy
run: |
mkdir -p ~/.config
ln -s $GITHUB_WORKSPACE ~/.config/doom
mkdir -p ~/.org/roam
- name: Generate init.el et. al from config.org
run: |
cd ~/.config/doom
emacs --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "config.org")'
- name: Clone Doom to ~/.emacs.d
run: git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d
- name: Get Doom's version
id: doom-version
run: |
cd ~/.emacs.d
echo ::set-output name=hash::$(git log -1 | head -1 | awk '{print substr($2,1,7)}')
shell: bash
- name: Cache Doom's install
uses: actions/cache@v2
with:
path: ~/.emacs.d
key: ${{ runner.os }}-doom@${{ steps.doom-version.outputs.hash }}
- name: Doom dependencies
run: sudo apt-get install git ripgrep
- name: Install Doom
run: ~/.emacs.d/bin/doom install --no-env --no-fonts
- name: Export config
run: |
cd ~/.config/doom/misc
./config-exporter.sh
cp ../config.html ../index.html
- name: Ensure all html files tracked
run: |
if grep -q '!*.html' ~/.config/doom/.gitignore; then
echo "!*.html" >> ~/.config/doom/.gitignore
fi
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./
force_orphan: true
exclude_assets: '.github,lisp/LaTeX-auto-activating-snippets,lisp/authinfo-color-mode,lisp/lexic,lisp/org-pandoc-import'

51
misc/config-exporter.sh Executable file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env sh
":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
(setq start-time (float-time))
(message "\033[1;0mBuilding config file export\033[0;90m")
(defun timed-message (orig-fn format-str &rest args)
(if (string-match-p "[%\\.1fs]" format-str)
(apply orig-fn format-str args)
(apply orig-fn
(concat "[%.1fs] " format-str)
(append (list (- (float-time) start-time))
args))))
(advice-add 'message :around #'timed-message)
(setq debug-on-error t
doom-debug-p t)
(advice-add 'theme-magic-from-emacs :override #'ignore)
(advice-add 'format-all-buffer :override #'ignore)
(load (expand-file-name "~/.emacs.d/init.el"))
(setq exit-code 0)
(defun red-error (orig-fn &rest args)
(message "\033[0;31m")
(apply orig-fn args)
(message "\033[0m")
(setq exit-code 1))
(advice-add 'debug :around #'red-error)
(message "\033[0;34m[%.1fs] Opening config file: %s\033[90m"
(- (float-time) start-time)
(expand-file-name "../config.org"))
(with-current-buffer (find-file (expand-file-name "../config.org"))
(message "\033[0;33m[%.1fs] Exporting %s\033[0m"
(- (float-time) start-time)
(buffer-file-name))
(org-html-export-to-html))
(message "\033[0;33m[%.1fs] Htmlizing %s\033[0m"
(- (float-time) start-time)
(buffer-file-name))
(htmlize-file (expand-file-name "../config.el"))
(message "\033[1;32m[%.1fs] Config export complete!\033[0m"
(- (float-time) start-time))
(setq inhibit-message t)
(kill-emacs exit-code)