Skip to content
Closed
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions .claude/skills/release/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ description: Use when cutting a new problemreductions crate release — checks t

# Release

`make release V=x.y.z` bumps the version in `Cargo.toml`, `problemreductions-macros/Cargo.toml`,
and `problemreductions-cli/Cargo.toml` (plus the inter-crate dependency versions), runs
`cargo check`, commits `release: vX.Y.Z`, tags `vX.Y.Z`, and pushes `main` and tags. CI then
publishes all three crates to crates.io. A pushed tag cannot be taken back cleanly, so every
`make release V=x.y.z` bumps all five workspace package versions and the published
inter-crate dependency versions, runs `cargo check --workspace`, commits the manifests
and `Cargo.lock` as `release: vX.Y.Z`, tags `vX.Y.Z`, and pushes `main` and tags. CI then
publishes expr, macros, library, and CLI in dependency order to crates.io; the web crate
is not published. A pushed tag cannot be taken back cleanly, so every
gate below is hard.

## Gates (refuse if any fails)
Expand All @@ -22,6 +23,11 @@ make check # fmt-check + clippy + test must pass

`make release` enforces the same branch/clean/up-to-date guard and runs `make check` itself.

If `main` requires a pull request, prepare the version and lockfile changes in a
release PR and run the same checks there. After it merges, fast-forward local `main`,
verify its versions and clean state, and tag and push only that merged commit.
Do not bypass branch protection or push a tag pointing to an unmerged release commit.

## Version and changelog

