|
| 1 | +name: "Reminder for 'run npm audit'" |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 22 * * *' |
| 6 | + workflow_dispatch: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - 'master' |
| 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-sdk-nodejs' |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 20 | + - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 |
| 21 | + with: |
| 22 | + node-version: '24' |
| 23 | + |
| 24 | + - name: Run npm audit and check diff |
| 25 | + id: audit |
| 26 | + run: ./scripts/npm-audit.sh |
| 27 | + continue-on-error: true |
| 28 | + |
| 29 | + - name: Create or update reminder issue |
| 30 | + if: steps.audit.outcome == 'failure' |
| 31 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 32 | + env: |
| 33 | + TZ: 'Asia/Tokyo' |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const { owner, repo } = context.repo; |
| 37 | + const title = 'Reminder: run npm audit'; |
| 38 | + const securityURL = `https://github.com/${owner}/${repo}/security`; |
| 39 | + const baseBody = [ |
| 40 | + 'Fix all vulnerabilities. You can check with `./scripts/npm-audit.sh` locally, then send a PR with the fixes.', |
| 41 | + `After fixing, make sure the vulnerabilities count in **${securityURL}** is **0**.` |
| 42 | + ].join('\n\n'); |
| 43 | +
|
| 44 | + const { data: result } = await github.rest.search.issuesAndPullRequests({ |
| 45 | + q: `repo:${owner}/${repo} is:issue is:open in:title "${title}"` |
| 46 | + }); |
| 47 | +
|
| 48 | + const today = new Date(); |
| 49 | +
|
| 50 | + if (result.total_count === 0) { |
| 51 | + await github.rest.issues.create({ |
| 52 | + owner, |
| 53 | + repo, |
| 54 | + title, |
| 55 | + body: `${baseBody}\n\n0 days have passed.` |
| 56 | + }); |
| 57 | + } else { |
| 58 | + const issue = result.items[0]; |
| 59 | + const created = new Date(issue.created_at); |
| 60 | + const diffDays = Math.floor((today - created) / 86_400_000); |
| 61 | + await github.rest.issues.update({ |
| 62 | + owner, |
| 63 | + repo, |
| 64 | + issue_number: issue.number, |
| 65 | + body: `${baseBody}\n\n${diffDays} days have passed.` |
| 66 | + }); |
| 67 | + } |
0 commit comments