Skip to content

Commit 8110548

Browse files
fix(version): single source of truth via lib/version.ml + tag-time bake (#297) (#300)
Closes the five-site `0.1.0` drift documented in #297: the compiler binary's `--version`, REPL banner, LSP `initialize` response, and the ONNX `m_producer_version` field were all hand-edited to "0.1.0" and never bumped when v0.1.1 was tagged, so the v0.1.1 binary still reported "0.1.0" (caught during the #282/#295 shim smoke). Approach: option (1) from #297 — generated `Version` module + CI substitution. One small module + one small workflow step; no runtime dependency on `dune-build-info` or any new opam package. Source-of-truth single file --------------------------- lib/version.ml new — `let value = "0.1.1"`, 1 string, baked from the tag at release time Five sites collapsed onto it ---------------------------- bin/main.ml `let version = Affinescript.Version.value` lib/repl.ml `Printf.printf "AffineScript REPL v%s\n" Version.value` lib/lsp_server.ml `("version", `String Version.value)` lib/onnx_codegen.ml `m_producer_version = Version.value` dune-project `(version 0.1.1)` (matches the latest release; opam metadata regenerated) lib/dune `version` added to the modules list Release pipeline bake step -------------------------- `.github/workflows/release.yml`: new step between `Install dependencies` and `Build release` that rewrites BOTH `lib/version.ml` and `dune-project` from `${GITHUB_REF_NAME#v}` (stripping the leading `v`) before `dune build --release`. Subsequent tag bumps need no hand-edit — cut a `vX.Y.Z` tag and the binary self-reports `X.Y.Z`. Cross-checked locally --------------------- $ opam exec -- dune build --release (clean, no warnings introduced) $ _build/default/bin/main.exe --version 0.1.1 $ grep '^version' affinescript.opam # 0.1.1 $ grep '^let value' lib/version.ml # 0.1.1 $ grep '^(version' .build/dune-project # 0.1.1 All four sites coherent. Closes #297. Refs #282 (the closure-PR smoke that surfaced the drift). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2f0f27f commit 8110548

9 files changed

Lines changed: 43 additions & 8 deletions

File tree

.build/dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
(name affinescript)
66

7-
(version 0.1.0)
7+
(version 0.1.1)
88

99
(generate_opam_files true)
1010

.github/workflows/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ jobs:
6969
- name: Install dependencies
7070
run: opam install . --deps-only --yes
7171

72+
- name: Bake release version into source (#297)
73+
# Single source of truth for the compiler version string lives
74+
# in `lib/version.ml`; `dune-project` mirrors it for opam. The
75+
# release workflow rewrites both from the tag so every emitted
76+
# binary self-reports the right number (--version, REPL banner,
77+
# LSP serverInfo, ONNX producer_version).
78+
run: |
79+
v="${GITHUB_REF_NAME#v}"
80+
sed -i "s/^let value = .*/let value = \"$v\"/" lib/version.ml
81+
sed -i "s/^(version .*)/(version $v)/" .build/dune-project
82+
echo "Baked version: $v"
83+
grep '^let value' lib/version.ml
84+
grep '^(version' .build/dune-project
85+
7286
- name: Build release
7387
run: opam exec -- dune build --release
7488

affinescript.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is generated by dune, edit dune-project instead
22
opam-version: "2.0"
3-
version: "0.1.0"
3+
version: "0.1.1"
44
synopsis:
55
"A programming language with affine types, dependent types, row polymorphism, and extensible effects"
66
description:
@@ -23,7 +23,7 @@ doc: "https://github.com/hyperpolymath/affinescript"
2323
bug-reports: "https://github.com/hyperpolymath/affinescript/issues"
2424
depends: [
2525
"ocaml" {>= "4.14"}
26-
"dune" {>= "3.14" & >= "3.14"}
26+
"dune" {>= "3.14"}
2727
"menhir" {>= "20231231"}
2828
"sedlex" {>= "3.2"}
2929
"ppx_deriving" {>= "5.2"}

bin/main.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
let () = Fmt_tty.setup_std_outputs ()
1313

14-
(** Version string *)
15-
let version = "0.1.0"
14+
(** Version string (single source of truth — see lib/version.ml; baked
15+
from the release tag by .github/workflows/release.yml). *)
16+
let version = Affinescript.Version.value
1617

1718
(** Read file contents *)
1819
let read_file path =

lib/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
types
7474
unify
7575
value
76+
version
7677
wasm
7778
wasm_encode
7879
wasm_gc

lib/lsp_server.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ let handle_initialize (id : Yojson.Basic.t) (_params : Yojson.Basic.t) : unit =
313313
]);
314314
("serverInfo", `Assoc [
315315
("name", `String "affinescript");
316-
("version", `String "0.1.0");
316+
("version", `String Version.value);
317317
]);
318318
]
319319
))

lib/onnx_codegen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ let generate (program : program) (_symbols : Symbol.t) : string =
230230
let model = {
231231
Onnx_proto.m_ir_version = 7; (* ONNX 1.10+ *)
232232
m_producer_name = "affinescript";
233-
m_producer_version = "0.1.0";
233+
m_producer_version = Version.value;
234234
m_opset_import = [{ op_domain = ""; op_version = 13 }];
235235
m_graph = graph;
236236
} in

lib/repl.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ let print_prompt () =
297297

298298
(** Print the REPL banner *)
299299
let print_banner () =
300-
print_endline "AffineScript REPL v0.1.0";
300+
Printf.printf "AffineScript REPL v%s\n" Version.value;
301301
print_endline "Type :help for help, :quit to exit";
302302
print_endline ""
303303

lib/version.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(* SPDX-License-Identifier: MIT OR AGPL-3.0-or-later *)
2+
(* Single source of truth for the compiler version string.
3+
*
4+
* Replaces the five hardcoded "0.1.0" sites that used to drift behind
5+
* the release tag (issue #297):
6+
*
7+
* bin/main.ml — `affinescript --version`
8+
* lib/repl.ml — REPL banner
9+
* lib/lsp_server.ml — LSP `initialize` response
10+
* lib/onnx_codegen.ml — ONNX `producer_version` field on emitted models
11+
*
12+
* The value below is baked at *build* time by the release workflow:
13+
* `.github/workflows/release.yml` sed-substitutes this line (and the
14+
* `(version …)` field in `dune-project`) to match `${GITHUB_REF_NAME}`
15+
* before running `dune build --release`. When building from a non-
16+
* release commit, this reflects whatever was last committed to main,
17+
* matching `dune-project`'s declared version. *)
18+
19+
let value = "0.1.1"

0 commit comments

Comments
 (0)