Skip to content
Merged
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
106 changes: 106 additions & 0 deletions .github/scripts/check_version_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3

from __future__ import annotations

import argparse
import subprocess
import sys
import tomllib
from pathlib import Path


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Verify Cargo.toml version is aligned with git tags."
)
parser.add_argument(
"--cargo-toml",
default="Cargo.toml",
help="Path to the Cargo.toml file to validate.",
)
parser.add_argument(
"--tag",
help="Require Cargo.toml to match this exact git tag (for release workflows).",
)
return parser.parse_args()


def normalize_version(raw: str) -> str:
value = raw.strip()
return value[1:] if value.startswith("v") else value


def parse_version(raw: str) -> tuple[int, ...]:
normalized = normalize_version(raw)
parts = normalized.split(".")
if not parts or any(not part.isdigit() for part in parts):
raise ValueError(
f"Unsupported version '{raw}'. Expected dotted numeric versions like 0.5.26."
)
return tuple(int(part) for part in parts)


def read_cargo_version(cargo_toml: Path) -> str:
with cargo_toml.open("rb") as handle:
data = tomllib.load(handle)
try:
return str(data["package"]["version"])
except KeyError as error:
raise KeyError(f"Missing [package].version in {cargo_toml}") from error


def latest_release_tag() -> str | None:
completed = subprocess.run(
["git", "tag", "--list", "v*", "--sort=-v:refname"],
check=True,
capture_output=True,
text=True,
)
for line in completed.stdout.splitlines():
candidate = line.strip()
if candidate:
return candidate
return None


def main() -> int:
args = parse_args()
cargo_toml = Path(args.cargo_toml)
cargo_version = read_cargo_version(cargo_toml)
cargo_tuple = parse_version(cargo_version)

if args.tag:
tag_version = normalize_version(args.tag)
if cargo_version != tag_version:
print(
f"Cargo.toml version {cargo_version} does not match release tag {args.tag}.",
file=sys.stderr,
)
return 1
print(f"Cargo.toml version {cargo_version} matches release tag {args.tag}.")
return 0

latest_tag = latest_release_tag()
if latest_tag is None:
print(f"Cargo.toml version {cargo_version} validated (no release tags found).")
return 0

latest_tuple = parse_version(latest_tag)
if cargo_tuple < latest_tuple:
print(
(
f"Cargo.toml version {cargo_version} is behind the latest tag {latest_tag}. "
"Bump [package].version before merging."
),
file=sys.stderr,
)
return 1

print(
f"Cargo.toml version {cargo_version} is aligned with latest tag {latest_tag}."
)
return 0


if __name__ == "__main__":
raise SystemExit(main())
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ env:
CARGO_TERM_COLOR: always

jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Verify Cargo version is not behind tags
run: python3 .github/scripts/check_version_sync.py

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Lint GitHub Actions
uses: raven-actions/actionlint@v2
- uses: actions/setup-node@v4
- uses: actions/setup-node@v5
with:
node-version: '20'
- name: Build frontend
Expand All @@ -33,7 +42,7 @@ jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.88.0
- uses: Swatinem/rust-cache@v2
- name: Install cargo-audit
Expand All @@ -47,8 +56,8 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: '20'
- name: Build frontend
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/diffscope.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.draft
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/eval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
echo "configured=false" >> "$GITHUB_OUTPUT"
fi

- uses: actions/checkout@v4
- uses: actions/checkout@v5
if: ${{ steps.secret-check.outputs.configured == 'true' }}
with:
fetch-depth: 0
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ jobs:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Verify Cargo version matches tag
run: python3 .github/scripts/check_version_sync.py --tag "${{ github.ref_name }}"

- name: Extract version
id: get_version
Expand Down Expand Up @@ -99,10 +101,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Install Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
node-version: '20'

Expand Down Expand Up @@ -215,7 +217,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diffscope"
version = "0.5.3"
version = "0.5.26"
edition = "2021"
rust-version = "1.88"
authors = ["Jonathan Haas <jonathan@haas.holdings>"]
Expand Down
2 changes: 1 addition & 1 deletion src/commands/eval/runner/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(in super::super) async fn run_eval_fixture(
EvalFixtureDagConfig {
repro_validate,
repro_max_comments,
artifact_context,
artifact_context: artifact_context.cloned(),
},
)
.await?;
Expand Down
Loading
Loading