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

Add working directory flag to allow use of action from non-root directory #19

Merged
merged 7 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,30 @@ jobs:
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-check
eslint_flags: 'testdata/'
eslint_flags: 'testdata/ --ignore-pattern /test-subproject/'
- name: eslint-github-check
uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: warning
eslint_flags: 'testdata/'
eslint_flags: 'testdata/ --ignore-pattern /test-subproject/'
- name: eslint-github-pr-review
uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
eslint_flags: 'testdata/'
eslint_flags: 'testdata/ --ignore-pattern /test-subproject/'
- name: eslint-subproject-github-pr-review
uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
workdir: ./test-subproject
eslint_flags: 'test-subproject/sub-testdata/'
- name: eslint-subproject
uses: ./
with:
github_token: ${{ secrets.github_token }}
workdir: ./test-subproject
eslint_flags: 'test-subproject/sub-testdata/'
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ github-pr-review can use Markdown and add a link to rule page in reviewdog repor

Optional. Flags and args of eslint command. Default: '.'

### `workdir`

Optional. The directory from which look for and run eslint. Default '.'

## Example usage

You also need to install [eslint](https://github.com/eslint/eslint).
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
eslint_flags:
description: "flags and args of eslint command. Default: '.'"
default: '.'
workdir:
description: "The directory from which look for and run eslint. Default '.'"
default: '.'
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
14 changes: 9 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ cd "$GITHUB_WORKSPACE"

export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"

if [ ! -f "$(npm bin)/eslint" ]; then
npm install
ESLINT_COMMAND="$(npm bin --prefix $INPUT_WORKDIR)/eslint"
LaurenceGA marked this conversation as resolved.
Show resolved Hide resolved

if [ ! -f $ESLINT_COMMAND ]; then
npm install --prefix $INPUT_WORKDIR
fi

$(npm bin)/eslint --version
eval $ESLINT_COMMAND --version

if [ "${INPUT_REPORTER}" == 'github-pr-review' ]; then
# Use jq and github-pr-review reporter to format result to include link to rule page.
$(npm bin)/eslint -f="json" ${INPUT_ESLINT_FLAGS:-'.'} \
eval $ESLINT_COMMAND --resolve-plugins-relative-to $INPUT_WORKDIR \
-f="json" -c $INPUT_WORKDIR/.eslintrc.* ${INPUT_ESLINT_FLAGS:-$INPUT_WORKDIR} \
| jq -r '.[] | {filePath: .filePath, messages: .messages[]} | "\(.filePath):\(.messages.line):\(.messages.column):\(.messages.message) [\(.messages.ruleId)](https://eslint.org/docs/rules/\(.messages.ruleId))"' \
| reviewdog -efm="%f:%l:%c:%m" -name="eslint" -reporter=github-pr-review -level="${INPUT_LEVEL}"
else
# github-pr-check,github-check (GitHub Check API) doesn't support markdown annotation.
$(npm bin)/eslint -f="stylish" ${INPUT_ESLINT_FLAGS:-'.'} \
eval $ESLINT_COMMAND --resolve-plugins-relative-to $INPUT_WORKDIR \
-f="stylish" -c $INPUT_WORKDIR/.eslintrc.* ${INPUT_ESLINT_FLAGS:-$INPUT_WORKDIR} \
| reviewdog -f="eslint" -reporter="${INPUT_REPORTER:-github-pr-check}" -level="${INPUT_LEVEL}"
fi
19 changes: 19 additions & 0 deletions test-subproject/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"standard"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
}
};
1 change: 1 addition & 0 deletions test-subproject/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
Loading