Skip to content

Commit 122616e

Browse files
committed
Add MODULE.bazel.lock update to pre-commit
bzlmod typically updates MODULE.bazel.lock on an as-needed basis, as you refer to targets that trigger the need for a dependency listed in the MODULE.bazel. If you make a dependency change, but only run a subset of tests, you may end up with a lock file that is different than the one that would result from a full presubmit. Leading to a CI failure, since there's a non-empty git diff now. This change adds this check to pre-commit, so you can easily get lockfiles up to date locally, and so that in cases where they are out of date, CI will fail faster. Change-Id: I72ccf4c520377c8275961dee5cf385936a6a6964
1 parent 386a77d commit 122616e

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

.pre-commit-config.yaml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
exclude: third_party/
22

3-
# The hooks here are using tools that we have pre-installed using flake.nix.
3+
# The hooks here are using tools that we have pre-installed using flake.nix, or
4+
# they are scripts in our scripts/ directory.
45
repos:
56
- repo: local
67
hooks:
@@ -9,51 +10,67 @@ repos:
910
entry: rustfmt
1011
language: system
1112
types: [rust]
13+
1214
- id: buildifier
1315
name: buildifier (Bazel BUILD and .bzl files)
1416
entry: buildifier
1517
language: system
1618
types: [bazel]
19+
20+
- id: bzllock
21+
name: Make sure MODULE.bazel.lock files are fully up to date
22+
entry: ./scripts/bazel_mod_deps
23+
language: system
24+
files: MODULE.bazel$
25+
1726
- id: clang-format
1827
name: clang-format (C/C++, Java, Proto)
1928
entry: clang-format -i
2029
language: system
2130
types_or: [c, c++, proto, java]
31+
2232
- id: prettier
2333
name: prettier (YAML, HTML, JS, TS, CSS, SCSS)
2434
entry: prettier --write
2535
language: system
2636
types_or: [yaml, html, javascript, ts, css, scss]
37+
2738
- id: hadolint
2839
name: hadolint (Dockerfiles)
2940
entry: hadolint
3041
language: system
3142
types: [dockerfile]
43+
3244
- id: ktfmt
3345
name: ktfmt (Kotlin)
3446
entry: ktfmt -F --google-style
3547
language: system
3648
types: [kotlin]
49+
3750
- id: markdownlint (Markdown files)
3851
name: apply markdownlint for markdown files
3952
entry: markdownlint --fix
4053
types: [markdown]
4154
language: system
42-
- id: shellcheck (Shell Script Files)
43-
name: apply shellcheck for shell scripts
55+
56+
- id: shellcheck
57+
name: shellcheck (shell script files)
4458
entry: shellcheck --external-sources --exclude=SC2155
4559
language: system
4660
types: [shell]
61+
4762
- id: nix
4863
name: nixfmt (Nix)
4964
entry: nix fmt
5065
language: system
5166
types: [nix]
67+
5268
- id: terraform fmt
5369
name: terraform fmt
5470
entry: terraform fmt --write=true
5571
language: system
5672
types: [terraform]
73+
5774
- id: badtodo
5875
name: Bad TODOs
5976
language: system
@@ -77,11 +94,13 @@ repos:
7794
markdown,
7895
shell,
7996
]
97+
8098
- id: bazellic
8199
name: Add notice license to all bazel packages
82100
language: system
83101
entry: ./scripts/add_bazel_license
84102
files: BUILD
103+
85104
- id: sourcelic
86105
name: Add Apache License to source files
87106
language: system
@@ -95,3 +114,4 @@ repos:
95114
name: id
96115
language: system
97116
entry: echo
117+
files: MODULE.bazel$

scripts/bazel_mod_deps

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
set -o pipefail
5+
6+
# Run bazel mod deps on each provided MODULE.bazel file to ensure that the lock file is fully up to date.
7+
for file in "$@"; do
8+
pushd "$(dirname "$file")"
9+
bazel mod deps
10+
popd
11+
done

0 commit comments

Comments
 (0)