Skip to content

Commit 05552d8

Browse files
Resolve the formatter in a temp project, not the runner's shared depot (#29)
`Pkg.add(name="JuliaFormatter", version="2")` ran with no active project, so it resolved into whatever environment the runner happened to have. The compat bounds already sitting in that depot cap the resolve, which makes the installed version a property of the machine rather than of this file: the same commit resolved 2.3.2 on a self-hosted runner and 2.10.1 on a GitHub-hosted one. Formatting differs across 2.x minors, so format-check returned a verdict on the runner, not on the diff. A leftover ITensorFormatter in a shared depot also pinned JuliaSyntax to 0.4 and turned the install into a hard resolve failure, which presents as a flake because it depends on which runner you land on. `Pkg.activate(; temp=true)` before the add is the fix, and the install and the check are now one process so the environment cannot expire between them. The version still floats, deliberately. A pin converts each new release into permanent debt in every calling repo and rots while the ecosystem moves; the answer to a release that reflows files is to adopt it and reformat. Isolation is what this check needed to be reproducible, and it is orthogonal to the version spec. Added an assertion that the loaded version is the one the temp project holds. `using` silently falls back to the depot's default environment when the active project does not declare the package, which has bitten this fleet twice through an env that looked right by its name. The failure message now names the version CI resolved and gives the same floating spec in a temp env, with `overwrite=true` and a retry loop, since `overwrite=false` is a check rather than a fix and one pass does not always converge. Runs the script through `shell: julia --color=yes {0}` rather than `julia -e`, which is how lab-sotashimozono/.github has run this check for months. The failure message has to contain a Julia command with its own quotes, and that does not survive nesting inside `-e '...'`. The two orgs' scripts are now byte-identical, so a fix to one is a copy-paste to the other. Verified locally on both arms rather than by CI round trip: a formatted tree exits 0 with the success line, a misformatted one exits 1 with the message. The YAML and the embedded script both parse. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 23ea763 commit 05552d8

1 file changed

Lines changed: 32 additions & 11 deletions

File tree

‎.github/workflows/format-check.yml‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Reusable JuliaFormatter (v2) check. Call from a repo with:
22
# jobs: { format: { uses: QAtlasHub/.github/.github/workflows/format-check.yml@main } }
3+
#
4+
# `Pkg.activate(; temp=true)` is load-bearing. A bare `Pkg.add` resolves into the runner's
5+
# shared/default environment, where the compat bounds already there cap the result: the same
6+
# commit resolved JuliaFormatter 2.3.2 on a self-hosted runner and 2.10.1 on a GitHub-hosted one,
7+
# and a leftover ITensorFormatter in such a depot once made the install fail outright. Same code,
8+
# different verdict, which presented for months as a "format-check flake".
9+
#
10+
# The version floats, deliberately. When a new 2.x reflows files the answer is to adopt it and
11+
# reformat, not to freeze the old one: a pin here becomes standing debt in every caller and rots
12+
# while the ecosystem moves. Reproducibility comes from the clean env above, not from a pin.
313
name: Format Check (reusable)
414
on:
515
workflow_call:
@@ -13,16 +23,27 @@ jobs:
1323
- uses: julia-actions/setup-julia@v3
1424
with:
1525
version: '1'
16-
- name: Install JuliaFormatter
17-
run: julia -e 'using Pkg; Pkg.add(name="JuliaFormatter", version="2"); using JuliaFormatter; @info "JuliaFormatter $(pkgversion(JuliaFormatter))"'
18-
- name: Check formatting
26+
- name: JuliaFormatter check
27+
shell: julia --color=yes {0}
1928
run: |
20-
julia -e '
21-
using JuliaFormatter
22-
ok = format(".", verbose=true, overwrite=false)
23-
if !ok
24-
println(stderr, "❌ Formatting issues found. Run locally: julia -e \"using JuliaFormatter; format(\\\".\\\")\"")
29+
using Pkg
30+
Pkg.activate(; temp = true) # clean env — no depot compat capping the resolve
31+
Pkg.add(PackageSpec(name = "JuliaFormatter", version = "2"))
32+
using JuliaFormatter
33+
v = pkgversion(JuliaFormatter)
34+
# `using` falls back to the depot's default env when the active project does not declare
35+
# the package, loading a different version and saying nothing, so ask the project itself.
36+
declared = [p.version for (_, p) in Pkg.dependencies() if p.name == "JuliaFormatter"]
37+
if declared != [v]
38+
println(stderr, "❌ JuliaFormatter $v came from outside the temp project, which holds $declared.")
2539
exit(1)
26-
end
27-
println("✅ All files are properly formatted.")
28-
'
40+
end
41+
@info "JuliaFormatter $v"
42+
ok = format("."; verbose = true, overwrite = false)
43+
if !ok
44+
println(stderr, "❌ Not formatted, under JuliaFormatter $v. `overwrite=false` above is the check;")
45+
println(stderr, " locally you want `true`, and one pass does not always converge. Run:")
46+
println(stderr, " julia -e 'using Pkg; Pkg.activate(;temp=true); Pkg.add(PackageSpec(name=\"JuliaFormatter\", version=\"2\")); using JuliaFormatter; for _ in 1:5; format(\".\"; overwrite=true) && break end'")
47+
exit(1)
48+
end
49+
println("✅ All files properly formatted.")

0 commit comments

Comments
 (0)