|
| 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 | + } |
0 commit comments