Skip to content

Commit 2feb4ae

Browse files
committed
NO-ISSUE Reminder for npm audit fix
1 parent b39ce60 commit 2feb4ae

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

.github/workflows/npm-audit.yml

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

scripts/npm-audit.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
find . -name package-lock.json \
2+
-not -path "./node_modules/*" \
3+
-execdir sh -c '
4+
printf "\033[1;34m==> %s\033[0m\n" "$PWD"
5+
npm audit fix --force
6+
' \;
7+
8+
if [ -n "$(git status --porcelain)" ]; then
9+
echo "Changes detected after 'npm audit fix'"
10+
exit 1
11+
else
12+
echo "No changes detected after 'npm audit fix'"
13+
fi

0 commit comments

Comments
 (0)