import sys
import subprocess
import os
def test():
cd(".")
run_commands([
"cargo build",
"cargo test"
])
def test_strict():
test()
cd(".")
run_commands([
"RUSTFLAGS=\"-D warnings\" cargo build",
"cargo clippy -- -D warnings",
"cargo rustdoc -- -D warnings -D rustdoc::all",
"cargo semver-checks"
])
def publish():
test_strict()
print("Publishing...")
run_commands([
"cargo package",
"cargo publish"
])
links()
def links():
print()
print("https://crates.io/crates/sac13")
print("https://docs.rs/sac13")
print()
TASKS = {
"test": test,
"publish": publish,
"test_strict": test_strict,
"links": links
}
def main():
cd(".")
if len(sys.argv) < 2 or sys.argv[1] not in TASKS:
print(f"Usage: {sys.argv[0]} <task>")
print("Available tasks:")
for name in TASKS:
print(f" - {name}")
sys.exit(1)
TASKS[sys.argv[1]]()
def run_commands(commands):
for cmd in commands:
print(f"RUN: '{cmd}'")
result = subprocess.run(cmd, shell=True)
if result.returncode != 0:
print(f"ERROR: Non-zero exit code {result.returncode}. CMD: '{cmd}'")
sys.exit(result.returncode)
print(f"SUCCESS RUN: '{cmd}'")
def cd(path):
script_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(os.path.join(script_dir, path))
if __name__ == "__main__":
main()