Skip to content

Commit

Permalink
feat: add reusable eslint action
Browse files Browse the repository at this point in the history
Runs the eslint defined in the given package.json, configured by the associated eslint.config.mjs file.
  • Loading branch information
CallumNZ committed Jun 11, 2024
1 parent be46066 commit 7479db1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/reusable-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: reusable eslint
on:
workflow_call:
inputs:
paths:
required: true
type: string
description: |
A list of root directory/s to where a package.json and eslint
configuration file (eslint.config.mjs) exist.
e.g.: my/root/one my/cool/root/two
jobs:
eslint:
runs-on: ubuntu-latest
steps:
- if: ${{ startsWith(github.repository, 'GeoNet/') == false }}
name: require GeoNet org
run: |
exit 1
- name: Parse paths
id: parse-paths
run: |
if [ -n "${{ inputs.paths }}" ]; then
echo "paths=$(echo '${{ inputs.paths }}' | tr '\n' ' ')" >> $GITHUB_OUTPUT
else
exit 1
fi
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '20.x'
- name: Install Node modules
id: install-node-modules
env:
PATHS: ${{ steps.parse-paths.outputs.paths }}
run: |
echo "$PATHS" | tr ' ' '\n' | xargs -i -n 1 npm install --prefix '{}'
- name: Run ESLint
id: eslint
env:
PATHS: ${{ steps.parse-paths.outputs.paths }}
run: |
echo "$PATHS" | tr ' ' '\n' | xargs -I '{}' -n 1 sh -c 'ESLINT_USE_FLAT_CONFIG=true $1/node_modules/.bin/eslint -c $1/eslint.config.mjs "$1"' _ '{}'
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [Markdown lint](#markdown-lint)
- [Copy to S3](#copy-to-s3)
- [Clean container versions](#clean-container-versions)
- [ESLint](#eslint)
- [Composite Actions](#composite-actions)
- [Tagging](#tagging)
- [Other documentation](#other-documentation)
Expand Down Expand Up @@ -1092,6 +1093,30 @@ jobs:
number-kept: 7
```

### ESLint

STATUS: alpha

Used to run ESLint on one or more directories. The paths specified
should have a package.json with eslint defined, alongside an eslint config
file named eslint.config.mjs.

```yaml
name: eslint
on:
push: {}
pull_request: {}
workflow_dispatch: {}
jobs:
eslint:
uses: GeoNet/Actions/.github/workflows/reusable-eslint.yml@main
with:
paths: |
./root/folder/one
./cool/root/folder/two
```


## Composite Actions

### Tagging
Expand Down

0 comments on commit 7479db1

Please sign in to comment.