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

Allow base_dir on modified strategy #13

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
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