mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
chore(ci): add npm-audit-fix workflow and helper script, expose audit-fix npm script
This commit is contained in:
48
.github/workflows/npm-audit-fix.yml
vendored
Normal file
48
.github/workflows/npm-audit-fix.yml
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
name: NPM Audit Fix
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
npm-audit-fix:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Run npm audit fix across packages
|
||||
run: npm run audit-fix
|
||||
|
||||
- name: Detect changes
|
||||
id: changes
|
||||
run: |
|
||||
if git status --porcelain | grep .; then
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Commit changes
|
||||
if: steps.changes.outputs.has_changes == 'true'
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add -A
|
||||
git commit -m "chore: npm audit fix"
|
||||
|
||||
- name: Push changes
|
||||
if: steps.changes.outputs.has_changes == 'true'
|
||||
run: |
|
||||
git push origin HEAD
|
||||
35
npm-audit-fix.sh
Normal file
35
npm-audit-fix.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
ROOT_DIR="$(pwd)"
|
||||
EXIT_CODE=0
|
||||
|
||||
while IFS= read -r -d '' package_json; do
|
||||
PROJECT_DIR="$(dirname "$package_json")"
|
||||
DISPLAY_DIR="${PROJECT_DIR#./}"
|
||||
|
||||
echo "Running npm audit fix in ${DISPLAY_DIR:-.}"
|
||||
|
||||
if ! cd "$PROJECT_DIR"; then
|
||||
echo "Skipping ${DISPLAY_DIR:-.}: cannot change directory" >&2
|
||||
EXIT_CODE=1
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ ! -f "package-lock.json" ] && [ ! -f "npm-shrinkwrap.json" ]; then
|
||||
echo "Skipping ${DISPLAY_DIR:-.}: no package-lock.json or npm-shrinkwrap.json"
|
||||
cd "$ROOT_DIR"
|
||||
continue
|
||||
fi
|
||||
|
||||
if ! npm audit fix; then
|
||||
echo "npm audit fix failed in ${DISPLAY_DIR:-.}" >&2
|
||||
EXIT_CODE=1
|
||||
fi
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
done < <(find . -name package.json -not -path '*/node_modules/*' -print0)
|
||||
|
||||
exit $EXIT_CODE
|
||||
@@ -38,6 +38,7 @@
|
||||
"uninstall": "bash uninstall.sh",
|
||||
"clean-modules": "bash remove-node-modules.sh",
|
||||
"install-modules": "bash install-node-modules.sh",
|
||||
"audit-fix": "bash npm-audit-fix.sh",
|
||||
"lint": "export NODE_OPTIONS='--max-old-space-size=32768' && npx eslint . --cache",
|
||||
"fix-lint": "export NODE_OPTIONS='--max-old-space-size=32768' && npx eslint . --fix --cache --debug",
|
||||
"fix": "npm run fix-lint",
|
||||
|
||||
Reference in New Issue
Block a user