Skip to content

Commit

Permalink
[test] Fix prettier ci task
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Aug 19, 2018
1 parent a29c7f1 commit 3916776
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,30 @@ jobs:
steps:
- checkout
- *restore_repo
- run:
name: Export changed files
command: |
# changed files on this branch
# `git diff --name-only master` but since the checkout used reset --hard
# we need to parse the revs for the actual master
echo 'export CHANGED_FILES=$(git diff --name-only $(git rev-parse origin/master))' >> $BASH_ENV
- run:
name: Check if yarn prettier was run
command: |
# Files changed on this branch
CHANGED_FILES=$(git diff --name-only master...)
# Files that should have been formatted while working on this branch
FORMATTED_FILES=$(yarn --silent prettier:files | grep "$CHANGED_FILES")
# if we run prettier unconditionally prettier will exit with non-zero
# because no file path was given
if [ $FORMATTED_FILES ]; then
echo "changes, let's check if they are formatted"
yarn prettier:ci "$FORMATTED_FILES"
else
# if we use an empty string as a pattern grep will match everything
if [ -z "$CHANGED_FILES" ]; then
echo "no changes"
else
# Files that should have been formatted while working on this branch
# CircleCI does not support interpolation when setting environment variables
echo 'export FORMATTED_FILES=$(yarn --silent prettier:files | grep "$CHANGED_FILES")' >> $BASH_ENV
source $BASH_ENV
if [ -z "$FORMATTED_FILES" ]; then
echo "no files for prettier were changed"
else
yarn prettier:ci $FORMATTED_FILES
fi
fi
- run:
name: Lint
Expand Down

0 comments on commit 3916776

Please sign in to comment.