Skip to content

Commit 5a4e867

Browse files
committed
Stamp binary release versions from tags
Binary releases require coordinated edits to three independent Cargo manifests and their lockfiles. Keep those binary packages at 0.0.0 in development and use a semantic-version tag as the release input, without changing independently versioned source crates. Add scripts/set_release_version.py to set or check the flare-cli, flare-winui-bridge, and flare-launcher manifest and lockfile versions. The release workflow validates the 0.0.0 development state and invokes the script in each Linux and Windows build checkout. The release guide documents tag-driven publication. Publishing a binary release now requires only the vMAJOR.MINOR.PATCH tag rather than a separate synchronized version commit. Existing draft publication and --locked build behavior remain in place, and Helios and Heliopause retain their independent package versions. Validated 0.0.0 to 0.2.1 to 0.0.0 transitions and Cargo metadata --locked --no-deps for all three manifests in both states. Parsed the workflow YAML and ran git diff --check. Full GitHub Actions builds were not run. Ruff was unavailable in .venv, so its checks were not run. Design-Signed-Off-By: Kimi (DeepSeek-V4.1-Flash); design-review=ed22
1 parent 778efad commit 5a4e867

9 files changed

Lines changed: 150 additions & 26 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,12 @@ jobs:
2626
- name: Resolve the release version
2727
id: version
2828
run: |
29-
crate_version() {
30-
cargo metadata --no-deps --format-version 1 --manifest-path "$1" |
31-
jq -er --arg name "$2" '.packages[] | select(.name == $name) | .version'
32-
}
3329
if [[ "$GITHUB_EVENT_NAME" == push ]]; then
3430
version=${GITHUB_REF_NAME#v}
3531
else
36-
version=$(crate_version flare-cli/Cargo.toml flare-cli)
32+
version=0.0.0
3733
fi
38-
for crate in flare-cli/Cargo.toml:flare-cli flare-winui/bridge/Cargo.toml:flare-winui-bridge \
39-
flare-winui/launcher/Cargo.toml:flare-launcher; do
40-
found=$(crate_version "${crate%%:*}" "${crate##*:}")
41-
if [[ "$found" != "$version" ]]; then
42-
echo "::error::${crate%%:*} has version $found; the release version is $version."
43-
exit 1
44-
fi
45-
done
34+
python3 scripts/set_release_version.py --check 0.0.0
4635
echo "version=$version" >> "$GITHUB_OUTPUT"
4736
4837
linux:
@@ -71,6 +60,8 @@ jobs:
7160
sudo apt-get install -y --no-install-recommends build-essential cmake nasm pkg-config protobuf-compiler ${{ matrix.build-packages }}
7261
rustup toolchain install "$RUST_TOOLCHAIN" --profile minimal --component rust-docs
7362
rustup default "$RUST_TOOLCHAIN"
63+
- name: Set the release version
64+
run: python3 scripts/set_release_version.py "$VERSION"
7465
- name: Build the CLI
7566
run: cargo build --locked --release --manifest-path flare-cli/Cargo.toml --bin flare
7667
- name: Package the CLI and license notices
@@ -131,6 +122,7 @@ jobs:
131122
run:
132123
shell: powershell
133124
env:
125+
VERSION: ${{ needs.version.outputs.version }}
134126
ARCHIVE: flare-windows-${{ matrix.arch }}.zip
135127
steps:
136128
- uses: actions/checkout@v4
@@ -143,6 +135,10 @@ jobs:
143135
throw "The shell runs as $env:PROCESSOR_ARCHITECTURE; this job builds on ${{ matrix.machine }}."
144136
}
145137
./scripts/setup_windows.ps1 -RustToolchain $env:RUST_TOOLCHAIN -BuildToolsOnly
138+
- name: Set the release version
139+
run: |
140+
python scripts/set_release_version.py "$env:VERSION"
141+
if ($LASTEXITCODE -ne 0) { throw 'Release version update failed.' }
146142
- name: Build the desktop client
147143
run: ./scripts/build_winui.ps1 -Platform ${{ matrix.platform }} -SingleFile
148144
- name: Package the desktop client and license notices

