|
| 1 | +import toml |
| 2 | +import requests |
| 3 | +import subprocess |
| 4 | + |
| 5 | +cargo_toml = toml.load("Cargo.toml") |
| 6 | +crate_version = cargo_toml["workspace"]["package"]["version"] |
| 7 | +print("Detected crate version " + crate_version) |
| 8 | + |
| 9 | +api_url = "https://crates.io/api/v1/crates/bootloader/" + crate_version |
| 10 | +released_version = requests.get(api_url).json() |
| 11 | + |
| 12 | +if "version" in released_version: |
| 13 | + version = released_version["version"] |
| 14 | + assert (version["crate"] == "bootloader") |
| 15 | + assert (version["num"] == crate_version) |
| 16 | + print("Version " + crate_version + " already exists on crates.io") |
| 17 | + |
| 18 | +else: |
| 19 | + print("Could not find version " + crate_version + |
| 20 | + " on crates.io; creating a new release") |
| 21 | + |
| 22 | + tag_name = "v" + crate_version |
| 23 | + print(" Tagging commit as " + tag_name) |
| 24 | + sha = subprocess.run(["git", "rev-parse", "HEAD"], check=True, |
| 25 | + stdout=subprocess.PIPE).stdout.decode("utf-8").strip() |
| 26 | + subprocess.run([ |
| 27 | + "gh", "api", "/repos/rust-osdev/x86_64/git/refs", |
| 28 | + "-X", "POST", "-H", "Accept: application/vnd.github.v3+json", |
| 29 | + "-F", "ref=refs/tags/" + tag_name, |
| 30 | + "-F", "sha="+sha |
| 31 | + ]) |
| 32 | + |
| 33 | + subprocess.run([ |
| 34 | + "gh", "api", "--method", "POST", "-H", "Accept: application/vnd.github+json", |
| 35 | + "/repos/rust-osdev/bootloader/releases", |
| 36 | + "-f", f"tag_name='{tag_name}'", "-f", f"target_commitish='{sha}'", |
| 37 | + "-f", f"name='{tag_name}'", |
| 38 | + "-f", "body='[Changelog](https://github.com/rust-osdev/bootloader/blob/main/Changelog.md)'", |
| 39 | + "-F", "draft=false", "-F", "prerelease=false", "-F", "generate_release_notes=false", |
| 40 | + ]) |
| 41 | + |
| 42 | + print(" Done") |
0 commit comments