Skip to content

Commit

Permalink
Allow base_dir on modified strategy (#13)
Browse files Browse the repository at this point in the history
* Modify the modified behavior to use base_dir, add test for it

* Update to work with sh

* Remove array

* update regex to case

* Fix linter

* Update shebang

* Update base_dir descrpition

* Update tests

* Updated tests

* Remove useless comments

* Remove useless comments

* Extra test
  • Loading branch information
marboledacci authored Dec 30, 2024
1 parent 04da34e commit 07b2505
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
13 changes: 12 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
orbs:
# Your orb will be automatically injected here during the pipeline.
# Reference your orb's jobs and commands below as they will exist when built.
orb-tools: circleci/orb-tools@12.0
orb-tools: circleci/orb-tools@12.3
# The orb definition is intentionally not included here. It will be injected into the pipeline.
vale: {}

Expand All @@ -24,6 +24,17 @@ workflows:
jobs:
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
# Test your orb's commands in a custom job and test your orb's jobs directly as a part of this workflow.
- vale/lint:
name: vale-lint-modified-default
strategy: modified
filters: *filters
- vale/lint:
name: vale-lint-modified-<<matrix.base_dir>>
matrix:
parameters:
base_dir: [src, sample, ".", .github]
strategy: modified
filters: *filters
- vale/lint:
name: vale-lint-all
base_dir: "sample/"
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parameters:
base_dir:
type: string
default: "$CIRCLE_WORKING_DIRECTORY"
description: "Base directory to run Vale from. By default, Vale will run in the current directory."
description: "Base directory to run Vale from. By default, Vale will run in the current directory. Do no put / at the end."
config:
type: string
default: ".vale.ini"
Expand Down
22 changes: 17 additions & 5 deletions src/scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,24 @@ elif [ "$VALE_ENUM_STRATEGY" = "modified" ]; then
command -v git > /dev/null 2>&1 || { apk add git; }

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

modified_files_space_separated=$(echo "$modified_files" | tr '\n' ' ')
PREFIX="$VALE_EVAL_CLI_BASE_DIR/"
FILES=""
while read -r file; do
if [ "$VALE_EVAL_CLI_BASE_DIR" = "." ] || [ "$VALE_EVAL_CLI_BASE_DIR" = "$PWD" ]; then
FILES="$file $FILES"
fi
case "$file" in
$PREFIX*)
FILES="$file $FILES"
;;
esac
done <<EOF
$(git diff --name-only --diff-filter=d "$VALE_STR_REFERENCE_BRANCH")
EOF

echo "$FILES"
echo "Running vale on modified files..."
sync_and_run_vale "$VALE_STR_CLI_GLOB" "$VALE_EVAL_CLI_CONFIG" "$modified_files_space_separated"
sync_and_run_vale "$VALE_STR_CLI_GLOB" "$VALE_EVAL_CLI_CONFIG" "$FILES"
else
echo "Invalid strategy: $VALE_ENUM_STRATEGY"
exit 1
Expand Down

0 comments on commit 07b2505

Please sign in to comment.