-
Notifications
You must be signed in to change notification settings - Fork 269
164 lines (140 loc) · 6.62 KB
/
Copy pathlabel-dependabot.yml
File metadata and controls
164 lines (140 loc) · 6.62 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Label Dependabot PRs
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to test labeling on'
required: true
type: number
jobs:
label:
if: github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Label and triage Dependabot PR
uses: actions/github-script@v9
with:
script: |
// Get PR details - either from event payload or workflow input
let prNumber, prTitle, prBody;
if (context.eventName === 'workflow_dispatch') {
// Manual trigger - fetch PR details
prNumber = parseInt(context.payload.inputs.pr_number);
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
prTitle = pr.title;
prBody = pr.body || '';
} else {
// Automatic trigger from PR event
prNumber = context.payload.pull_request.number;
prTitle = context.payload.pull_request.title;
prBody = context.payload.pull_request.body || '';
}
// Bundler/AWS SDK updates can blow the 1MB Lambda@Edge bundle limit.
// This is the one piece of risk signal worth flagging automatically.
const lambdaEdgeRiskDeps = [
'webpack', '-loader', '-webpack-plugin', '@aws-sdk/'
];
// Extract dependency names from PR body
const dependencyPattern = /(?:Bumps|Updates) \[([^\]]+)\]/g;
const dependencies = [];
let match;
while ((match = dependencyPattern.exec(prBody)) !== null) {
dependencies.push(match[1]);
}
// Also check PR title for dependency names
const titleMatch = prTitle.match(/bump\s+(.+?)\s+from/i);
if (titleMatch) {
dependencies.push(titleMatch[1]);
}
// Flag Lambda@Edge bundling risk
let hasLambdaEdgeRisk = false;
for (const dep of dependencies) {
const depLower = dep.toLowerCase();
if (lambdaEdgeRiskDeps.some(pattern => depLower.includes(pattern.toLowerCase()))) {
hasLambdaEdgeRisk = true;
}
}
// Prepare labels to add (`dependencies` is already applied via dependabot.yml)
const labelsToAdd = ['dependencies'];
// Check for security updates
const isSecurity = prTitle.toLowerCase().includes('security') ||
prBody.toLowerCase().includes('security');
if (isSecurity) {
labelsToAdd.push('deps-security-patch');
}
// Check for bulk updates (10+ dependencies)
if (dependencies.length >= 10) {
labelsToAdd.push('deps-bulk-update');
}
// Add Lambda@Edge risk flag
if (hasLambdaEdgeRisk) {
labelsToAdd.push('deps-lambda-edge-risk');
}
// Add ecosystem label based on PR labels
const existingLabels = context.payload.pull_request.labels.map(l => l.name);
if (existingLabels.includes('npm')) labelsToAdd.push('npm');
if (existingLabels.includes('github-actions')) labelsToAdd.push('github-actions');
// Apply labels
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: labelsToAdd
});
console.log(`Applied labels: ${labelsToAdd.join(', ')}`);
} catch (error) {
console.error('Failed to apply labels:', error.message);
core.setFailed(`Failed to apply labels: ${error.message}`);
}
// Generate triage comment
let triageComment = '## Automated Dependabot Triage\n\n';
triageComment += `**Dependencies:** ${dependencies.length > 0 ? dependencies.join(', ') : 'See PR body'}\n\n`;
if (isSecurity) {
triageComment += '🔒 **Security Update** - Prioritize: evaluate and merge promptly.\n\n';
}
triageComment += '**Evaluate and merge:**\n';
triageComment += '- [ ] Run `make build` (or `make serve-all` for browser-facing changes) and verify the site builds and loads\n';
triageComment += '- [ ] Spot-check search, console errors, and markdown rendering\n';
triageComment += '- [ ] Merge once CI is green\n\n';
if (hasLambdaEdgeRisk) {
triageComment += '🚨 **Lambda@Edge Risk** - This update affects webpack, bundlers, or AWS SDK. ';
triageComment += 'See [Infrastructure Change Review](https://github.com/pulumi/docs/blob/master/BUILD-AND-DEPLOY.md#infrastructure-change-review) ';
triageComment += 'section for deployment risks.\n\n';
}
if (dependencies.length >= 10) {
triageComment += '📦 **Bulk Update** - 10+ dependencies. Review carefully for conflicts.\n\n';
}
triageComment += '### Claude Code Review\n\n';
triageComment += 'Automated Claude reviews are not available for Dependabot PRs. ';
triageComment += 'To review this PR with Claude Code, run:\n\n';
triageComment += '```bash\n';
triageComment += `/pr-review ${prNumber}\n`;
triageComment += '```\n\n';
triageComment += '---\n';
triageComment += 'For detailed triage guidance, see the [Dependency Management](https://github.com/pulumi/docs/blob/master/BUILD-AND-DEPLOY.md#dependency-management) section in BUILD-AND-DEPLOY.md.\n';
// Post comment
try {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: triageComment
});
console.log(`Posted triage comment for ${dependencies.length} dependencies`);
} catch (error) {
console.error('Failed to post comment:', error.message);
// Don't fail the workflow if comment posting fails
}