|
| 1 | +#= |
| 2 | +Auto-registration driver. Run from the registry repository root: |
| 3 | +
|
| 4 | + julia .ci/auto_register.jl |
| 5 | +
|
| 6 | +For each package listed in .ci/packages.toml: |
| 7 | + 1. Shallow-clone the configured branch into a temp dir. |
| 8 | + 2. Read the working copy's Project.toml version. |
| 9 | + 3. Compare against the highest version already in <L>/<name>/Versions.toml. |
| 10 | + 4. If the working copy is newer, call LocalRegistry.register(...; push=false) |
| 11 | + so a single commit lands in the registry working tree. The workflow does |
| 12 | + the actual git push. |
| 13 | +
|
| 14 | +Packages whose cloned Project.toml still contains a [sources] block are |
| 15 | +skipped with a warning. This script is the wrong tool for those. |
| 16 | +=# |
| 17 | + |
| 18 | +using Pkg |
| 19 | +using TOML |
| 20 | + |
| 21 | +const REGISTRY_PATH = pwd() |
| 22 | +const CONFIG_PATH = joinpath(REGISTRY_PATH, ".ci", "packages.toml") |
| 23 | + |
| 24 | +Pkg.add("LocalRegistry") |
| 25 | +using LocalRegistry |
| 26 | + |
| 27 | +function latest_registered(regdir::AbstractString, name::AbstractString) |
| 28 | + L = uppercase(string(name[1])) |
| 29 | + vfile = joinpath(regdir, L, name, "Versions.toml") |
| 30 | + isfile(vfile) || return nothing |
| 31 | + parsed = TOML.parsefile(vfile) |
| 32 | + isempty(parsed) && return nothing |
| 33 | + return maximum(VersionNumber.(keys(parsed))) |
| 34 | +end |
| 35 | + |
| 36 | +function clone_at(repo::AbstractString, branch::AbstractString) |
| 37 | + dir = mktempdir(; prefix = "regsync_") |
| 38 | + run(`git clone --depth 1 --branch $branch $repo $dir`) |
| 39 | + return dir |
| 40 | +end |
| 41 | + |
| 42 | +function process(pkg) |
| 43 | + name = pkg["name"] |
| 44 | + repo = pkg["repo"] |
| 45 | + branch = get(pkg, "branch", "master") |
| 46 | + println("[check] $name @ $branch ($repo)") |
| 47 | + |
| 48 | + clonedir = clone_at(repo, branch) |
| 49 | + proj = TOML.parsefile(joinpath(clonedir, "Project.toml")) |
| 50 | + |
| 51 | + if haskey(proj, "sources") |
| 52 | + @warn "Skipping $name: cloned Project.toml has a [sources] block" |
| 53 | + return |
| 54 | + end |
| 55 | + |
| 56 | + wcver = VersionNumber(proj["version"]) |
| 57 | + regver = latest_registered(REGISTRY_PATH, name) |
| 58 | + |
| 59 | + if regver !== nothing && wcver <= regver |
| 60 | + println("[skip] $name v$wcver already covered (registered: v$regver)") |
| 61 | + return |
| 62 | + end |
| 63 | + |
| 64 | + println("[register] $name v$wcver (previous: $(regver === nothing ? "none" : "v$regver"))") |
| 65 | + register(clonedir; registry = REGISTRY_PATH, push = false) |
| 66 | +end |
| 67 | + |
| 68 | +function main() |
| 69 | + cfg = TOML.parsefile(CONFIG_PATH) |
| 70 | + packages = get(cfg, "package", Any[]) |
| 71 | + isempty(packages) && (println("No packages configured."); return) |
| 72 | + for pkg in packages |
| 73 | + try |
| 74 | + process(pkg) |
| 75 | + catch err |
| 76 | + @error "Failed to process $(get(pkg, "name", "?"))" exception = (err, catch_backtrace()) |
| 77 | + end |
| 78 | + end |
| 79 | +end |
| 80 | + |
| 81 | +main() |
0 commit comments