Skip to content

Commit

Permalink
Merge pull request #8 from gaurav-nelson/lint-all-files
Browse files Browse the repository at this point in the history
Added arguments to lint all files
  • Loading branch information
gaurav-nelson authored Oct 9, 2019
2 parents aa6f934 + 482b542 commit 5437f92
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ jobs:
- uses: actions/checkout@master
- name: vale-lint-PR
uses: ./
with:
lint-all-files: 'yes'
env:
GH_COMMENT_TOKEN: ${{ secrets.GH_COMMENT_TOKEN }}
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,42 @@ You must have [Vale configuration file](https://errata-ai.github.io/vale/config/
## How to use
1. Create a new file in your repository `.github/workflows/action.yml`.
```bash
touch .github/workflows/action.yml
touch .github/workflows/pull_request.yml
```
1. Copy-paste the folloing workflow in your `action.yml` file:
1. Copy-paste the folloing workflow in your `pull_request.yml` file:

```yml
name: Lint PRs with Vale

on: pull_request

jobs:
vale-lint-PR:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- uses: gaurav-nelson/github-action-vale-lint@v0.0.3
- uses: gaurav-nelson/github-action-vale-lint@v0.1.0
env:
GH_COMMENT_TOKEN: ${{ secrets.GH_COMMENT_TOKEN }}
```
1. Or, if you want to lint all files (or files in a specific folder)
and not just modified files, use the following workflow in your
`pull_request.yml` file:

```yml
name: Lint PRs with Vale
on: pull_request
jobs:
vale-lint-PR:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- uses: gaurav-nelson/github-action-vale-lint@v0.1.0
with:
lint-all-files: 'yes'
dir-to-lint: 'directory/path/to/lint'
env:
GH_COMMENT_TOKEN: ${{ secrets.GH_COMMENT_TOKEN }}
```
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ author: 'Gaurav Nelson'
branding:
icon: 'check-circle'
color: 'blue'
inputs:
lint-all-files:
description: 'Use yes if you want to lint all files instead of linting only modified files.'
required: true
default: 'no'
dir-to-lint:
description: 'Specify path of the directory to lint. Use this in conjunction with the lint-all-files argument.'
required: true
default: '.'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.lint-all-files }}
- ${{ inputs.dir-to-lint }}
33 changes: 20 additions & 13 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ BLUE='\033[0;34m'

MASTER_HASH=$(git rev-parse origin/master)
EXTENSION_ARRAY=(.md .adoc .rst .txt)
LINT_ALL_FILES_INPUT="$1"
DIRECTORY_TO_LINT_INPUT="$2"

# ---- For PR comments START ----

Expand Down Expand Up @@ -84,16 +86,21 @@ containsElement () {
return 1
}

mapfile -t FILE_ARRAY < <( git diff --name-only "$MASTER_HASH" )
if [ "$LINT_ALL_FILES_INPUT" = "yes" ]; then
echo -e "${YELLOW}Linting all files from the directory ${BLUE}${DIRECTORY_TO_LINT_INPUT}${YELLOW}${NC}"
/vale --glob='*.{md,adoc,rst,txt}' "${DIRECTORY_TO_LINT_INPUT}" >> output.txt
else
mapfile -t FILE_ARRAY < <( git diff --name-only "$MASTER_HASH" )

for i in "${FILE_ARRAY[@]}"
do
if ( containsElement "${i: -3}" "${EXTENSION_ARRAY[@]}" ) || ( containsElement "${i: -4}" "${EXTENSION_ARRAY[@]}" ) || ( containsElement "${i: -5}" "${EXTENSION_ARRAY[@]}" ) ; then
/vale "${i}" >> output.txt
else
echo "${i}" >> ignored.txt
fi
done
for i in "${FILE_ARRAY[@]}"
do
if ( containsElement "${i: -3}" "${EXTENSION_ARRAY[@]}" ) || ( containsElement "${i: -4}" "${EXTENSION_ARRAY[@]}" ) || ( containsElement "${i: -5}" "${EXTENSION_ARRAY[@]}" ) ; then
/vale "${i}" >> output.txt
else
echo "${i}" >> ignored.txt
fi
done
fi

if [ -s output.txt ] ; then
echo -e "${YELLOW}=========================> ERRORS <========================="
Expand Down Expand Up @@ -128,9 +135,9 @@ else
echo -e "To add a new Secret, go to ${BLUE}Repository Settings > Secrets > Add a new secret${NC}"
echo -e "${GREEN}All good!${NC}"
else
check_events_json;
NUMBER=$(jq --raw-output .number "${GITHUB_EVENT_PATH}");
clean_up;
echo -e "${GREEN}All good!${NC}"
check_events_json;
NUMBER=$(jq --raw-output .number "${GITHUB_EVENT_PATH}");
clean_up;
echo -e "${GREEN}All good!${NC}"
fi
fi

0 comments on commit 5437f92

Please sign in to comment.