はじめに
Qiita-CLI を使っていると md ファイルが多くなりすぎて管理ができなくなってしまう.
もちろん,後に編集はできるようにしたいのですべて public フォルダにおいておきたい.(md ファイルが public フォルダにないとプレビューがみれない)
そのため,ファイル名を正規化して,ツリー構造を作成することでどのような記事があるかを一目でわかるようにする.
前回の記事
自動でファイル名を変更する
前回,ファイル名を変更するスクリプトを作成した.
しかし,それを毎回実行するのは面倒なので,自動で実行するようにしたい!
どうせファイルで書いているなら,git管理をしているということで,github actions で自動実行するようにする.
github actions で自動実行
github actions は github で提供されている CI/CD ツールである.
今回は,Qiita-CLI で作成した md ファイルを整理するためのスクリプトを自動で実行するようにする.
0.ファイル名を管理する.ipynb
ファイルを作成
ファイル内容は前回の記事を参照
今回は.ipynb
で作成しています.
理由は特にないです,,
github actions で実行するスクリプトを作成
まずは,前回作成したスクリプトを github actions で実行するようにする.
以下のファイルを.github/workflows/run_notebook.yml
として作成する.
run_notebook.yml
name: Run Genre Notebook and Commit Changes
on:
push:
branches:
- main
- master
workflow_dispatch:
jobs:
run-and-commit-notebook:
runs-on: ubuntu-latest
steps:
- name: リポジトリをチェックアウト
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: 依存関係をインストール
run: |
python -m pip install --upgrade pip
pip install jupyter numpy glob2
- name: Notebookを実行
run: |
jupyter nbconvert --to notebook --execute --inplace genre.ipynb
- name: Commit & Push
env:
ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add -A .
git commit -m "update file name"
git -c http.extraheader="AUTHORIZATION: bearer ${ACCESS_TOKEN}" push
github secrets にアクセストークンを登録
こちらの記事を参考に github secrets にアクセストークンを登録する.