Skip to content
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

Release via Github Actions workflow #999

Merged
merged 6 commits into from Nov 12, 2023

Conversation

nicholasbishop
Copy link
Contributor

This new workflow will simplify our release process and make it more reviewable:

  1. Create a branch that updates the versions of all packages you want to release. This PR should include all related changes such as updating the versions in dependent crates and updating the changelog.
  2. Create a PR of that branch. The subject of the PR must start with release:, the rest of the message is arbitrary.
  3. Once the PR is approved and merged, a Github Actions workflow will take care of creating git tags and publishing to crates.io.

Since all the changes are now part of one PR that is created before the release actually occurs, we can now review our release changes just like any other PR. And with the release happening in a github action, it avoids a lot of easy-to-make mistakes such as releasing from the wrong commit or forgetting to push tags.

Obviously it's a little tricky to test release flows, so while I've tested the git-tag portion and a dry-run of the cargo-publish step, there could certainly be some bugs to resolve.

Closes #325

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@nicholasbishop nicholasbishop force-pushed the bishop-auto-release-2 branch 2 times, most recently from 18f2543 to 8a89d68 Compare November 12, 2023 03:45
@phip1611
Copy link
Contributor

phip1611 commented Nov 12, 2023

Thanks for working on this @nicholasbishop , I like the idea. Once this is merged, I update #568 (if not obsolete now) and then we close this one was well.

@@ -44,6 +44,19 @@ pub fn run_cmd(mut cmd: Command) -> Result<()> {
}
}

/// Print a `Command` and run it, then check that it completes
/// successfully. Return the command's stdout.
pub fn get_cmd_stdout(mut cmd: Command) -> Result<Vec<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: pub fn run_command(mut cmd: Command) -> Result<String>

  1. From cmd.output() it is not obvious that the command is executed here. I had to double-check that in the docs
  2. I think we can already check here whether we have a string, right? Anything non-utf8 should be a failure anyway, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to run_cmd_get_stdout -- we already have a run_cmd above, which is useful when you want the stdout/stderr to not be hidden (like when running most cargo commands).

Changed to convert to a String as suggested.

@@ -24,5 +26,5 @@ sha2 = "0.10.6"
syn = { version = "2.0.0", features = ["full"] }
tar = "0.4.38"
tempfile = "3.6.0"
ureq = { version = "2.8.0", features = ["http-interop"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: any reason why you prefer ureq over hyper here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No super strong reason, but generally I agree with this section of the ureq docs: https://docs.rs/ureq/2.8.0/ureq/#blocking-io-for-simplicity

Basically, async IO (which hyper is built around) doesn't add much for a very low-traffic client like this, and would also significantly expand the dep tree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I don't have a strong opinion here either.

xtask/src/opt.rs Outdated
@@ -202,3 +203,9 @@ pub struct FmtOpt {
#[clap(long, action)]
pub check: bool,
}

/// Run the auto-release process.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add something like This is tied to the GitHub CI. or similar. We should also ensure that no unexpected things happen, when people run this locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to:

/// Run the auto-release process (should only be run by Github Action).
///
/// This is run by the `release.yml` workflow. It is not intended to be run
/// locally, and will exit immediately if `GITHUB_SHA` is not set.

So unless someone goes out of their way to set GITHUB_SHA it won't do anything when run locally, and even then it won't do publish anything unless that user has permissions to push to the repo/crates.io.

@@ -0,0 +1,20 @@
# This workflow runs when commits are pushed to main or a branch starting with
# "version-". It checks if any packages require a new release, and if so,
# creates the crates.io release and git tag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tag -> tags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- uses: Swatinem/rust-cache@v2
- run: cargo xtask auto-release
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
Copy link
Contributor

@phip1611 phip1611 Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this token bound to your account? How did you create it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this token is part of my account, although there's nothing really specific to my account -- any of the three of us with owner access to the uefi crates can create a token at https://crates.io/settings/tokens/new with the publish-update scope.

A potential alternative would be to create a service account instead of using a personal account, but then we'd need some way to manage credentials for that, so probably more trouble than it's worth for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree.

@phip1611
Copy link
Contributor

Generally speaking, I like the idea. Thanks for working on it! However, I'm concerned regarding the additional complexity in xtask. Could we also archive something similar with a simple shell script wrapper around cargo-release?

@nicholasbishop
Copy link
Contributor Author

However, I'm concerned regarding the additional complexity in xtask. Could we also archive something similar with a simple shell script wrapper around cargo-release?

Definitely a fair point. I think what I'd really like is to have this new code in its own library on crates.io for easy re-use, then we wouldn't need to maintain it in this repo. $dayjob makes it easy for me to contribute to existing open source repos, but there's significant overhead in me creating a new one myself, so I'm trying to avoid doing that ;)

It is possible that we could replace most of the code in release.rs with an invocation of cargo-release. I think the trouble I'm having there is that cargo-release is somewhat underdocumented given it's complexity. As far as I see they just have the two docs, leaving me unsure of exactly what behavior I can get out of it. And testing releases with a complex tool is a pain, since if you do it wrong you end up with tags and crates.io releases that you didn't intend. Dry-run mode helps with that some, but necessarily skips a lot of the important operations.

@phip1611
Copy link
Contributor

phip1611 commented Nov 12, 2023

$dayjob makes it easy for me to contribute to existing open source repos, but there's significant overhead in me creating a new one myself, so I'm trying to avoid doing that ;)

haha, I can relate 😄

Fine with me. No strong opinion regarding the approach we take. If it works, it's good. IMHO, I'd prefer if we merge this but also update #568 in a way that it first discusses WHAT we want (git tags with specific name) and then ways of HOW we achive this (approach A: github flow, approach B: manual flow)

@nicholasbishop nicholasbishop added this pull request to the merge queue Nov 12, 2023
Merged via the queue into rust-osdev:main with commit 554eb14 Nov 12, 2023
12 checks passed
@nicholasbishop nicholasbishop deleted the bishop-auto-release-2 branch November 12, 2023 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find a way to improve/automate the process of publishing new crate versions
2 participants