[nomuraya.tk] 実務でも使いそうなCI運用の話
- name: python3.8以前では「PosixPath.with_stem」が使えないので、Pythonをバージョンアップする。
id: python_command
# Ref:
# - https://docs.python.org/ja/3/library/pathlib.html
# - https://codechacha.com/ja/ubuntu-install-python39/
# - https://stackoverflow.com/questions/65644782/how-to-install-pip-for-python-3-9-on-ubuntu-20-04
env:
minor: 9
run: |
pyc=$(python3)
if [ "$(python3 --version | cut -d"." -f2)" -lt "${minor}" ]
then
sudo apt update && sudo apt install software-properties-common python3.${minor}-distutils
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.${minor}
pyc=python3.${minor}
fi
${pyc} --version
echo "::set-output name=pyc::${pyc}"
- name: webp変換パッケージインストール
env:
pyc: ${{ steps.python_command.outputs.pyc }}
run: |
${pyc} -m pip install --upgrade pip
${pyc} -m pip install pathlib
${pyc} -m pip install pillow
${pyc} -m pip install python-box
- name: webp変換
env:
pyc: ${{ steps.python_command.outputs.pyc }}
run: |
curl -sf https://raw.githubusercontent.com/shimajima-eiji/__Operation-Maintenance/main/for_github/workflows/convert_webp.py | ${pyc}
- name: 更新状態を確認
id: check_files
# 実行結果としてはエラーではないので、continue-on-errorでパスさせる
# Ref: https://qiita.com/ljourm/items/556f5ccc8425891865de
continue-on-error: true
run: |
if [ "$(git status -s)" ]
then
echo "[Run] ファイルの変更を検出したため、処理を継続"
else
echo "[Skip] ファイルの変更がないため、処理を中断"
exit 1 # 本来はここで終了してしまうが、見た目上エラーにしたくないのでcontinue-on-errorを設定している
fi
- name: コミット
id: commit
run: |
# (中略)
# 引き継ぎ元のステップにはIDを任意で設定しておく
echo "::set-output name=OWNER::${OWNER}"
echo "::set-output name=BRANCH_BASE::${BRANCH_BASE}"
echo "::set-output name=BRANCH_HEAD::${BRANCH_HEAD}"
echo "::set-output name=MESSAGE::${MESSAGE}"
- name: プルリク作成
if: steps.commit.conclusion == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # hubコマンドの実行にパスワードが必要
REVIEWER: shimajima-eiji
BRANCH_BASE: ${{ steps.commit.outputs.BRANCH_BASE }}
BRANCH_HEAD: ${{ steps.commit.outputs.BRANCH_HEAD }}
MESSAGE: ${{ steps.commit.outputs.MESSAGE }}
run: |
hub pull-request -f -m "${MESSAGE}" -h ${BRANCH_HEAD} -b ${BRANCH_BASE} -a ${REVIEWER} -r ${REVIEWER}
echo "[COMPLETED] Success create pull-request"