Skip to content

Commit 313fcdc

Browse files
committed
NO-ISSUE Reminder for npm audit fix
1 parent 5d36a87 commit 313fcdc

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

.github/scripts/npm-audit.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
IFS=$'\n'
5+
locks=($(find . -path '*/node_modules' -prune -o -name package-lock.json -print))
6+
unset IFS
7+
8+
declare -a failed=()
9+
10+
for lock in "${locks[@]}"; do
11+
dir=$(dirname "$lock")
12+
printf '\n\n\033[1;34m==> %s\033[0m\n' "$dir"
13+
14+
pushd "$dir" >/dev/null
15+
if ! npm audit --audit-level moderate; then
16+
failed+=("$dir")
17+
fi
18+
popd >/dev/null
19+
done
20+
21+
if ((${#failed[@]})); then
22+
echo -e "\n\033[0;31mnpm audit reported vulnerabilities in:\033[0m"
23+
printf ' - %s\n' "${failed[@]}"
24+
exit 1
25+
else
26+
echo "npm audit passed: no vulnerabilities detected"
27+
exit 0
28+
fi

.github/workflows/npm-audit.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "Reminder for 'run npm audit'"
2+
3+
on:
4+
schedule:
5+
- cron: '0 22 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-npm-audit:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
issues: write
14+
if: github.repository == 'line/line-bot-mcp-server'
15+
steps:
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
17+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
18+
with:
19+
node-version: '24'
20+
21+
- name: Run npm audit and check diff
22+
id: audit
23+
run: ./scripts/npm-audit.sh
24+
continue-on-error: true
25+
26+
- name: Create or update reminder issue
27+
if: steps.audit.outcome == 'failure'
28+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
29+
env:
30+
TZ: 'Asia/Tokyo'
31+
with:
32+
script: |
33+
const { owner, repo } = context.repo;
34+
const title = 'Reminder: run npm audit';
35+
const securityURL = `https://github.com/${owner}/${repo}/security`;
36+
const baseBody = [
37+
'Fix all vulnerabilities. You can check with `.github/scripts/npm-audit.sh` locally, then send a PR with the fixes.',
38+
`After fixing, make sure the vulnerabilities count in **${securityURL}** is **0**.`
39+
].join('\n\n');
40+
41+
const { data: result } = await github.rest.search.issuesAndPullRequests({
42+
q: `repo:${owner}/${repo} is:issue is:open in:title "${title}"`
43+
});
44+
45+
const today = new Date();
46+
47+
if (result.total_count === 0) {
48+
await github.rest.issues.create({
49+
owner,
50+
repo,
51+
title,
52+
body: `${baseBody}\n\n0 days have passed.`
53+
});
54+
} else {
55+
const issue = result.items[0];
56+
const created = new Date(issue.created_at);
57+
const diffDays = Math.floor((today - created) / 86_400_000);
58+
await github.rest.issues.update({
59+
owner,
60+
repo,
61+
issue_number: issue.number,
62+
body: `${baseBody}\n\n${diffDays} days have passed.`
63+
});
64+
}

0 commit comments

Comments
 (0)