Skip to content

NPM Dependency Reports #314

NPM Dependency Reports

NPM Dependency Reports #314

name: NPM Dependency Reports
on:
schedule:
- cron: '0 15 * * 2' # Tuesday morning at 7:00-8:00am Pacific Time.
workflow_dispatch:
# START HERE! v
# ADD REQUIRED FILES:
# - .github/helpers/parse-json5-config.js
# - .github/helpers/npm-deps/parse-npm-deps.cjs
# - .github/helpers/npm-deps/create-report.cjs
# - .github/helpers/npm-deps/create-report-issues.cjs
# - .github/helpers/github-api/github-api-requests.cjs
# - .github/helpers/github-api/create-and-close-existing-issue.cjs
# - .github/config/dep-report.json5
# EDIT .github/config/dep-report.json5
# DO NOT Edit below env variables.
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
# Parse Vars from config.
parse-json5-config:
runs-on: ubuntu-22.04
outputs:
# save output from dep-report.json5 to Github env variables
packageJsonPaths: ${{ steps.parse_config.outputs.packageJsonPaths }}
ignoreList: ${{ steps.parse_config.outputs.ignoreList }}
depLevels: ${{ steps.parse_config.outputs.depLevels }}
steps:
# Checkout branch.
- name: Checkout Repository
uses: actions/checkout@v4
# Install json5 npm package for parsing config.
- name: Install Dependencies
run: npm install json5 os
# Run script to convert json5 config to Output Vars.
- name: Run Script
id: parse_config
run: node .github/helpers/parse-json5-config .github/config/dep-report.json5
# Check package versions for updates.
parse-package-versions:
runs-on: ubuntu-22.04
needs: parse-json5-config
env:
packageJsonPaths: ${{ needs.parse-json5-config.outputs.packageJsonPaths }}
container:
# Lightweight NodeJS Image
image: node:21.5-bullseye-slim
steps:
# Checkout branch.
- name: Checkout repository
uses: actions/checkout@v4
# Run NodeJS script to check for latest npm dependency versions and capture output.
- name: Run NPM DEP Check Node.js script
id: check_versions
run: |
node .github/helpers/npm-deps/parse-npm-deps.cjs > outdatedDeps.json
# Upload the output as an artifact.
- name: Upload output
uses: actions/upload-artifact@v4
with:
name: outdatedDeps
path: outdatedDeps.json
# Create comment text
create-comment-text:
runs-on: ubuntu-22.04
needs:
- parse-json5-config
- parse-package-versions
env:
ignoreList: ${{ needs.parse-json5-config.outputs.ignoreList }}
depLevels: ${{ needs.parse-json5-config.outputs.depLevels }}
outputs:
commentContents: ${{ steps.create_comment.outputs.commentContents }}
steps:
# download artifact from parse-package-versions
- name: Download output
uses: actions/download-artifact@v4
with:
name: outdatedDeps
path: .
# encode file to github needs
- name: Encode Outdated Deps
shell: bash
run: |
OUTPUT=$(cat outdatedDeps.json)
OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "DEP_INPUT=${OUTPUT}" >> $GITHUB_ENV
# checkout repo and branch
- name: Checkout Branch
uses: actions/checkout@v4
# setup Python environment
- name: setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11' # current Python version
# Run Python Script to Create Comment
- name: Create Comment Contents
id: create_comment
env:
DEP_INPUT: ${{ env.DEP_INPUT }} # dependency updates
run: |
python3 .github/helpers/npm-deps/parse_to_comment.py
# Write the output text for the GitHub Issue.
write-output:
needs:
- parse-json5-config
- parse-package-versions
runs-on: ubuntu-22.04
env:
packageJsonPaths: ${{ needs.parse-json5-config.outputs.packageJsonPaths }}
container:
# Lightweight NodeJS Image
image: node:21.5-bullseye-slim
steps:
# Checkout branch.
- name: Checkout repository
uses: actions/checkout@v4
# Download the output artifact from parse-package-versions.
- name: Download output
uses: actions/download-artifact@v4
with:
name: outdatedDeps
path: .
# Run NodeJS script to create GitHub Issue body.
- name: Run NPM DEP Check Node.js script
id: check_versions
run: |
node .github/helpers/npm-deps/create-report.cjs > outputText.json
# Upload the output as an artifact.
- name: Upload output
uses: actions/upload-artifact@v4
with:
name: outputText
path: outputText.json
# Create the GitHub Issues.
create-issues:
needs:
- parse-json5-config
- create-comment-text
- write-output
runs-on: ubuntu-22.04
env:
packageJsonPaths: ${{ needs.parse-json5-config.outputs.packageJsonPaths }}
commentContents: ${{ needs.create-comment-text.outputs.commentContents }}
container:
# Lightweight NodeJS Image
image: node:21.5-bullseye-slim
steps:
# Checkout branch.
- name: Checkout repository
uses: actions/checkout@v4
# Download the output artifact.
- name: Download output
uses: actions/download-artifact@v4
with:
name: outputText
path: .
# Install @octokit/rest npm package for making GitHub rest API requests.
- name: Install @octokit/rest npm
run: npm i @octokit/rest
# Run Node Script to Create GitHub Issue.
- name: Create GitHub Issues
run: |
node .github/helpers/npm-deps/create-report-issues.cjs