public-js/eslint-plugin-node

View on GitHub
.github/actions/nodejs/action.yml

Summary

Maintainability
Test Coverage
name: Action for Node.js & cache
description: Node.js setup and cache

inputs:
  node-version:
    description: Node.js version
    required: false
    default: 18.x

outputs:
  root-package-version:
    description: Full version from root package.json
    value: ${{ steps.output.outputs.root-package-version }}
  root-package-major-version:
    description: Major version from root package.json
    value: ${{ steps.output.outputs.root-package-major-version }}

runs:
  using: composite
  steps:
    - name: Additional debug logs
      shell: bash
      run: |
        echo "github.workflow: ${{ github.workflow }}"
        echo "github.sha: ${{ github.sha }}"
        echo "github.ref: ${{ github.ref }}"
        echo "github.ref_name: ${{ github.ref_name }}"
        echo "github.ref_type: ${{ github.ref_type }}"
        echo "github.base_ref: ${{ github.base_ref }}"
        echo "github.head_ref: ${{ github.head_ref }}"
        echo "github.run_id: ${{ github.run_id }}"
        echo "github.run_number: ${{ github.run_number }}"
        echo "github.run_attempt: ${{ github.run_attempt }}"
        echo "github.event.number: ${{ github.event.number }}"
        echo "github.event.pull_request.head.ref: ${{ github.event.pull_request.head.ref }}"
        echo "github.event.pull_request.head.repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}"

    - name: Use Node.js ${{ inputs.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ inputs.node-version }}
        registry-url: 'https://registry.npmjs.org'

    - name: Restore node_modules from cache
      id: cache-node-modules
      uses: actions/cache@v3
      with:
        path: |
          **/node_modules/
          !**/node_modules/.cache
        key: modules-cache__nodejs-${{ inputs.node-version }}__${{ hashFiles('package-lock.json') }}

    - name: Restore from global npm cache
      if: steps.cache-node-modules.outputs.cache-hit != 'true'
      uses: actions/cache@v3
      with:
        path: ~/.npm
        key: npm-cache__nodejs-${{ inputs.node-version }}__${{ hashFiles('package-lock.json') }}
        restore-keys: npm-cache-hash__

    - shell: bash
      run: |
        echo "Environment info: Node.js, npm"
        node -v
        npm -v

    - shell: bash
      run: |
        echo "Providing global variables"
        echo "TIMING=true" >> $GITHUB_ENV
        echo "NPM_CONFIG_CACHE=~/.npm" >> $GITHUB_ENV

    - name: Clean install dependencies
      if: steps.cache-node-modules.outputs.cache-hit != 'true'
      run: npm ci
      shell: bash

    - id: output
      shell: bash
      run: |
        echo "root-package-version=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
        echo "root-package-major-version=$(node -p "parseInt(require('./package.json').version)")" >> $GITHUB_OUTPUT