差分チェックスクリプト
scripts/circleci/is_changed_directory.sh
#!/bin/bash
# See: https://blog.hatappi.me/entry/2018/10/08/232625
if [ "${CIRCLE_BRANCH}" = "master" ]; then
DIFF_TARGET="HEAD^ HEAD"
else
DIFF_TARGET="origin/master"
fi
DIFF_FILES=(`git diff ${DIFF_TARGET} --name-only --relative=${1}`)
if [ ${#DIFF_FILES[@]} -eq 0 ]; then
exit 1
else
exit 0
fi
.circleci/config.yml
..circleci/config.yml
script_setup: &script_setup
command: |
echo 'export PATH=$PATH:${CIRCLE_WORKING_DIRECTORY}/scripts/circleci' >> $BASH_ENV
jobs:
sample_job:
steps:
- checkout
- run:
<<: *script_setup
- run:
name: 後続の job 実行継続判定
command: |
if ! is_changed_directory.sh "foo/bar" -a "${CIRCLE_BRANCH}" != "master"; then
echo "foo/bar に変更がありません"
circleci step halt
fi