```bash
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:

- uses: Swatinem/rust-cache@v2

- name: Publish expression crate
run: cargo publish --manifest-path problemreductions-expr/Cargo.toml --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

- name: Wait for expression crate to be indexed
run: sleep 30

- name: Publish macros crate
run: cargo publish --manifest-path problemreductions-macros/Cargo.toml --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [

[package]
name = "problemreductions"
version = "0.6.0"
version = "0.7.0"
edition = "2024"
rust-version = "1.88"
description = "A library for reducing NP-hard problems"
Expand All @@ -35,8 +35,8 @@ highs = "2.4.0"
inventory = "0.3.24"
rand = "0.10.2"
criterion = { version = "0.8.2", optional = true }
problemreductions-macros = { version = "0.6.0", path = "problemreductions-macros" }
problemreductions-expr = { version = "0.6.0", path = "problemreductions-expr" }
problemreductions-macros = { version = "0.7.0", path = "problemreductions-macros" }
problemreductions-expr = { version = "0.7.0", path = "problemreductions-expr" }

[dev-dependencies]
proptest = "1.11.0"
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ endif
$(MAKE) check
@echo "Releasing v$(V)..."
$(SED_I) 's/^version = ".*"/version = "$(V)"/' Cargo.toml
$(SED_I) 's/^version = ".*"/version = "$(V)"/' problemreductions-expr/Cargo.toml
$(SED_I) 's/^version = ".*"/version = "$(V)"/' problemreductions-macros/Cargo.toml
$(SED_I) 's/^version = ".*"/version = "$(V)"/' problemreductions-cli/Cargo.toml
$(SED_I) 's/^version = ".*"/version = "$(V)"/' problemreductions-web/Cargo.toml
$(SED_I) 's/problemreductions-expr = { version = "[^"]*"/problemreductions-expr = { version = "$(V)"/' Cargo.toml problemreductions-macros/Cargo.toml
$(SED_I) 's/problemreductions-macros = { version = "[^"]*"/problemreductions-macros = { version = "$(V)"/' Cargo.toml
$(SED_I) 's/problemreductions = { version = "[^"]*"/problemreductions = { version = "$(V)"/' problemreductions-cli/Cargo.toml
cargo check
git add Cargo.toml problemreductions-macros/Cargo.toml problemreductions-cli/Cargo.toml
cargo check --workspace
git add Cargo.toml problemreductions-expr/Cargo.toml problemreductions-macros/Cargo.toml problemreductions-cli/Cargo.toml problemreductions-web/Cargo.toml Cargo.lock
git commit -m "release: v$(V)"
git tag -a "v$(V)" -m "Release v$(V)"
git push origin main --tags
Expand Down
4 changes: 2 additions & 2 deletions problemreductions-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "problemreductions-cli"
version = "0.6.0"
version = "0.7.0"
edition = "2024"
rust-version = "1.88"
description = "CLI tool for exploring NP-hard problem reductions"
Expand All @@ -21,7 +21,7 @@ all = ["mcp"]
mcp = ["dep:rmcp", "dep:tokio", "dep:schemars", "dep:tracing-subscriber"]

[dependencies]
problemreductions = { version = "0.6.0", path = "..", features = ["example-db"] }
problemreductions = { version = "0.7.0", path = "..", features = ["example-db"] }
clap = { version = "4.6.7", features = ["derive", "string"] }
anyhow = "1.0.104"
serde = { version = "1.0.229", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion problemreductions-expr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "problemreductions-expr"
version = "0.6.0"
version = "0.7.0"
edition = "2024"
rust-version = "1.88"
description = "Lossless symbolic expressions for problemreductions"
Expand Down
4 changes: 2 additions & 2 deletions problemreductions-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "problemreductions-macros"
version = "0.6.0"
version = "0.7.0"
edition = "2024"
rust-version = "1.88"
description = "Procedural macros for problemreductions"
Expand All @@ -14,5 +14,5 @@ proc-macro = true
syn = { version = "3.0.6", features = ["full", "parsing"] }
quote = "1.0.47"
proc-macro2 = "1.0.107"
problemreductions-expr = { version = "0.6.0", path = "../problemreductions-expr" }
problemreductions-expr = { version = "0.7.0", path = "../problemreductions-expr" }
num-traits = "0.2.19"
2 changes: 1 addition & 1 deletion problemreductions-web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "problemreductions-web"
version = "0.6.0"
version = "0.7.0"
edition = "2024"
rust-version = "1.88"
publish = false
Expand Down
78 changes: 78 additions & 0 deletions scripts/test_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Exercise the release target with real Cargo and a local Git remote."""

import shutil
import subprocess
import tempfile
import tomllib
from pathlib import Path


def run(*args, cwd):
result = subprocess.run(args, cwd=cwd, text=True, capture_output=True)
assert result.returncode == 0, result.stdout + result.stderr
return result.stdout.strip()


def check_release():
with tempfile.TemporaryDirectory(prefix="release-check-") as tmp:
root = Path(tmp)
repo = root / "repo"
repo.mkdir()
remote = root / "origin.git"
run("git", "init", "--bare", str(remote), cwd=root)
run("git", "init", "-b", "main", cwd=repo)
run("git", "config", "user.name", "Release Test", cwd=repo)
run("git", "config", "user.email", "release@example.com", cwd=repo)
run("git", "remote", "add", "origin", str(remote), cwd=repo)
shutil.copyfile(Path(__file__).resolve().parents[1] / "Makefile", repo / "Makefile")

dependencies = {
"problemreductions": ["problemreductions-macros", "problemreductions-expr"],
"problemreductions-macros": ["problemreductions-expr"],
"problemreductions-expr": [],
"problemreductions-cli": ["problemreductions"],
"problemreductions-web": ["problemreductions-expr"],
}
for name, deps in dependencies.items():
package = repo if name == "problemreductions" else repo / name
(package / "src").mkdir(parents=True)
(package / "src/lib.rs").write_text("pub const READY: bool = true;\n")
manifest = f'[package]\nname = "{name}"\nversion = "0.1.0"\nedition = "2024"\n'
if name == "problemreductions":
members = ", ".join(f'"{n}"' for n in dependencies if n != name)
manifest += f'\n[workspace]\nmembers = [{members}]\n'
manifest += '\n[features]\nexample-db = []\n'
manifest += "\n[dependencies]\n"
for dep in deps:
path = dep if name == "problemreductions" else f"../{dep}"
if dep == "problemreductions":
path = ".."
version = '' if name == "problemreductions-web" else 'version = "0.1.0", '
manifest += f'{dep} = {{ {version}path = "{path}" }}\n'
(package / "Cargo.toml").write_text(manifest)
(repo / ".gitignore").write_text("/target/\n")
run("cargo", "generate-lockfile", "--offline", cwd=repo)
run("git", "add", ".", cwd=repo)
run("git", "commit", "-m", "Initial workspace", cwd=repo)
run("git", "push", "-u", "origin", "main", cwd=repo)

run("make", "release", "V=0.2.0", cwd=repo)

for name, deps in dependencies.items():
package = repo if name == "problemreductions" else repo / name
manifest = tomllib.loads((package / "Cargo.toml").read_text())
assert manifest["package"]["version"] == "0.2.0", name
for dep in deps:
if name != "problemreductions-web":
assert manifest["dependencies"][dep]["version"] == "0.2.0", (name, dep)
assert run("git", "status", "--porcelain", cwd=repo) == ""
commit = run("git", "rev-parse", "HEAD", cwd=repo)
assert run("git", "rev-parse", "v0.2.0^{}", cwd=remote) == commit
assert run("git", "rev-parse", "main", cwd=remote) == commit
lock = tomllib.loads(run("git", "show", "v0.2.0:Cargo.lock", cwd=repo))
assert all(p["version"] == "0.2.0" for p in lock["package"])


if __name__ == "__main__":
check_release()
print("Release versions, lockfile, commit, and remote tag verified.")
6 changes: 1 addition & 5 deletions src/models/graph/minimum_edge_cost_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,7 @@ impl MinimumEdgeCostFlow {
}

// (3) Flow requirement: net flow into sink >= R
if balance[self.sink] < self.required_flow {
return Ok(false);
}

Ok(true)
Ok(balance[self.sink] >= self.required_flow)
}

/// Compute the edge cost for a feasible flow: sum of prices of arcs with
Expand Down
6 changes: 1 addition & 5 deletions src/models/misc/minimum_register_sufficiency_for_loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ impl MinimumRegisterSufficiencyForLoops {
// Check if arc1 is entirely in the gap of arc2.
let gap2_start = (s2 + l2) % n;
let dist_s1_in_gap2 = (s1 + n - gap2_start) % n;
if dist_s1_in_gap2 + l1 <= n - l2 {
return false;
}

true
dist_s1_in_gap2 + l1 > n - l2
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/models/misc/rectilinear_picture_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,19 @@ impl RectilinearPictureCompression {
}
// Find the rightmost column from c1 that is all-1 in row r1.
let mut c_max = n;
for c in c1..n {
if !self.matrix[r1][c] {
for (c, &filled) in self.matrix[r1].iter().enumerate().skip(c1) {
if !filled {
c_max = c;
break;
}
}
// Extend downward row by row, narrowing column range.
let mut c_end = c_max; // exclusive upper bound on columns
for r2 in r1..m {
for (r2, row) in self.matrix.iter().enumerate().skip(r1) {
// Narrow c_end based on row r2.
let mut new_c_end = c1;
for c in c1..c_end {
if self.matrix[r2][c] {
for (c, &filled) in row.iter().enumerate().take(c_end).skip(c1) {
if filled {
new_c_end = c + 1;
} else {
break;
Expand Down
8 changes: 2 additions & 6 deletions src/rules/ksatisfiability_preemptivescheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,13 @@ fn construct_schedule_from_assignment(
if pattern == 0 {
return None;
}
for pattern_index in 0..7 {
for (pattern_index, &job) in construction.clause_jobs[clause_index].iter().enumerate() {
let slot = if pattern_index + 1 == pattern {
source.num_vars() + 1
} else {
source.num_vars() + 2
};
set_task_slot(
&mut task_slots,
construction.clause_jobs[clause_index][pattern_index],
slot,
);
set_task_slot(&mut task_slots, job, slot);
}
}

Expand Down
23 changes: 11 additions & 12 deletions src/rules/unitdiskmapping/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ impl MappingGrid {
/// Get all occupied coordinates.
pub fn occupied_coords(&self) -> Vec<(usize, usize)> {
let mut coords = Vec::new();
for r in 0..self.rows {
for c in 0..self.cols {
if self.content[r][c].is_occupied() {
for (r, row) in self.content.iter().enumerate() {
for (c, cell) in row.iter().enumerate() {
if cell.is_occupied() {
coords.push((r, c));
}
}
Expand All @@ -200,9 +200,9 @@ impl MappingGrid {
/// Returns a set of (row, col) for cells in the Doubled state.
pub fn doubled_cells(&self) -> std::collections::HashSet<(usize, usize)> {
let mut cells = std::collections::HashSet::new();
for r in 0..self.rows {
for c in 0..self.cols {
if matches!(self.content[r][c], CellState::Doubled { .. }) {
for (r, row) in self.content.iter().enumerate() {
for (c, cell) in row.iter().enumerate() {
if matches!(cell, CellState::Doubled { .. }) {
cells.insert((r, c));
}
}
Expand Down Expand Up @@ -250,9 +250,9 @@ impl MappingGrid {
let pos_to_idx: HashMap<(usize, usize), usize> = if config.is_some() {
let mut map = HashMap::new();
let mut idx = 0;
for r in 0..self.rows {
for c in 0..self.cols {
if self.content[r][c].is_occupied() {
for (r, row) in self.content.iter().enumerate() {
for (c, cell) in row.iter().enumerate() {
if cell.is_occupied() {
map.insert((r, c), idx);
idx += 1;
}
Expand All @@ -265,10 +265,9 @@ impl MappingGrid {

let mut lines = Vec::new();

for r in 0..self.rows {
for (r, row) in self.content.iter().enumerate() {
let mut line = String::new();
for c in 0..self.cols {
let cell = &self.content[r][c];
for (c, cell) in row.iter().enumerate() {
let s = if let Some(cfg) = config {
if let Some(&idx) = pos_to_idx.get(&(r, c)) {
if cfg.get(idx).copied().unwrap_or(0) > 0 {
Expand Down
Loading