-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdependabot-runbook.ps1
More file actions
150 lines (113 loc) · 7.15 KB
/
Copy pathdependabot-runbook.ps1
File metadata and controls
150 lines (113 loc) · 7.15 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#Requires -Version 7.0
<#
.SYNOPSIS
Dependabot & Dependency Review runbook for gh CLI.
Module 6: Dependabot Config, Rules and Dependency Review Action.
.DESCRIPTION
On-demand commands to manage Dependabot version updates, security updates,
dependency review, and related PR workflows using the GitHub CLI.
.NOTES
Repository : timothywarner-org/globomantics-robot-fleet
Prereqs : gh auth login, PowerShell 7+
#>
$Owner = 'timothywarner-org'
$Repo = 'globomantics-robot-fleet'
$Nwo = "$Owner/$Repo"
# ─────────────────────────────────────────────
# 1. VERIFY PREREQUISITES
# ─────────────────────────────────────────────
Write-Host '=== 1. Checking prerequisites ===' -ForegroundColor Cyan
gh auth status
gh repo view $Nwo --json name,owner -q '"\(.owner.login)/\(.name)"'
# ─────────────────────────────────────────────
# 2. ENABLE DEPENDABOT FEATURES
# (a) Vulnerability alerts -> security updates depend on this
# (b) Dependabot security updates
# ─────────────────────────────────────────────
Write-Host '=== 2. Enabling Dependabot features ===' -ForegroundColor Cyan
# Enable vulnerability alerts (required for security update PRs)
gh api -X PUT "repos/$Nwo/vulnerability-alerts" --silent
Write-Host ' Vulnerability alerts enabled.' -ForegroundColor Green
# Enable Dependabot security updates (auto-fix PRs for CVEs)
gh api -X PUT "repos/$Nwo/automated-security-fixes" --silent
Write-Host ' Dependabot security updates enabled.' -ForegroundColor Green
# ─────────────────────────────────────────────
# 3. TRIGGER DEPENDABOT ON-DEMAND
# Pushing any change to dependabot.yml forces an immediate rescan.
# This adds a timestamp comment so the push is non-destructive.
# ─────────────────────────────────────────────
Write-Host '=== 3. Triggering Dependabot rescan ===' -ForegroundColor Cyan
$ConfigPath = '.github/dependabot.yml'
$Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzz'
# Read current file, append/update the last-triggered comment
$Content = Get-Content $ConfigPath -Raw
$MarkerPattern = '(?m)^# Last triggered:.*$'
$MarkerLine = "# Last triggered: $Timestamp"
if ($Content -match $MarkerPattern) {
$Content = $Content -replace $MarkerPattern, $MarkerLine
}
else {
$Content = $Content.TrimEnd() + "`n`n$MarkerLine`n"
}
Set-Content -Path $ConfigPath -Value $Content -NoNewline
git add $ConfigPath
git commit -m "deps: trigger Dependabot rescan $Timestamp"
git push
Write-Host " Pushed dependabot.yml update. Dependabot will rescan shortly." -ForegroundColor Green
# ─────────────────────────────────────────────
# 4. LIST DEPENDABOT ALERTS (security vulnerabilities)
# ─────────────────────────────────────────────
Write-Host '=== 4. Current Dependabot alerts ===' -ForegroundColor Cyan
gh api "repos/$Nwo/dependabot/alerts" --jq '.[] | "\(.state) | \(.security_advisory.severity) | \(.dependency.package.name) | \(.security_advisory.summary)"' | Format-Table
# ─────────────────────────────────────────────
# 5. LIST OPEN DEPENDABOT PRS (version + security)
# ─────────────────────────────────────────────
Write-Host '=== 5. Open Dependabot PRs ===' -ForegroundColor Cyan
gh pr list --repo $Nwo --author 'app/dependabot' --state open --json number,title,labels --template '{{range .}}#{{.number}} {{.title}} {{range .labels}}[{{.name}}] {{end}}{{"\n"}}{{end}}'
# ─────────────────────────────────────────────
# 6. CHECK DEPENDENCY REVIEW WORKFLOW RUNS
# ─────────────────────────────────────────────
Write-Host '=== 6. Recent dependency-review workflow runs ===' -ForegroundColor Cyan
gh run list --repo $Nwo --workflow 'Dependency Review' --limit 5
# ─────────────────────────────────────────────
# 7. LIVE DEMO: TEST VULNERABLE DEPENDENCY
# Creates a branch, adds a vulnerable package,
# opens a PR, and lets the dependency review action block it.
# ─────────────────────────────────────────────
function Start-VulnerableDepDemo {
Write-Host '=== 7. Live demo: vulnerable dependency PR ===' -ForegroundColor Cyan
$Branch = 'test-vulnerable-dep'
git checkout main
git pull origin main
git checkout -b $Branch
# Add serialize-javascript 3.0.0 (CVE-2020-7660, Critical)
$Pkg = Get-Content 'package.json' -Raw | ConvertFrom-Json
$Pkg.dependencies | Add-Member -NotePropertyName 'serialize-javascript' -NotePropertyValue '3.0.0' -Force
$Pkg | ConvertTo-Json -Depth 10 | Set-Content 'package.json'
git add package.json
git commit -m 'deps: add serialize-javascript for data serialization'
git push -u origin $Branch
gh pr create --title 'Add data serialization support' --body 'Adding serialize-javascript for robot telemetry data serialization.'
Write-Host ' PR created. Watch the Checks tab for the dependency review result.' -ForegroundColor Yellow
gh pr checks
}
# ─────────────────────────────────────────────
# 8. CLEAN UP DEMO BRANCH
# ─────────────────────────────────────────────
function Remove-VulnerableDepDemo {
Write-Host '=== 8. Cleaning up demo ===' -ForegroundColor Cyan
$Branch = 'test-vulnerable-dep'
gh pr close $Branch --delete-branch
git checkout main
git branch -D $Branch 2>$null
Write-Host ' Demo branch and PR cleaned up.' -ForegroundColor Green
}
# ─────────────────────────────────────────────
# MENU
# ─────────────────────────────────────────────
Write-Host ''
Write-Host 'Interactive commands available:' -ForegroundColor Magenta
Write-Host ' Start-VulnerableDepDemo - Run the live demo (Section 7)'
Write-Host ' Remove-VulnerableDepDemo - Clean up demo artifacts (Section 8)'
Write-Host ''
Write-Host 'Sections 1-6 ran automatically above.' -ForegroundColor DarkGray