-
Notifications
You must be signed in to change notification settings - Fork 45
331 lines (309 loc) · 12 KB
/
Copy pathupdate-deps.yml
File metadata and controls
331 lines (309 loc) · 12 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
name: update-deps
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
on:
workflow_dispatch:
schedule:
- cron: '0 9 * * *'
push:
branches:
- 'main'
jobs:
update:
runs-on: ubuntu-24.04
environment: update-deps # secrets are gated by this environment
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
strategy:
fail-fast: false
matrix:
dep:
- docker
- buildx
- buildkit
- compose
- cosign
- regctl
- undock
steps:
-
name: GitHub auth token from GitHub App
id: write-app
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.GHACTIONS_REPO_WRITE_CLIENT_ID }}
private-key: ${{ secrets.GHACTIONS_REPO_WRITE_PRIVATE_KEY }}
owner: docker
repositories: actions-toolkit
permission-contents: write
permission-pull-requests: write
permission-workflows: write
-
name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
token: ${{ steps.write-app.outputs.token }}
fetch-depth: 0
persist-credentials: false
-
name: Update dependency
id: update
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_DEP: ${{ matrix.dep }}
with:
script: |
const fs = require('fs');
const path = require('path');
const dep = core.getInput('dep');
function escapeRegExp(value) {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function formatList(values) {
const quoted = values.map(value => `\`${value}\``);
if (quoted.length === 1) {
return quoted[0];
}
if (quoted.length === 2) {
return `${quoted[0]} and ${quoted[1]}`;
}
return `${quoted.slice(0, -1).join(', ')}, and ${quoted.at(-1)}`;
}
function unique(values) {
return [...new Set(values)];
}
function stripLeadingV(value) {
return value.startsWith('v') ? value.slice(1) : value;
}
function stripDockerTag(value) {
return value.replace(/^docker-v/, '').replace(/^v/, '');
}
function majorMinor(value) {
const match = value.match(/^(\d+\.\d+)/);
if (!match) {
throw new Error(`Unable to derive major.minor version from ${value}`);
}
return match[1];
}
function readJson(relativePath) {
const absolutePath = path.join(process.env.GITHUB_WORKSPACE, relativePath);
return JSON.parse(fs.readFileSync(absolutePath, 'utf8'));
}
function readLatestTag(relativePath) {
const tag = readJson(relativePath)?.latest?.tag_name;
if (!tag) {
throw new Error(`Unable to resolve latest tag from ${relativePath}`);
}
return tag;
}
function dockerfileArgPattern(key) {
return new RegExp(`^(ARG ${escapeRegExp(key)}=)(.+)$`, 'm');
}
function workflowEnvPattern(key) {
return new RegExp(`^( ${escapeRegExp(key)}: ")([^"]*)(")$`, 'm');
}
const dependencyConfigs = {
docker: {
name: 'Docker version',
branch: 'deps/docker-version',
sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/docker-releases.json',
async resolve() {
const tag = readLatestTag('.github/docker-releases.json');
const version = majorMinor(stripDockerTag(tag));
return {
titleValue: version,
targets: [
{
path: 'dev.Dockerfile',
key: 'DOCKER_VERSION',
value: version,
pattern: dockerfileArgPattern('DOCKER_VERSION')
}
]
};
}
},
buildx: {
name: 'Buildx version',
branch: 'deps/buildx-version',
sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/buildx-releases.json',
async resolve() {
const tag = readLatestTag('.github/buildx-releases.json');
return {
titleValue: tag,
targets: [
{
path: 'dev.Dockerfile',
key: 'BUILDX_VERSION',
value: stripLeadingV(tag),
pattern: dockerfileArgPattern('BUILDX_VERSION')
},
{
path: '.github/workflows/test.yml',
key: 'BUILDX_VERSION',
value: tag,
pattern: workflowEnvPattern('BUILDX_VERSION')
}
]
};
}
},
buildkit: {
name: 'BuildKit image',
branch: 'deps/buildkit-image',
sourceUrl: 'https://github.com/moby/buildkit/releases/latest',
async resolve({github}) {
const release = await github.rest.repos.getLatestRelease({
owner: 'moby',
repo: 'buildkit'
});
const image = `moby/buildkit:${release.data.tag_name}`;
return {
titleValue: image,
targets: [
{
path: '.github/workflows/test.yml',
key: 'BUILDKIT_IMAGE',
value: image,
pattern: workflowEnvPattern('BUILDKIT_IMAGE')
}
]
};
}
},
compose: {
name: 'Compose version',
branch: 'deps/compose-version',
sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/compose-releases.json',
async resolve() {
const tag = readLatestTag('.github/compose-releases.json');
return {
titleValue: tag,
targets: [
{
path: 'dev.Dockerfile',
key: 'COMPOSE_VERSION',
value: stripLeadingV(tag),
pattern: dockerfileArgPattern('COMPOSE_VERSION')
}
]
};
}
},
undock: {
name: 'Undock version',
branch: 'deps/undock-version',
sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/undock-releases.json',
async resolve() {
const tag = readLatestTag('.github/undock-releases.json');
return {
titleValue: tag,
targets: [
{
path: 'dev.Dockerfile',
key: 'UNDOCK_VERSION',
value: stripLeadingV(tag),
pattern: dockerfileArgPattern('UNDOCK_VERSION')
}
]
};
}
},
regctl: {
name: 'Regctl version',
branch: 'deps/regctl-version',
sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/regclient-releases.json',
async resolve() {
const tag = readLatestTag('.github/regclient-releases.json');
return {
titleValue: tag,
targets: [
{
path: 'dev.Dockerfile',
key: 'REGCTL_VERSION',
value: tag,
pattern: dockerfileArgPattern('REGCTL_VERSION')
}
]
};
}
},
cosign: {
name: 'Cosign version',
branch: 'deps/cosign-version',
sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/cosign-releases.json',
async resolve() {
const tag = readLatestTag('.github/cosign-releases.json');
return {
titleValue: tag,
targets: [
{
path: 'dev.Dockerfile',
key: 'COSIGN_VERSION',
value: tag,
pattern: dockerfileArgPattern('COSIGN_VERSION')
}
]
};
}
}
};
const config = dependencyConfigs[dep];
if (!config) {
core.setFailed(`Unknown dependency ${dep}`);
return;
}
const resolved = await config.resolve({github});
const currentValues = [];
const changedFiles = [];
for (const target of resolved.targets) {
const absolutePath = path.join(process.env.GITHUB_WORKSPACE, target.path);
const content = fs.readFileSync(absolutePath, 'utf8');
const match = content.match(target.pattern);
if (!match) {
throw new Error(`Missing ${target.key} in ${target.path}`);
}
currentValues.push(match[2]);
if (match[2] === target.value) {
continue;
}
const updatedContent = content.replace(target.pattern, (...args) => {
const groups = args.slice(1, -2);
const prefix = groups[0];
const suffix = groups[2] || '';
return `${prefix}${target.value}${suffix}`;
});
fs.writeFileSync(absolutePath, updatedContent, 'utf8');
changedFiles.push(target.path);
}
core.info(`Resolved ${config.name} from ${config.sourceUrl}`);
if (changedFiles.length === 0) {
core.info(`No workspace changes needed for ${config.name}`);
} else {
core.info(`New ${config.name} ${resolved.titleValue} found`);
}
core.setOutput('branch', config.branch);
core.setOutput('title', `chore(deps): update ${config.name} to ${resolved.titleValue}`);
core.setOutput('before', formatList(unique(currentValues)));
core.setOutput('files', formatList(unique(changedFiles)));
core.setOutput('source-url', config.sourceUrl);
-
name: Create pull request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
base: main
branch: ${{ steps.update.outputs.branch }}
token: ${{ steps.write-app.outputs.token }}
commit-message: ${{ steps.update.outputs.title }}
title: ${{ steps.update.outputs.title }}
signoff: true
sign-commits: true
delete-branch: true
body: |
This updates the pinned value from ${{ steps.update.outputs.before }} in ${{ steps.update.outputs.files }}.
The source of truth for this update is ${{ steps.update.outputs.source-url }}.