‎docs/release.md‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ acceptance follows [signing](signing.md) as it does for a source build.
3939

4040
## Publish a release
4141

42-
1. Set the same `version` in `flare-cli/Cargo.toml`,
43-
`flare-winui/bridge/Cargo.toml`, and `flare-winui/launcher/Cargo.toml`,
44-
update the three `Cargo.lock` files, and merge the change to the default
45-
branch.
46-
2. Tag that commit `vMAJOR.MINOR.PATCH` with the same version and push the tag.
42+
Development checkouts use `0.0.0` in the three release manifests and their
43+
lockfiles. Do not commit a release-version bump. Tag the intended commit
44+
`vMAJOR.MINOR.PATCH` and push the tag. The build jobs use
45+
`scripts/set_release_version.py` to apply the tag's version to
46+
`flare-cli/Cargo.toml`, `flare-winui/bridge/Cargo.toml`,
47+
`flare-winui/launcher/Cargo.toml`, and their lockfiles in each runner's
48+
checkout.
4749

4850
The workflow publishes to the repository that received the tag. Running it
4951
through `workflow_dispatch` performs every build and check and uploads the four
@@ -60,8 +62,9 @@ All builds use Rust 1.94.1 and the locked Cargo manifests. Every job must pass
6062
before anything is published; no target can be skipped.
6163

6264
- **Version.** A tag push requires the tagged commit to be an ancestor of the
63-
default branch. The three crate versions listed above must equal the tag's
64-
version. A dispatched run takes the version from `flare-cli/Cargo.toml`.
65+
default branch and all three release manifests and lockfiles to contain
66+
`0.0.0`. Each build job applies the tag's version before compiling. A
67+
dispatched run builds `0.0.0` without publishing a release.
6568
- **Linux.** The runner builds `flare` with
6669
`cargo build --locked --release --manifest-path flare-cli/Cargo.toml` and
6770
packages it with `packaging/archive.py`. The extracted archive then runs in

‎flare-cli/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flare-cli/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flare-cli"
3-
version = "0.2.1"
3+
version = "0.0.0"
44
license = "Apache-2.0"
55
edition = "2024"
66
rust-version = "1.88"

‎flare-winui/bridge/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flare-winui/bridge/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flare-winui-bridge"
3-
version = "0.2.1"
3+
version = "0.0.0"
44
edition = "2024"
55
rust-version = "1.88"
66
license = "Apache-2.0"

‎flare-winui/launcher/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flare-winui/launcher/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flare-launcher"
3-
version = "0.1.0"
3+
version = "0.0.0"
44
edition = "2024"
55
rust-version = "1.88"
66
license = "Apache-2.0"

