Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
534 lines (478 loc) · 17.8 KB
/
Copy pathaction.yml
File metadata and controls
534 lines (478 loc) · 17.8 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
name: "Codependence"
description: "Enforce dependency version policy in CI and optionally update mismatched versions"
author: "Jeff Wainwright"
branding:
icon: "package"
color: "blue"
inputs:
codependencies:
description: 'Space-separated list of dependencies to check (e.g., "lodash react")'
required: false
config:
description: "Path to config file"
required: false
files:
description: "File glob patterns (space-separated)"
required: false
targets:
description: "Configured manager targets to run (space-separated)"
required: false
version:
description: "Exact tool version override; Node package manager versions can be inferred from package.json when omitted"
required: false
lockfile:
description: "Require lockfiles for selected targets (true/false)"
required: false
default: "true"
pull-request:
description: "Create or update a pull request (true/false)"
required: false
default: "false"
token:
description: "Fine-grained PAT used to create pull requests"
required: false
dockerhub-username:
description: "Docker Hub username for private image metadata"
required: false
dockerhub-token:
description: "Docker Hub read-only PAT or organization access token"
required: false
ghcr-username:
description: "GitHub username for private GHCR image metadata"
required: false
ghcr-token:
description: "GitHub token with read access to GHCR packages"
required: false
post-update-command:
description: "Trusted command that regenerates lockfiles after updates"
required: false
draft:
description: "Create a draft pull request (true/false)"
required: false
default: "false"
branch-prefix:
description: "Stable pull request branch prefix"
required: false
default: "update-dependencies"
update:
description: "Update dependencies based on check (true/false)"
required: false
default: "false"
dryRun:
description: "Preview changes without modifying files (true/false)"
required: false
default: "false"
permissive:
description: "Update all dependencies to latest except those in codependencies (true/false)"
required: false
default: "false"
mode:
description: "Policy mode: verbose checks listed packages; precise updates all except listed packages"
required: false
level:
description: "Allowed update level: patch, minor, or major"
required: false
language:
description: "Target language: nodejs (stable), or experimental go, python, rust, circleci, docker, github-actions, helm, kubernetes, kustomize, terraform"
required: false
fail-on-outdated:
description: "Fail the action if dependencies are outdated (true/false)"
required: false
default: "true"
rootDir:
description: "Root directory to start search"
required: false
ignore:
description: "Ignore glob patterns (space-separated)"
required: false
silent:
description: "Enable silent logging (true/false)"
required: false
default: "false"
debug:
description: "Enable debug logging (true/false)"
required: false
default: "false"
yarnConfig:
description: "Enable yarn config support (true/false)"
required: false
default: "false"
noCache:
description: "Disable version cache for fresh registry results (true/false)"
required: false
default: "false"
format:
description: "Output format: json, markdown, or table"
required: false
outputFile:
description: "Write formatted output to this file path"
required: false
outputs:
outdated:
description: "Whether any dependencies were outdated (true/false)"
value: ${{ steps.codependence.outputs.outdated }}
pull-request-url:
description: "Created or updated pull request URL"
value: ${{ steps.create-pull-request.outputs.pull-request-url }}
runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "26"
- name: Prepare targets
id: targets
shell: bash
env:
INPUT_TARGETS: ${{ inputs.targets }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_ROOT_DIR: ${{ inputs.rootDir }}
run: |
set -eo pipefail
action_path="${GITHUB_ACTION_PATH:-$PWD}"
package_manager_version() {
local manager="$1"
node "$action_path/scripts/ci/tool-versions.js" package-manager-version "$manager" "$INPUT_ROOT_DIR"
}
for manager in bun conda go npm pip pipenv pnpm poetry rust uv yarn; do
echo "$manager-version=" >> "$GITHUB_OUTPUT"
done
target_input="${INPUT_TARGETS//$'\n'/ }"
target_input="${target_input//,/ }"
read -r -a requested <<< "$target_input"
if [ "${#requested[@]}" -eq 0 ]; then
echo "list=" >> "$GITHUB_OUTPUT"
echo "branch-suffix=" >> "$GITHUB_OUTPUT"
exit 0
fi
targets=()
versioned=()
for target in "${requested[@]}"; do
if [[ " ${targets[*]} " == *" $target "* ]]; then
continue
fi
case "$target" in
bun|npm|pnpm|yarn|go|rust|uv|pip|pipenv|poetry|conda)
versioned+=("$target")
;;
circleci|docker|github-actions|helm|kubernetes|kustomize|terraform)
;;
*)
echo "::error::Unsupported Action target: $target"
exit 2
;;
esac
targets+=("$target")
done
version_for() {
local manager="$1"
if [ "${#versioned[@]}" -eq 1 ] && [ -n "$INPUT_VERSION" ] && [[ "$INPUT_VERSION" != *"="* ]]; then
printf '%s' "$INPUT_VERSION"
return
fi
local assignments="${INPUT_VERSION//,/ }"
for assignment in $assignments; do
if [ "${assignment%%=*}" = "$manager" ]; then
printf '%s' "${assignment#*=}"
return
fi
done
if [[ "$manager" == bun || "$manager" == npm || "$manager" == pnpm || "$manager" == yarn ]]; then
package_manager_version "$manager"
fi
}
if [ "${#versioned[@]}" -eq 0 ] && [ -n "$INPUT_VERSION" ]; then
echo "::error::Infrastructure targets do not accept version"
exit 2
fi
for manager in "${versioned[@]}"; do
tool_version="$(version_for "$manager")"
if [[ ! "$tool_version" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)?$ ]]; then
echo "::error::$manager requires an exact version"
exit 2
fi
if [ "$manager" = "rust" ]; then
rust_toolchain="${tool_version#v}"
if [[ ! "$rust_toolchain" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::rust requires an exact stable version"
exit 2
fi
fi
echo "$manager-version=$tool_version" >> "$GITHUB_OUTPUT"
done
target_list="${targets[*]}"
branch_suffix="$(printf '%s\n' "${targets[@]}" | sort | paste -sd- -)"
echo "list=$target_list" >> "$GITHUB_OUTPUT"
echo "branch-suffix=$branch_suffix" >> "$GITHUB_OUTPUT"
- name: Validate pull request mode
if: inputs.pull-request == 'true'
shell: bash
env:
INPUT_POST_UPDATE_COMMAND: ${{ inputs.post-update-command }}
INPUT_TARGETS: ${{ steps.targets.outputs.list }}
INPUT_TOKEN: ${{ inputs.token }}
run: |
set -euo pipefail
if [ "$GITHUB_EVENT_NAME" != "schedule" ] && [ "$GITHUB_EVENT_NAME" != "workflow_dispatch" ]; then
echo "::error::Pull request mode only supports schedule and workflow_dispatch events"
exit 2
fi
if [ -z "$INPUT_TOKEN" ]; then
echo "::error::Pull request mode requires a fine-grained PAT"
exit 2
fi
if [ -z "$INPUT_TARGETS" ]; then
echo "::error::Pull request mode requires targets"
exit 2
fi
if [ -z "$INPUT_POST_UPDATE_COMMAND" ]; then
echo "::error::Pull request mode requires post-update-command"
exit 2
fi
if [ -n "$(git status --porcelain)" ]; then
echo "::error::Pull request mode requires a clean checkout"
exit 2
fi
- name: Setup Bun
if: steps.targets.outputs.bun-version != ''
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: ${{ steps.targets.outputs.bun-version }}
- name: Setup Go
if: steps.targets.outputs.go-version != ''
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.4.0
with:
go-version: ${{ steps.targets.outputs.go-version }}
cache: false
- name: Setup Rust
if: steps.targets.outputs.rust-version != ''
shell: bash
env:
TOOL_VERSION: ${{ steps.targets.outputs.rust-version }}
run: |
if ! command -v rustup >/dev/null 2>&1; then
echo "::error::Rust targets require rustup on the runner"
exit 2
fi
rust_toolchain="${TOOL_VERSION#v}"
rustup toolchain install "$rust_toolchain" --profile minimal
rustup default "$rust_toolchain"
echo "RUSTUP_TOOLCHAIN=$rust_toolchain" >> "$GITHUB_ENV"
- name: Setup uv
if: steps.targets.outputs.uv-version != ''
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
version: ${{ steps.targets.outputs.uv-version }}
- name: Setup Conda
if: steps.targets.outputs.conda-version != ''
uses: conda-incubator/setup-miniconda@be893c923ea9cf1cf7cd510fbdde27c7e18cbdcb # v4
with:
conda-version: ${{ steps.targets.outputs.conda-version }}
miniforge-version: latest
channels: conda-forge
conda-remove-defaults: true
activate-environment: ""
auto-activate: false
run-init: false
- name: Setup Python package managers
if: steps.targets.outputs.pip-version != '' || steps.targets.outputs.pipenv-version != '' || steps.targets.outputs.poetry-version != ''
shell: bash
env:
PIP_VERSION: ${{ steps.targets.outputs.pip-version }}
PIPENV_VERSION: ${{ steps.targets.outputs.pipenv-version }}
POETRY_VERSION: ${{ steps.targets.outputs.poetry-version }}
run: |
set -euo pipefail
install_python_package_managers() {
local environment_path="$RUNNER_TEMP/codependence-python"
local packages=()
local executable="bin/python"
if [ "${RUNNER_OS:-}" = "Windows" ]; then
executable="Scripts/python.exe"
fi
python3 -m venv "$environment_path"
if [ -n "$PIP_VERSION" ]; then
packages+=("pip==$PIP_VERSION")
fi
if [ -n "$PIPENV_VERSION" ]; then
packages+=("pipenv==$PIPENV_VERSION")
fi
if [ -n "$POETRY_VERSION" ]; then
packages+=("poetry==$POETRY_VERSION")
fi
"$environment_path/$executable" -m pip install "${packages[@]}"
echo "$environment_path/${executable%/*}" >>"$GITHUB_PATH"
}
install_python_package_managers
- name: Setup npm
if: steps.targets.outputs.npm-version != ''
shell: bash
env:
TOOL_VERSION: ${{ steps.targets.outputs.npm-version }}
run: npm install --global "npm@$TOOL_VERSION"
- name: Setup pnpm
if: steps.targets.outputs.pnpm-version != ''
shell: bash
env:
TOOL_VERSION: ${{ steps.targets.outputs.pnpm-version }}
run: npm install --global "pnpm@$TOOL_VERSION"
- name: Setup Yarn
if: steps.targets.outputs.yarn-version != ''
shell: bash
env:
TOOL_VERSION: ${{ steps.targets.outputs.yarn-version }}
run: npm install --global "yarn@$TOOL_VERSION"
- name: Install Codependence
shell: bash
run: |
set -euo pipefail
ACTION_PATH="${GITHUB_ACTION_PATH:-$PWD}"
if [ -f "$ACTION_PATH/dist/cli.js" ]; then
echo "Using local Codependence build"
chmod +x "$ACTION_PATH/dist/cli.js"
npm install -g "$ACTION_PATH" --ignore-scripts
else
VERSION=$(node -p "require(process.argv[1]).version" "$ACTION_PATH/package.json" 2>/dev/null || true)
if [ -n "$VERSION" ]; then
npm install -g "codependence@$VERSION"
else
npm install -g codependence
fi
fi
- name: Run Codependence
id: codependence
shell: bash
env:
DOCKERHUB_TOKEN: ${{ inputs.dockerhub-token }}
DOCKERHUB_USERNAME: ${{ inputs.dockerhub-username }}
GHCR_TOKEN: ${{ inputs.ghcr-token }}
GHCR_USERNAME: ${{ inputs.ghcr-username }}
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ github.token }}
INPUT_CODEDEPENDENCIES: ${{ inputs.codependencies }}
INPUT_CONFIG: ${{ inputs.config }}
INPUT_DRY_RUN: ${{ inputs.dryRun }}
INPUT_FILES: ${{ inputs.files }}
INPUT_FORMAT: ${{ inputs.format }}
INPUT_LOCKFILE: ${{ inputs.lockfile }}
INPUT_LANGUAGE: ${{ inputs.language }}
INPUT_LEVEL: ${{ inputs.level }}
INPUT_MODE: ${{ inputs.mode }}
INPUT_NO_CACHE: ${{ inputs.noCache }}
INPUT_OUTPUT_FILE: ${{ inputs.outputFile }}
INPUT_UPDATE: ${{ inputs.update }}
INPUT_PERMISSIVE: ${{ inputs.permissive }}
INPUT_FAIL_ON_OUTDATED: ${{ inputs.fail-on-outdated }}
INPUT_ROOT_DIR: ${{ inputs.rootDir }}
INPUT_IGNORE: ${{ inputs.ignore }}
INPUT_SILENT: ${{ inputs.silent }}
INPUT_TARGETS: ${{ steps.targets.outputs.list }}
INPUT_DEBUG: ${{ inputs.debug }}
INPUT_PULL_REQUEST: ${{ inputs.pull-request }}
INPUT_YARN_CONFIG: ${{ inputs.yarnConfig }}
run: |
set -u
CMD=(codependence)
append_list_flag() {
local flag="$1"
local values="$2"
[ -n "$values" ] || return 0
local -a arguments=()
read -r -a arguments <<< "${values//$'\n'/ }"
CMD+=("$flag" "${arguments[@]}")
}
append_value_flag() {
local flag="$1"
local value="$2"
[ -n "$value" ] || return 0
CMD+=("$flag" "$value")
}
append_bool_flag() {
local flag="$1"
local value="$2"
[ "$value" = "true" ] || return 0
CMD+=("$flag")
}
append_list_flag --codependencies "$INPUT_CODEDEPENDENCIES"
append_value_flag --config "$INPUT_CONFIG"
append_list_flag --files "$INPUT_FILES"
append_list_flag --target "$INPUT_TARGETS"
append_bool_flag --update "$INPUT_UPDATE"
append_bool_flag --dryRun "$INPUT_DRY_RUN"
append_bool_flag --permissive "$INPUT_PERMISSIVE"
append_bool_flag --silent "$INPUT_SILENT"
append_bool_flag --debug "$INPUT_DEBUG"
append_bool_flag --yarnConfig "$INPUT_YARN_CONFIG"
append_bool_flag --noCache "$INPUT_NO_CACHE"
if [ -n "$INPUT_TARGETS" ]; then
CMD+=(--lockfile "$INPUT_LOCKFILE")
fi
if [ "$INPUT_PULL_REQUEST" = "true" ] && [ "$INPUT_UPDATE" != "true" ]; then
CMD+=(--update)
fi
append_value_flag --mode "$INPUT_MODE"
append_value_flag --level "$INPUT_LEVEL"
append_value_flag --language "$INPUT_LANGUAGE"
append_value_flag --format "$INPUT_FORMAT"
append_value_flag --outputFile "$INPUT_OUTPUT_FILE"
append_value_flag --rootDir "$INPUT_ROOT_DIR"
append_list_flag --ignore "$INPUT_IGNORE"
echo "Running Codependence"
set +e
"${CMD[@]}"
EXIT_CODE=$?
set -e
if [ "$EXIT_CODE" -eq 1 ]; then
echo "outdated=true" >> "$GITHUB_OUTPUT"
if [ "$INPUT_FAIL_ON_OUTDATED" = "true" ]; then
echo "::error::Dependencies are outdated. Run 'codependence --update' to fix."
exit 1
fi
elif [ "$EXIT_CODE" -ne 0 ]; then
echo "outdated=false" >> "$GITHUB_OUTPUT"
echo "::error::Codependence failed with exit code $EXIT_CODE."
exit "$EXIT_CODE"
else
echo "outdated=false" >> "$GITHUB_OUTPUT"
fi
exit 0
- name: Regenerate lockfiles
if: inputs.pull-request == 'true'
shell: bash
env:
POST_UPDATE_COMMAND: ${{ inputs.post-update-command }}
run: |
bash -eo pipefail -c "$POST_UPDATE_COMMAND"
- name: Prepare pull request
id: pull-request
if: inputs.pull-request == 'true'
shell: bash
env:
BRANCH_SUFFIX: ${{ steps.targets.outputs.branch-suffix }}
BRANCH_PREFIX: ${{ inputs.branch-prefix }}
TARGETS: ${{ steps.targets.outputs.list }}
run: |
set -euo pipefail
if [[ ! "$BRANCH_PREFIX" =~ ^[a-z0-9]([a-z0-9._/-]*[a-z0-9])?$ ]]; then
echo "::error::branch-prefix must be a lowercase branch-safe name"
exit 2
fi
branch="$BRANCH_PREFIX/$BRANCH_SUFFIX"
title="chore: update $TARGETS dependencies"
body="Updates the selected Codependence targets: $TARGETS."
echo "branch=$branch" >> "$GITHUB_OUTPUT"
echo "title=$title" >> "$GITHUB_OUTPUT"
echo "body=$body" >> "$GITHUB_OUTPUT"
- name: Create pull request
id: create-pull-request
if: inputs.pull-request == 'true'
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1
with:
token: ${{ inputs.token }}
branch: ${{ steps.pull-request.outputs.branch }}
commit-message: ${{ steps.pull-request.outputs.title }}
title: ${{ steps.pull-request.outputs.title }}
body: ${{ steps.pull-request.outputs.body }}
draft: ${{ inputs.draft }}
delete-branch: true