1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHub Actions で Spell Checkを行う(aspell)

Last updated at Posted at 2023-01-04

概要

aspellを利用してスペルチェックを行う
aspellとcspellどっちがいいんですかねえ…

ファイル配置例

.github
|-aspell
| |-ignore.txt
| |-run.sh
|
|-workflows
  |-aspell.yaml

github actionsの設定

・pull_requestのopen時とブランチが更新されたときに実行
・ubuntuで
 contentsはreadのみ
 長時間動いてしまうと怖いのでtimeoutは1min
・PR対象のブランチをチェックアウト
 元となるブランチもfetch(mainに固定してしまっているので、元ブランチが違う場合には記述を変える必要あり)
 aspellをインストールして実行

.github/workflows/aspell.yaml
name: aspell

on:
  pull_request:
    types: [ opened, synchronize ]

jobs:
  main:
    runs-on: ubuntu-22.04  # runner OS version
    permissions:
      contents: read
    timeout-minutes: 1
    steps:
      - name: checkout
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Fetch base branch
        run: git fetch origin main
      - name: aspell
        run: |
          sudo apt install -y aspell aspell-en > /dev/null 2>&1
          sh ./.github/aspell/run.sh

aspellの実行

設定ファイルをわかりやすくするために
・個人辞書は小文字でsortして格納するルールとする
・git diff で変更があった部分のみチェックをする

.github/aspell/run.sh
tail -n +2 ./.github/aspell/ignore.txt > /tmp/trimmed_ignore.txt
tr A-Z a-z < /tmp/trimmed_ignore.txt > /tmp/lower_ignore.txt
diff /tmp/trimmed_ignore.txt /tmp/lower_ignore.txt
if [ $? -gt 0 ]; then
    echo 'There is upper case words in .github/aspell/ignore.txt. please fix lower case.'
    exit 1
fi

sort -u -f /tmp/lower_ignore.txt > /tmp/sorted_lower_ignore.txt
diff /tmp/lower_ignore.txt /tmp/sorted_lower_ignore.txt
if [ $? -gt 0 ]; then
    echo 'Please sort words in .github/aspell/ignore.txt'
    exit 1
fi
rm /tmp/trimmed_ignore.txt /tmp/lower_ignore.txt /tmp/sorted_lower_ignore.txt

cp ./.github/aspell/ignore.txt ~/.aspell.en.pws
git diff origin/main HEAD | grep "^+" | tr A-Z a-z | aspell list |sort |uniq > error_spells.txt
if [ -s ./error_spells.txt ]; then
    echo 'Check the spelling. Please store in .github/aspell/ignore.txt if needed.'
    cat ./error_spells.txt
    exit 1
fi
rm ~/.aspell.en.pws

個人辞書

aspellの個人辞書だが、無視する単語を格納しているのでignore.txtというファイルにして格納している
run.sh内でデフォルトのファイル名に変更している
これはaspell実行時のオプションでファイル名指定でもいいかもしれない…
先頭行だけ個人辞書を表すヘッダ。残りには無視する単語を入れていく

.github/aspell/ignore.txt(例)
personal_ws-1.1 en 0
api
aspell
cp

雑感

使い始めは毎回スペルチェックに引っかかるのでちょっと面倒
辞書が整ってくるとtypoを見つけることができたりして便利になってくる
textlintやpullリクエストへの自動コメントも入れたかったがそれはまた今度ということでここまで

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?