Repository navigation
100 lines (93 loc) · 4.23 KB
/
Copy pathaudit-fix.yml
File metadata and controls
100 lines (93 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Dependency audit fix
# audit-schedule.yml runs the advisory gate daily and files a
# `dependency-audit` issue when it is red. Each of its early red runs was
# resolved by hand with the same mechanical step, a lockfile bump to a
# patched release that already sat inside the ranges package.json allows.
# This workflow runs that step when the scheduled audit fails, and opens the
# pull request if the gate is green on the result.
#
# It is a separate workflow rather than a second job there so the audit lane
# keeps its issues-only token and single-gate cost (tests/audit-schedule-
# contract.test.mjs pins both), and only this lane holds contents and
# pull-requests write scope.
#
# `npm audit fix --package-lock-only` moves nothing outside the existing
# semver ranges and never touches package.json, so the diff a reviewer sees is
# the lockfile alone. When the gate is still red afterwards the patched release
# is outside the ranges, which needs an `overrides` floor and a SECURITY.md row
# a person has to choose; this job then fails and the scheduled lane's issue
# stays the notification, as before.
#
# A pull request opened with the workflow token does not itself trigger ci.yml;
# a maintainer closes and reopens it, or pushes to it, to start the checks.
on:
workflow_run:
workflows: [Dependency audit]
types: [completed]
branches: [main]
workflow_dispatch:
permissions:
contents: read
# Serialised on the branch this workflow force-pushes; see the note in
# refresh-radar-reports.yml. Not cancelled, for the same reason.
concurrency:
group: automation/audit-fix
cancel-in-progress: false
jobs:
remediate:
name: Open a lockfile fix for the advisories npm can patch in range
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: write
pull-requests: write
# A green or cancelled audit run leaves nothing to fix.
if: >-
github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'failure'
steps:
- name: Check out main
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ./.github/actions/setup-node-deps
# Proceed only when the gate is red on main as checked out. A manual
# dispatch while it is green would otherwise still rewrite the lockfile:
# `npm audit fix` normalises fields npm no longer emits, and the result
# would be a pull request that moves no advisory.
- name: Confirm the gate is red
id: gate
run: |
if npm run check:audit; then
echo 'red=false' >> "$GITHUB_OUTPUT"
else
echo 'red=true' >> "$GITHUB_OUTPUT"
fi
# Rewrites package-lock.json only; the re-run gate below reads it.
- if: steps.gate.outputs.red == 'true'
run: npm audit fix --package-lock-only
# The versions `npm audit fix` just resolved have not been reviewed by
# anyone, and this is the only job in the repository that installs
# unreviewed versions while holding contents: write and
# pull-requests: write. Install them without running their lifecycle
# scripts: `npm run check:audit` reads the lockfile and
# `npm run test:unit` is `node --test`, so neither needs a postinstall.
- if: steps.gate.outputs.red == 'true'
run: npm ci --ignore-scripts
- if: steps.gate.outputs.red == 'true'
run: npm run check:audit
- if: steps.gate.outputs.red == 'true'
run: npm run test:unit
- if: steps.gate.outputs.red == 'true'
uses: ./.github/actions/open-automation-pr
with:
branch: automation/audit-fix
commit-message: 'fix(deps): move patched advisories in the lockfile'
title: 'fix(deps): move patched advisories in the lockfile'
body: |
The scheduled dependency audit failed on `main`, and
`npm audit fix --package-lock-only` resolved every gated advisory
inside the lockfile's existing semver ranges. No `overrides`
floor or `package.json` change was needed.
`npm run check:audit` and the unit suite passed on this lockfile.
Remit: security exposure; `npm run check:audit` failing on `main`.