Skip to content

Commit

Permalink
feat: check only modified files (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRibeiro authored Jul 26, 2023
1 parent d02c21e commit 7df71e9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ workflows:
- vale/lint:
name: vale-lint-all
base_dir: "sample/"
strategy: all
filters: *filters
- vale/lint:
name: vale-lint-md
base_dir: "sample/"
strategy: all
glob: "*/test.md"
filters: *filters
- vale/lint:
name: vale-lint-readme
strategy: all
glob: "*/README.md"
filters: *filters
# The orb must be re-packed for publishing, and saved to the workspace.
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# orb.yml is "packed" from source, and not published directly from the repository.
orb.yml
.DS_Store
.DS_Store
styles/Google
styles/write-good
17 changes: 17 additions & 0 deletions src/jobs/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,29 @@ parameters:
type: string
default: ".vale.ini"
description: "Path to a Vale configuration file. By default, Vale will look for a .vale.ini file in the root of your repository."
strategy:
type: enum
default: modified
enum: [modified, all]
description: |
Strategy to use when determining which files to lint.
By default, only modified files will be linted.
If set to modified, the "reference_branch" parameter must also be set.
reference_branch:
type: string
default: main
description: |
Branch to use as a reference when determining modified files.
By default, the main branch will be used.
If the strategy is set to "modified", this parameter must also be set.
steps:
- checkout
- run:
name: Lint files
environment:
VALE_STR_CLI_GLOB: << parameters.glob >>
VALE_STR_REFERENCE_BRANCH: << parameters.reference_branch >>
VALE_EVAL_CLI_CONFIG: << parameters.config >>
VALE_EVAL_CLI_BASE_DIR: << parameters.base_dir >>
VALE_ENUM_STRATEGY: << parameters.strategy >>
command: <<include(scripts/lint.sh)>>
36 changes: 31 additions & 5 deletions src/scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@ redtext() {
echo -e "\033[0;31m$1\033[0m"
}

# $1: glob
# $2: config
# $3: files
sync_and_run_vale() {
set -x
vale sync
# shellcheck disable=SC2086
vale --glob="$1" --config="$2" $3 # No quotes around $3
set +x
}

VALE_EVAL_CLI_CONFIG="$(eval echo "$VALE_EVAL_CLI_CONFIG")"
VALE_STR_CLI_GLOB="$(circleci env subst "$VALE_STR_CLI_GLOB")"
VALE_STR_REFERENCE_BRANCH="$(circleci env subst "$VALE_STR_REFERENCE_BRANCH")"

VALE_EVAL_CLI_BASE_DIR="$(eval echo "$VALE_EVAL_CLI_BASE_DIR")"
VALE_EVAL_CLI_BASE_DIR="${VALE_EVAL_CLI_BASE_DIR/\~/$HOME}"

if [[ ! -f "$VALE_EVAL_CLI_CONFIG" ]]; then
if [ ! -f "$VALE_EVAL_CLI_CONFIG" ]; then
redtext "No configuration file found at $VALE_EVAL_CLI_CONFIG"
echo "To get started, you'll need a configuration file (.vale.ini)"
echo "Create a config file, or modify the 'config' parameter for this job"
Expand All @@ -21,7 +33,21 @@ if [[ ! -f "$VALE_EVAL_CLI_CONFIG" ]]; then
'
exit 1
fi
set -x
vale sync
vale --glob="$VALE_STR_CLI_GLOB" --config="$VALE_EVAL_CLI_CONFIG" "$VALE_EVAL_CLI_BASE_DIR"
set +x

if [ "$VALE_ENUM_STRATEGY" = "all" ]; then
sync_and_run_vale "$VALE_STR_CLI_GLOB" "$VALE_EVAL_CLI_CONFIG" "$VALE_EVAL_CLI_BASE_DIR"
elif [ "$VALE_ENUM_STRATEGY" = "modified" ]; then
echo "Installing git..."
command -v git > /dev/null 2>&1 || { apk add git; }

echo "Checking for modified files..."
modified_files="$(git diff --name-only "$VALE_STR_REFERENCE_BRANCH")"
echo "$modified_files"

modified_files_space_separated=$(echo "$modified_files" | tr '\n' ' ')
echo "Running vale on modified files..."
sync_and_run_vale "$VALE_STR_CLI_GLOB" "$VALE_EVAL_CLI_CONFIG" "$modified_files_space_separated"
else
echo "Invalid strategy: $VALE_ENUM_STRATEGY"
exit 1
fi

0 comments on commit 7df71e9

Please sign in to comment.