Repository navigation
Expand file tree
/
Copy pathlock-check.sh
More file actions
executable file
·56 lines (50 loc) · 2.46 KB
/
Copy pathlock-check.sh
File metadata and controls
executable file
·56 lines (50 loc) · 2.46 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
#!/usr/bin/env bash
# Check that mise.lock is up to date with mise.toml.
#
# Shared across iglootools projects. The canonical copy is scripts/lock-check.sh in
# iglootools/common, alongside the guideline that explains it; project copies are
# verbatim, so fix it there and re-copy rather than editing one in place.
#
# Unlike `uv lock --check`, mise has no read-only freshness check, so this regenerates the
# lockfile and compares. Doing that naively is a trap; each guard below was earned by hitting
# the corresponding failure:
#
# - Regenerates into a scratch copy, never in place. `mise lock` always writes, and undoing
# that with `git checkout mise.lock` discards the regenerated lockfile that the error
# message tells you to commit.
#
# - Reads its inputs from the git index, not the working tree. mise rewrites mise.lock on
# its own: with [settings] lockfile = true, any tool-resolving command updates the version
# stanza and drops the per-platform checksums it can no longer vouch for — which is
# precisely the state that makes `mise install --locked` fail on a fresh runner. The
# working copy is therefore not a stable reference, so "up to date" can only mean "matches
# what is staged". Reading the index also makes this immune to CI's
# `mise use python@<matrix>`, which rewrites the working copy of mise.toml.
#
# - Unsets MISE_PYTHON_VERSION, which `mise lock` honours — otherwise an env-selected matrix
# interpreter would be locked in place of the committed pin.
#
# - Uses `set -euo pipefail`. Without it, a failing `mise lock` leaves the copied lockfile
# untouched, the diff finds no difference, and the check *passes* — the guard defeated by
# the very situation it exists to catch.
#
# Usage:
# mise run lock-check # the usual entry point
# scripts/lock-check.sh # equivalent, runs from any directory in the repo
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
git show :mise.toml > "$tmp/mise.toml"
git show :mise.lock > "$tmp/staged.lock"
cp "$tmp/staged.lock" "$tmp/mise.lock"
# MISE_TRUSTED_CONFIG_PATHS rather than `mise trust`, so the scratch config is not added to
# the user's persistent trust store on every run.
(
cd "$tmp"
MISE_TRUSTED_CONFIG_PATHS="$tmp" env -u MISE_PYTHON_VERSION mise lock
)
if ! diff -u "$tmp/staged.lock" "$tmp/mise.lock" >&2; then
echo "mise.lock is out of date. Run 'mise lock' and commit the result." >&2
exit 1
fi