Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Fix prettier ci task with multiple changed files #12579

Merged
merged 1 commit into from
Aug 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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