Github action for getting stats about npm dependencies
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.
- Loads dependency ignore settings from
.github/dependabot.yml
if it exists
The following workflow logs out dependency stats within Github Actions
name: Check Outdated Dependencies
on:
push:
branches:
- main
jobs:
check:
name: Check Dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 18.x
- 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 }} %)"
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: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
- 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"
ignore
input to ignore dependencies (instead of loading from dependabot config)- Use
npm outdated
if yarn is not being used - Output stats for multiple package levels in a single run
-
Why is the
dist
folder included on major version branches? 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). When using an exact version Github will pick up from releases, but using a major version point to the major version branch. -
Why Node 16?
This is the maximum version runtime supported by Github Actions