Skip to content

Commit

Permalink
chore(ci): better commit range & doc work detection (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Apr 23, 2022
1 parent 8a97022 commit 84bd37b
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -457,33 +457,37 @@ jobs:
# there's no need to run the workflow
check_doc_abort:
executor: docker-circleci
environment:
COMMIT_RANGE: << pipeline.git.base_revision >>..<<pipeline.git.revision>>
steps:
- checkout
- run: |
if [[ $(git diff --name-only HEAD master | grep -v '^doc' -c) -eq 0 ]]; then
echo "Branch is only doc work"
# Extract commit range (or single commit)
echo "commit range from CircleCI: ${COMMIT_RANGE}"
if [[ -n ${CIRCLE_PR_NUMBER} ]]; then
curl -L "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64" \
-o jq
chmod +x jq
url="https://api.github.com/repos/org/repo/pulls/$CIRCLE_PR_NUMBER?access_token=$GITHUB_TOKEN"
TARGET_BRANCH=$(curl "$url" | ./jq '.base.ref' | tr -d '"')
echo "Target branch: $TARGET_BRANCH"
COMMIT_RANGE=$(echo "$CIRCLE_SHA1..$TARGET_BRANCH")
fi
echo "Normalized commit range: $COMMIT_RANGE"
echo "File changed count: $(git diff --name-only $COMMIT_RANGE | grep -v '*' -c)"
echo "Non doc file changes: $(git diff --name-only $COMMIT_RANGE | grep -v '^doc' -c)"
if [[ $(git diff --name-only $COMMIT_RANGE | grep -v '*' -c) -gt 0 ]] && [[ $(git diff --name-only $COMMIT_RANGE | grep -v '^doc' -c) -eq 0 ]]; then
echo "Branch is only doc work, cancelling..."
curl --request POST \
--url https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel?circle-token=$CIRCLE_API_TOKEN \
--url https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel?circle-token=$CIRCLE_API_TOKEN
else
echo "Running workflow $CIRCLE_WORKFLOW_ID"
echo "Branch contains more than doc, running workflow $CIRCLE_WORKFLOW_ID..."
fi
# - run: |
# GIT_COMMIT_DESC=$(git log -1 HEAD --pretty=format:%s)
# echo "Commit message: '$GIT_COMMIT_DESC'"
# if [[ $GIT_COMMIT_DESC == Gitbook:* ]]; then
# echo "Cancelling workflow $CIRCLE_WORKFLOW_ID"
# curl --request POST \
# --url https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel?circle-token=$CIRCLE_API_TOKEN \

# elif [[ $(git diff --name-only HEAD master | grep -v '^doc' -c) -eq 0 ]]; then
# echo "Branch is only doc work"
# curl --request POST \
# --url https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel?circle-token=$CIRCLE_API_TOKEN \

# else
# echo "Running workflow $CIRCLE_WORKFLOW_ID"
# fi
# # # # # # # # # # # # # # # #
# - Workflows -
Expand Down

0 comments on commit 84bd37b

Please sign in to comment.