-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create CI script to trigger a release on new version in Cargo.toml
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
check: | ||
name: Trigger Release | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: "Install Python Libraries" | ||
run: python -m pip install --user -r .github/workflows/trigger-release/requirements.txt | ||
|
||
- name: "Run release script" | ||
run: "python3 .github/workflows/trigger-release/trigger-release.py" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import toml | ||
import requests | ||
import subprocess | ||
|
||
cargo_toml = toml.load("Cargo.toml") | ||
crate_version = cargo_toml["workspace"]["package"]["version"] | ||
print("Detected crate version " + crate_version) | ||
|
||
api_url = "https://crates.io/api/v1/crates/bootloader/" + crate_version | ||
released_version = requests.get(api_url).json() | ||
|
||
if "version" in released_version: | ||
version = released_version["version"] | ||
assert (version["crate"] == "bootloader") | ||
assert (version["num"] == crate_version) | ||
print("Version " + crate_version + " already exists on crates.io") | ||
|
||
else: | ||
print("Could not find version " + crate_version + | ||
" on crates.io; creating a new release") | ||
|
||
tag_name = "v" + crate_version | ||
print(" Tagging commit as " + tag_name) | ||
sha = subprocess.run(["git", "rev-parse", "HEAD"], check=True, | ||
stdout=subprocess.PIPE).stdout.decode("utf-8").strip() | ||
subprocess.run([ | ||
"gh", "api", "/repos/rust-osdev/x86_64/git/refs", | ||
"-X", "POST", "-H", "Accept: application/vnd.github.v3+json", | ||
"-F", "ref=refs/tags/" + tag_name, | ||
"-F", "sha="+sha | ||
]) | ||
|
||
subprocess.run([ | ||
"gh", "api", "--method", "POST", "-H", "Accept: application/vnd.github+json", | ||
"/repos/rust-osdev/bootloader/releases", | ||
"-f", f"tag_name='{tag_name}'", "-f", f"target_commitish='{sha}'", | ||
"-f", f"name='{tag_name}'", | ||
"-f", "body='[Changelog](https://github.com/rust-osdev/bootloader/blob/main/Changelog.md)'", | ||
"-F", "draft=false", "-F", "prerelease=false", "-F", "generate_release_notes=false", | ||
]) | ||
|
||
print(" Done") |