‎scripts/set_release_version.py‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env python3
2+
"""Set or check versions for Flare's independently packaged release crates."""
3+
4+
import argparse
5+
from pathlib import Path
6+
import re
7+
import subprocess
8+
import sys
9+
import tomllib
10+
11+
CRATES = (
12+
(Path("flare-cli"), "flare-cli"),
13+
(Path("flare-winui/bridge"), "flare-winui-bridge"),
14+
(Path("flare-winui/launcher"), "flare-launcher"),
15+
)
16+
STABLE_VERSION = re.compile(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)")
17+
PACKAGE_SECTION = re.compile(r"(?ms)^\[package\]\n(.*?)(?=^\[|\Z)")
18+
MANIFEST_VERSION = re.compile(r'(?m)^version = "[^"]+"')
19+
20+
21+
def manifest(path: Path, package: str) -> tuple[str, str]:
22+
text = path.read_text(encoding="utf-8")
23+
document = tomllib.loads(text)
24+
if document["package"]["name"] != package:
25+
raise ValueError(f"{path} does not define {package}")
26+
return text, document["package"]["version"]
27+
28+
29+
def lock_version(path: Path, package: str) -> str:
30+
document = tomllib.loads(path.read_text(encoding="utf-8"))
31+
versions = [entry["version"] for entry in document["package"] if entry["name"] == package]
32+
if len(versions) != 1:
33+
raise ValueError(f"{path} has {len(versions)} entries for {package}; expected one")
34+
return versions[0]
35+
36+
37+
def replace_manifest_version(path: Path, package: str, version: str) -> tuple[str, str, str]:
38+
text, current = manifest(path, package)
39+
section = PACKAGE_SECTION.search(text)
40+
if section is None:
41+
raise ValueError(f"{path} has no package section")
42+
field = MANIFEST_VERSION.search(section.group(1))
43+
if field is None:
44+
raise ValueError(f"{path} has no package version field")
45+
start = section.start(1) + field.start()
46+
end = section.start(1) + field.end()
47+
return text[:start] + f'version = "{version}"' + text[end:], current, lock_version(
48+
path.with_name("Cargo.lock"), package
49+
)
50+
51+
52+
def check(root: Path, version: str) -> list[str]:
53+
errors = []
54+
for directory, package in CRATES:
55+
manifest_path = root / directory / "Cargo.toml"
56+
_, actual_manifest = manifest(manifest_path, package)
57+
actual_lock = lock_version(manifest_path.with_name("Cargo.lock"), package)
58+
if actual_manifest != version:
59+
errors.append(f"{manifest_path}: version is {actual_manifest}; expected {version}")
60+
if actual_lock != version:
61+
errors.append(
62+
f"{manifest_path.with_name('Cargo.lock')}: {package} is {actual_lock}; expected {version}"
63+
)
64+
return errors
65+
66+
67+
def set_version(root: Path, version: str) -> None:
68+
updates = []
69+
for directory, package in CRATES:
70+
path = root / directory / "Cargo.toml"
71+
text, current, current_lock = replace_manifest_version(path, package, version)
72+
updates.append((path, text, current, current_lock))
73+
74+
for path, text, _, _ in updates:
75+
path.write_text(text, encoding="utf-8")
76+
77+
for (directory, package), (_, _, current, current_lock) in zip(CRATES, updates):
78+
path = root / directory / "Cargo.toml"
79+
if current_lock != version:
80+
subprocess.run(
81+
[
82+
"cargo",
83+
"update",
84+
"--manifest-path",
85+
str(path),
86+
"--package",
87+
package,
88+
"--precise",
89+
version,
90+
],
91+
cwd=root,
92+
check=True,
93+
)
94+
print(f"{path.relative_to(root)}: {current} -> {version}")
95+
96+
errors = check(root, version)
97+
if errors:
98+
raise ValueError("\n".join(errors))
99+
100+
101+
def main() -> int:
102+
parser = argparse.ArgumentParser(description=__doc__)
103+
parser.add_argument("version", help="stable MAJOR.MINOR.PATCH version")
104+
parser.add_argument("--check", action="store_true", help="check without changing files")
105+
args = parser.parse_args()
106+
if not STABLE_VERSION.fullmatch(args.version):
107+
parser.error("version must be a stable MAJOR.MINOR.PATCH version")
108+
109+
root = Path(__file__).resolve().parent.parent
110+
try:
111+
if args.check:
112+
errors = check(root, args.version)
113+
if errors:
114+
raise ValueError("\n".join(errors))
115+
print(f"Release manifests and lockfiles are {args.version}.")
116+
else:
117+
set_version(root, args.version)
118+
except (OSError, KeyError, ValueError, subprocess.CalledProcessError) as error:
119+
print(f"error: {error}", file=sys.stderr)
120+
return 1
121+
return 0
122+
123+
124+
if __name__ == "__main__":
125+
raise SystemExit(main())

0 commit comments

Comments
 (0)