Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ name: Format Check
# Reusable JuliaFormatter check. The pool follows the CALLER's visibility unless `runner` is
# passed — private → rosina, public → ubuntu-latest. Canonical note: `autoregister.yml`.
#
# TWO things here are load-bearing — do not "simplify" them away:
# `Pkg.activate(; temp=true)` is load-bearing — do not "simplify" it away. Installing into the
# runner's shared/default environment lets that depot's existing compat bounds cap the resolve: on
# rosina a floating spec silently resolved to JuliaFormatter 2.3.2 while a laptop resolved 2.10.1,
# and a leftover ITensorFormatter there once made the install fail outright. Same code, different
# verdict, which is the long-standing "format-check flake". It was never a flake, it was the
# shared env, and that is the half worth defending.
#
# 1. `Pkg.activate(; temp=true)` — a CLEAN env. Installing into the runner's shared/default
# environment lets that depot's existing compat bounds cap the resolve: on rosina a floating
# `version="2"` silently resolved to **JuliaFormatter 2.3.2**, while a laptop resolved 2.10.1.
# Same code, different verdict → the long-standing "format-check flake". It was never a flake,
# it was version drift.
# 2. `JF_VERSION` is an EXACT pin, not a range. CI and your laptop must run the *same* formatter
# or the check is not reproducible. Bump it here, once, and reformat the fleet with that
# version — never let it float.
# The version floats, deliberately. When a new 2.x reflows files the answer is to adopt it and
# reformat, not to freeze the old one: a pin here becomes standing debt in every caller and rots
# while the ecosystem moves. Reproducibility comes from the clean env above, not from the pin.
#
# Format locally with exactly this version:
# Format locally with the same floating spec, in a temp env, so you resolve what CI just did:
# julia -e 'using Pkg; Pkg.activate(;temp=true); Pkg.add(PackageSpec(name="JuliaFormatter",
# version="2.10.1")); using JuliaFormatter; format(".")'
# version="2")); using JuliaFormatter; format(".")'
on:
workflow_call:
inputs:
Expand All @@ -26,9 +26,6 @@ on:
type: string
default: ''

env:
JF_VERSION: '2.10.1'

jobs:
format-check:
runs-on: ${{ inputs.runner != '' && fromJSON(inputs.runner) || (github.event.repository.private && fromJSON('["self-hosted","rosina"]') || 'ubuntu-latest') }}
Expand All @@ -37,23 +34,27 @@ jobs:
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- name: JuliaFormatter ${{ env.JF_VERSION }} check
- name: JuliaFormatter check
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.activate(; temp = true) # clean env — no depot compat capping the resolve
Pkg.add(PackageSpec(name = "JuliaFormatter", version = ENV["JF_VERSION"]))
Pkg.add(PackageSpec(name = "JuliaFormatter", version = "2"))
using JuliaFormatter
v = pkgversion(JuliaFormatter)
@info "JuliaFormatter $v (pinned $(ENV["JF_VERSION"]))"
if string(v) != ENV["JF_VERSION"]
println(stderr, "❌ resolved JuliaFormatter $v, expected $(ENV["JF_VERSION"]) — the check would not be reproducible.")
# `using` falls back to the depot's default env when the active project does not declare
# the package, loading a different version and saying nothing, so ask the project itself.
declared = [p.version for (_, p) in Pkg.dependencies() if p.name == "JuliaFormatter"]
if declared != [v]
println(stderr, "❌ JuliaFormatter $v came from outside the temp project, which holds $declared.")
exit(1)
end
@info "JuliaFormatter $v"
ok = format("."; verbose = true, overwrite = false)
if !ok
println(stderr, "❌ Not formatted. Run locally with the SAME version:")
println(stderr, " julia -e 'using Pkg; Pkg.activate(;temp=true); Pkg.add(PackageSpec(name=\"JuliaFormatter\", version=\"$(ENV["JF_VERSION"])\")); using JuliaFormatter; format(\".\")'")
println(stderr, "❌ Not formatted, under JuliaFormatter $v. `overwrite=false` above is the check;")
println(stderr, " locally you want `true`, and one pass does not always converge. Run:")
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'")
exit(1)
end
println("✅ All files properly formatted.")