From 9cbf7eb7443b0f11da9ebab6f1b81c203e442094 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 08:12:52 +0200 Subject: [PATCH 1/9] Create a basic release script --- .github/workflows/release.yml | 19 +++++++++++++++++++ scripts/ci-release.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/ci-release.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..65e3eba54 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,19 @@ +name: Release + +on: + push: + branches: + - 'ci-release' + +jobs: + release: + name: "Release" + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: "Checkout Repository" + uses: actions/checkout@v1 + + - name: "Run release script" + run: "python3 scripts/ci-release.py" diff --git a/scripts/ci-release.py b/scripts/ci-release.py new file mode 100644 index 000000000..8c427cd84 --- /dev/null +++ b/scripts/ci-release.py @@ -0,0 +1,31 @@ +import toml +import requests +import subprocess + +cargo_toml = toml.load("Cargo.toml") +crate_version = cargo_toml["package"]["version"] +print("Detected crate version " + crate_version) + +api_url = "https://crates.io/api/v1/crates/x86_64/versions" +crates_io_versions = requests.get(api_url).json() + +new_version = True +for version in crates_io_versions["versions"]: + assert (version["crate"] == "x86_64") + if version["num"] == crate_version: + new_version = False + break + +if new_version: + 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) + subprocess.run(["git", "tag", tag_name], check=True) + + print(" Running `cargo publish`") + subprocess.run(["cargo", "publish", "--dry-run"], check=True) + + print(" Done") +else: + print("Version " + crate_version + " already exists on crates.io") From 26c71ca252f40e73cb666b94e4c556a107285c0a Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 08:15:53 +0200 Subject: [PATCH 2/9] Install python requirements --- .github/workflows/release.yml | 4 ++++ scripts/requirements.txt | 1 + 2 files changed, 5 insertions(+) create mode 100644 scripts/requirements.txt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 65e3eba54..404c9b33b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,5 +15,9 @@ jobs: - name: "Checkout Repository" uses: actions/checkout@v1 + - name: "Install Python Libraries" + run: python -m pip install --user -r requirements.txt + working-directory: "scripts" + - name: "Run release script" run: "python3 scripts/ci-release.py" diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 000000000..bd79a658f --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1 @@ +toml From f998080b54d26976606dd0ac784256a8f713c348 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 08:16:42 +0200 Subject: [PATCH 3/9] Bump version for testing --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5859f2841..7a696233f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ license = "MIT/Apache-2.0" name = "x86_64" readme = "README.md" repository = "https://github.com/rust-osdev/x86_64" -version = "0.14.3" +version = "0.14.4-alpha" edition = "2018" [dependencies] From f74310fe109bb990844b26cbb122277fd388df69 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 08:19:19 +0200 Subject: [PATCH 4/9] Run cargo publish without --dry-run --- scripts/ci-release.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci-release.py b/scripts/ci-release.py index 8c427cd84..4d04148fe 100644 --- a/scripts/ci-release.py +++ b/scripts/ci-release.py @@ -24,7 +24,7 @@ subprocess.run(["git", "tag", tag_name], check=True) print(" Running `cargo publish`") - subprocess.run(["cargo", "publish", "--dry-run"], check=True) + subprocess.run(["cargo", "publish"], check=True) print(" Done") else: From e621338b482fc160f85489d7a86c8e7a1ac239de Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 08:21:50 +0200 Subject: [PATCH 5/9] Push the git tag to the repo --- Cargo.toml | 2 +- scripts/ci-release.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7a696233f..891951655 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ license = "MIT/Apache-2.0" name = "x86_64" readme = "README.md" repository = "https://github.com/rust-osdev/x86_64" -version = "0.14.4-alpha" +version = "0.0.1-alpha" edition = "2018" [dependencies] diff --git a/scripts/ci-release.py b/scripts/ci-release.py index 4d04148fe..1bbe109b2 100644 --- a/scripts/ci-release.py +++ b/scripts/ci-release.py @@ -19,12 +19,13 @@ if new_version: print("Could not find version " + crate_version + " on crates.io; creating a new release") + print(" Running `cargo publish`") + subprocess.run(["cargo", "publish"], check=True) + tag_name = "v" + crate_version print(" Tagging commit as " + tag_name) subprocess.run(["git", "tag", tag_name], check=True) - - print(" Running `cargo publish`") - subprocess.run(["cargo", "publish"], check=True) + subprocess.run(["git", "push", "origin", tag_name], check=True) print(" Done") else: From 9c7f0f22d24f206e1dc1bac93597835e5037da89 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 08:35:02 +0200 Subject: [PATCH 6/9] Set up crates.io token for releasing --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 404c9b33b..a5afdb9aa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,7 @@ jobs: name: "Release" runs-on: ubuntu-latest timeout-minutes: 15 + environment: crates_io_release steps: - name: "Checkout Repository" @@ -21,3 +22,5 @@ jobs: - name: "Run release script" run: "python3 scripts/ci-release.py" + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} From 3e934c3ad71ea656a2677a0be7e898dcccadc8a1 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 09:30:19 +0200 Subject: [PATCH 7/9] Fix tagging --- Cargo.toml | 2 +- scripts/ci-release.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 891951655..138335edd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ license = "MIT/Apache-2.0" name = "x86_64" readme = "README.md" repository = "https://github.com/rust-osdev/x86_64" -version = "0.0.1-alpha" +version = "0.0.1-alpha.1" edition = "2018" [dependencies] diff --git a/scripts/ci-release.py b/scripts/ci-release.py index 1bbe109b2..2386fe85c 100644 --- a/scripts/ci-release.py +++ b/scripts/ci-release.py @@ -24,8 +24,13 @@ tag_name = "v" + crate_version print(" Tagging commit as " + tag_name) - subprocess.run(["git", "tag", tag_name], check=True) - subprocess.run(["git", "push", "origin", tag_name], check=True) + 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 + ]) print(" Done") else: From 1c2e2c7597e6dd44dc065d91b7b71d51ac5e7a10 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 09:35:00 +0200 Subject: [PATCH 8/9] Authenticate `gh` tool --- .github/workflows/release.yml | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5afdb9aa..eedaada37 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,3 +24,4 @@ jobs: run: "python3 scripts/ci-release.py" env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 138335edd..30a32907a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ license = "MIT/Apache-2.0" name = "x86_64" readme = "README.md" repository = "https://github.com/rust-osdev/x86_64" -version = "0.0.1-alpha.1" +version = "0.0.1-alpha.2" edition = "2018" [dependencies] From 3bc134e9931a7dc8c25d74ba093d50816a3dd3d4 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Jul 2021 09:37:30 +0200 Subject: [PATCH 9/9] Run script only on master branch and set version back to 0.14.3 --- .github/workflows/release.yml | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eedaada37..17583b0e1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Release on: push: branches: - - 'ci-release' + - 'master' jobs: release: diff --git a/Cargo.toml b/Cargo.toml index 30a32907a..5859f2841 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ license = "MIT/Apache-2.0" name = "x86_64" readme = "README.md" repository = "https://github.com/rust-osdev/x86_64" -version = "0.0.1-alpha.2" +version = "0.14.3" edition = "2018" [dependencies]