Skip to content

Commit 99d1328

Browse files
authored
CI - Publishable crates check also checks for license file (#2681)
Co-authored-by: Zeke Foppa <[email protected]>
1 parent 020d64c commit 99d1328

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

crates/codegen/LICENSE

Whitespace-only changes.

tools/crate-publish-checks.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from pathlib import Path
55

6-
def find_non_path_spacetimedb_deps(dev_deps):
6+
def find_non_path_spacetimedb_deps(dev_deps, cargo_toml_path):
77
non_path_spacetimedb = []
88
for name, details in dev_deps.items():
99
if not name.startswith("spacetimedb"):
@@ -15,10 +15,10 @@ def find_non_path_spacetimedb_deps(dev_deps):
1515
else:
1616
# String dependency = version from crates.io
1717
non_path_spacetimedb.append(name)
18-
return non_path_spacetimedb
18+
success = not non_path_spacetimedb
19+
return success, non_path_spacetimedb
1920

20-
def check_cargo_metadata(data):
21-
package = data.get("package", {})
21+
def check_cargo_metadata(package, cargo_toml_path):
2222
missing_fields = []
2323

2424
# Accept either license OR license-file
@@ -28,7 +28,31 @@ def check_cargo_metadata(data):
2828
if "description" not in package:
2929
missing_fields.append("description")
3030

31-
return missing_fields
31+
missing_license_file = None
32+
if "license-file" in package:
33+
license_file = package["license-file"]
34+
license_path = cargo_toml_path.parent / license_file
35+
if not license_path.exists():
36+
missing_license_file = license_path
37+
38+
success = not missing_fields and not missing_license_file
39+
return success, missing_fields, missing_license_file
40+
41+
def run_checks(data, cargo_toml_path):
42+
result = {
43+
"success": True,
44+
}
45+
46+
success, bad_deps = find_non_path_spacetimedb_deps(data.get("dev-dependencies", {}), cargo_toml_path)
47+
result["success"] = result["success"] and success
48+
result["bad_deps"] = bad_deps
49+
50+
success, missing_fields, missing_license_file = check_cargo_metadata(data.get("package", {}), cargo_toml_path)
51+
result["missing_fields"] = missing_fields
52+
result["missing_license_file"] = missing_license_file
53+
result["success"] = result["success"] and success
54+
55+
return result
3256

3357
if __name__ == "__main__":
3458
parser = argparse.ArgumentParser(description="Check Cargo.toml for metadata and dev-dependencies.")
@@ -43,29 +67,18 @@ def check_cargo_metadata(data):
4367

4468
data = toml.load(cargo_toml_path)
4569

46-
# Check dev-dependencies
47-
dev_deps = data.get("dev-dependencies", {})
48-
bad_deps = find_non_path_spacetimedb_deps(dev_deps)
49-
50-
# Check license/license-file and description
51-
missing_fields = check_cargo_metadata(data)
52-
53-
exit_code = 0
54-
55-
if bad_deps:
56-
print(f"❌ These dev-dependencies in {cargo_toml_path} must be converted to use `path` in order to not impede crate publishing:")
57-
for dep in bad_deps:
58-
print(f" - {dep}")
59-
exit_code = 1
60-
61-
if missing_fields:
62-
print(f"❌ Missing required fields in [package] of {cargo_toml_path}: {', '.join(missing_fields)}")
63-
exit_code = 1
64-
65-
if exit_code == 0:
70+
checks = run_checks(data, cargo_toml_path)
71+
if checks["success"]:
6672
print(f"✅ {cargo_toml_path} passed all checks.")
67-
68-
sys.exit(exit_code)
73+
else:
74+
print(f"❌ {cargo_toml_path} failed checks:")
75+
if checks["missing_fields"]:
76+
print(f" Missing required fields: {', '.join(checks['missing_fields'])}")
77+
if checks["missing_license_file"]:
78+
print(f" Specified license file does not exist: {checks['missing_license_file']}")
79+
if checks["bad_deps"]:
80+
print(f" These dev-dependencies must be converted to use `path` in order to not impede crate publishing: {', '.join(checks['bad_deps'])}")
81+
sys.exit(1)
6982

7083
except Exception as e:
7184
print(f"⚠️ Error: {e}")

0 commit comments

Comments
 (0)