diff --git a/.github/workflows/reusable-eslint.yml b/.github/workflows/reusable-eslint.yml new file mode 100644 index 0000000..2223cad --- /dev/null +++ b/.github/workflows/reusable-eslint.yml @@ -0,0 +1,39 @@ +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 + - 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: ${{ inputs.paths }} + run: | + for path in $PATHS; do + npm install --prefix $path + done + - name: Run ESLint + id: eslint + env: + PATHS: ${{ inputs.paths }} + run: | + for path in $PATHS; do + ESLINT_USE_FLAT_CONFIG=true $path/node_modules/.bin/eslint -c $path/eslint.config.mjs + done diff --git a/README.md b/README.md index 1dbe576..d3b5d25 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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