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