diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 34bd95f..c7d1665 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -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. diff --git a/.gitignore b/.gitignore index 3c88c1b..6207f08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ # orb.yml is "packed" from source, and not published directly from the repository. orb.yml -.DS_Store \ No newline at end of file +.DS_Store +styles/Google +styles/write-good \ No newline at end of file diff --git a/src/jobs/lint.yml b/src/jobs/lint.yml index ce0943c..c9e6cce 100755 --- a/src/jobs/lint.yml +++ b/src/jobs/lint.yml @@ -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: <> diff --git a/src/scripts/lint.sh b/src/scripts/lint.sh index 5a27e64..38130d0 100644 --- a/src/scripts/lint.sh +++ b/src/scripts/lint.sh @@ -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" @@ -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