2025年3月22日土曜日

Github Actions で elisp の lint をする方法

Github Actions で elisp の lint をする方法

概要

elisp-autofmt を使ってフォーマットした結果 git diff で差分があった場合はエラーにすることで lint チェックします

環境

  • emacs 30.1

format_elisp_files.sh

フォーマットするためのシェルスクリプトです
内部で emacs を使って elisp-autofmt を実行しフォーマットします
ls-files で取得するファイル名は適宜変更してください

for file_name in `git ls-files files | egrep -e 'el|emacs'`
do
emacs --batch $file_name -l ~/.emacs.d/elpa/elisp-autofmt-*/elisp-autofmt.el --eval "
(progn
  (let ((use-stdout nil))
    (dolist (buf (buffer-list))
      (with-current-buffer buf
        (when (buffer-file-name)
          (setq buffer-undo-list t) ;; Disable undo.
          (if use-stdout
              (progn
                (elisp-autofmt-buffer)
                (princ (buffer-substring-no-properties (point-min) (point-max))))
            (princ buffer-file-name)
            (princ \"\n\")
            (elisp-autofmt-buffer-to-file)))))))"
done

.github/workflows/elisp_lint.yml

ame: Emacs Lisp Format Check

on:
  push:
  pull_request:

jobs:
  format-check:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Emacs
        run: sudo apt-get install -y emacs-nox

      - name: Install pyenv
        uses: actions/setup-python@v5
        with:
          python-version: "3.12.9"

      - name: Install elisp-autofmt into emacs
        run: |
          mkdir -p ~/.emacs.d/elpa/elisp-autofmt-latest/
          wget -O ~/.emacs.d/elpa/elisp-autofmt-latest/elisp-autofmt.el https://codeberg.org/ideasman42/emacs-elisp-autofmt/raw/branch/main/elisp-autofmt.el

      - name: Run format_elisp_files.sh
        run: sh ./format_elisp_files.sh

      - name: Check diff
        run: git diff --exit-code

最後に

これで CI 上で elisp の lint ができます

参考サイト

0 件のコメント:

コメントを投稿