@side/npm-dependency-stats-action

    2.1.2 • Public • Published

    NPM Dependency Stats Action

    Github action for getting stats about npm dependencies

    NPM version Build Status Code Coverage License semantic-release Code Style

    NOTE: Currently only packages using yarn are supported since the yarn outdated command is used. There is a plan to support npm in the future.

    Features

    • Loads dependency ignore settings from .github/dependabot.yml if it exists

    Examples

    Basic

    The following workflow logs out dependency stats within Github Actions

    name: Check Outdated Dependencies
    
    on:
      push:
        branches:
          - master
    
    jobs:
      check:
        name: Check Dependencies
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            os: [ubuntu-20.04]
            node-version: [14.x]
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
    
          - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
            uses: actions/setup-node@v2.1.5
            with:
              node-version: ${{ matrix.node-version }}
    
          - name: Check Outdated
            id: dep-stats
            uses: reside-eng/npm-dependency-stats-action@v1
            with:
              output-file: ./dep-stats.json
    
          - name: Message Outdated
            run: |
              echo "counts: ${{ fromJSON(steps.dep-stats.outputs.counts) }}"
              percents=${{ fromJSON(steps.dep-stats.outputs.percents) }}
              counts=${{ fromJSON(steps.dep-stats.outputs.counts) }}
              totalDeps=${{ fromJSON(steps.dep-stats.outputs.counts).total }}
              echo "counts total: $counts.total"
              echo "up to date: ${{ fromJSON(steps.dep-stats.outputs.counts).upToDate }}/$totalDeps (${{ fromJSON(steps.dep-stats.outputs.percents).upToDate }} %)"
              echo "major behind: ${{ fromJSON(steps.dep-stats.outputs.counts).major }}/$totalDeps (${{ fromJSON(steps.dep-stats.outputs.percents).major }} %)"
              echo "minor behind: ${{ fromJSON(steps.dep-stats.outputs.counts).minor }}/$totalDeps (${{ fromJSON(steps.dep-stats.outputs.percents).minor }} %)"
              echo "patch behind: ${{ fromJSON(steps.dep-stats.outputs.counts).patch }}/$totalDeps (${{ fromJSON(steps.dep-stats.outputs.percents).patch }} %)"

    Save File And Upload

    The following workflow saves a file of stats information which is then uploaded to Google Cloud Storage. This is useful if you would like to load this data in another tool, such as Retool.

    name: Check Outdated Dependencies
    
    on:
      push:
        branches:
          - master
    
    jobs:
      check:
        name: Upload Dependency Stats
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            os: [ubuntu-20.04]
            node-version: [14.x]
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
    
          - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
            uses: actions/setup-node@v2.1.5
            with:
              node-version: ${{ matrix.node-version }}
    
          - name: Check Outdated
            id: dep-stats
            uses: reside-eng/npm-dependency-stats-action@v1
            with:
              output-file: ./dep-stats.json
    
          # Setup gcloud CLI for uploading to storage in "Deploy Changed Functions" step
          - name: Set up Google Cloud SDK
            uses: google-github-actions/setup-gcloud@master
            with:
              project_id: "some-project"
              service_account_key: ${{ secrets.STAGE_SERVICE_ACCOUNT }}
              export_default_credentials: true
    
            # Deploy only Cloud Functions which have changed based on cache stored in Google Cloud Storage
          - name: Upload Dependency Stats To Cloud Storage
            run: |
              echo "Uploading results to cloud storage"
              echo ""
              bucket=some-project.appspot.com
              depStatsFolder=dependency-stats
              gsutil -m -q cp ./dep-stats.json gs://$bucket/$depStatsFolder/$(date +%Y-%m-%d_%H-%M-%S).json
              gsutil -m -q cp ./dep-stats.json gs://$bucket/$depStatsFolder/latest.json
              echo ""
              echo "Successfully uploaded dependency stats to Cloud Storage"

    Ideas

    • ignore input to ignore dependencies (instead of loading from dependabot config)
    • Setting to only check production dependencies (not include dev dependencies)
    • Use npm outdated if yarn is not being used
    • Output stats for multiple package levels in a single run

    FAQ

    1. Why is the dist folder included in the repo? This is a built version of the action which is necessary to have in place for Github Actions to be able to use the action since the action's source code is written in Typescript (Actions runs Node)

    Keywords

    none

    Install

    npm i @side/npm-dependency-stats-action

    DownloadsWeekly Downloads

    52

    Version

    2.1.2

    License

    MIT

    Unpacked Size

    484 kB

    Total Files

    33

    Last publish

    Collaborators

    • reside-eng