Skip to content

Added Workflow to Check for Outdated npm Packages #20

Added Workflow to Check for Outdated npm Packages

Added Workflow to Check for Outdated npm Packages #20

Workflow file for this run

name: Trivy Vulnerability and Secret Scan
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
trivy_scan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Dependencies
run: |
npm install --no-audit
- name: Run Trivy vulnerability scan
run: |
docker run --rm -v ${{ github.workspace }}:/src aquasec/trivy:latest fs /src \
--severity CRITICAL,HIGH \
--ignore-unfixed \
--scanners vuln \
--format table > trivy-vuln-report.txt
- name: Run Trivy secret scan
run: |
docker run --rm -v ${{ github.workspace }}:/src aquasec/trivy:latest fs /src \
--scanners secret \
--format table > trivy-secret-report.txt
# custom check
- name: Check for outdated npm packages
run: |
npm outdated > npm-outdated-report.txt || echo "Some packages may be outdated."
- name: Updates the outdated dependencies
run:
npx npm-check-updates -u
npm update
- name: Commit changes push them
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add package.json package-lock.json
git commit -m "chore: update outdated npm packages"
git push origin HEAD || echo "No changes to push"
- name: Create Pull Request for updated Dependenncies
uses: peter-evans/create-pull-request@v5
with:
branch: update-dependencies-branch
title: "chore: update outdated npm dependencies"
body: |
This PR updates the following outdated npm dependencies:
- Updated dependencies using npm-check-updates
- Automatically created by GitHub Actions
commit-message: "chore: update outdated npm dependencies"
labels: "dependencies, automated update"
assignees: "your-github-username" # Optional: assign the PR to someone
- name: Handling empty files
run: |
is_empty(){
file_name="$1"
content="$2"
if [ ! -s "$file_name" ]; then
echo "$content" > "$file_name"
fi
}
is_empty trivy-vuln-report.txt "No vulnerability found"
is_empty trivy-secret-report.txt "No Secret expose found"
is_empty npm-outdated-report.txt "No outdated package found"
- name: Generate Enhanced Security Report
run: |
cat << EOF > trivy-V-and-S-Scan-report.md
# Security Scan Report
## Table of Contents
- [Trivy Vulnerability Scan](#trivy-vulnerability-scan)
- [Trivy Secrets Scan](#trivy-secrets-scan)
- [NPM Outdated Packages](#npm-outdated-packages)
## Trivy Vulnerability Scan
\`\`\`
$(if [ -s trivy-vuln-report.txt ]; then cat trivy-vuln-report.txt; else echo "No vulnerabilities found."; fi)
\`\`\`
## Trivy Secrets Scan
\`\`\`
$(if [ -s trivy-secret-report.txt ]; then cat trivy-secret-report.txt; else echo "No secrets found."; fi)
\`\`\`
## NPM Outdated Packages
\`\`\`
$(if [ -s npm-outdated-report.txt ]; then cat npm-outdated-report.txt; else echo "No outdated packages found."; fi)
\`\`\`
---
Report generated on $(date)
EOF
- name: Display Combined Report
run: cat trivy-V-and-S-Scan-report.md
- name: Upload Combined Report
uses: actions/upload-artifact@v4
with:
name: trivy scan (vs and ss)
path: trivy-V-and-S-Scan-report.md