-
Notifications
You must be signed in to change notification settings - Fork 143
Create a CI script for automated releases #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9cbf7eb
Create a basic release script
phil-opp 26c71ca
Install python requirements
phil-opp f998080
Bump version for testing
phil-opp f74310f
Run cargo publish without --dry-run
phil-opp e621338
Push the git tag to the repo
phil-opp 9c7f0f2
Set up crates.io token for releasing
phil-opp 3e934c3
Fix tagging
phil-opp 1c2e2c7
Authenticate `gh` tool
phil-opp 3bc134e
Run script only on master branch and set version back to 0.14.3
phil-opp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,27 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
|
||
jobs: | ||
release: | ||
name: "Release" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
environment: crates_io_release | ||
|
||
steps: | ||
- 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" | ||
env: | ||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or 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,37 @@ | ||
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") | ||
|
||
print(" Running `cargo publish`") | ||
subprocess.run(["cargo", "publish"], check=True) | ||
phil-opp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
]) | ||
|
||
print(" Done") | ||
else: | ||
print("Version " + crate_version + " already exists on crates.io") |
This file contains hidden or 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be made (slightly) more efficient by querying something like
https://crates.io/api/v1/crates/x86_64/0.14.3
directly, and then just checking if the returned JSON has a"version"
field, or thatversion.num
is the requested field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the existing solution is also fine, let's see if it works for 0.14.4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I didn't know about this API endpoint. Is there a complete reference for it somewhere?