Skip to content

Add CI workflow to publish backtrace after a push to main - #165802

Open
Kobzol wants to merge 8 commits into
rust-lang:mainfrom
Kobzol:publish-crates
Open

Kobzol wants to merge 8 commits into
rust-lang:mainfrom
Kobzol:publish-crates

Conversation

@Kobzol

@Kobzol Kobzol commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

View all comments

This PR implements crate publishing, which is required for rust-lang/backtrace-rs#778, and would be useful also for other use-cases in the future.
To keep things simple, I reused the existing post-merge workflow, and implemented the publishing in bash.

To make this work, we will also need to make changes in team: rust-lang/team#2941

I think that we could start by moving the publishing to rust-lang/rust, while still keeping the submodule, and test whether the publishing works as expected. Then we can get rid of the submodule and inline backtrace into rust-lang/rust.

CC @workingjubilee

I used a chatbot to generate the if condition line in bash (lol), and the cargo metadata command.

r? jieyouxu

@rustbot rustbot added A-CI Area: Our Github Actions CI S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Nov 11, 2026
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
@Kobzol

Kobzol commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Set the environment variables and updated the message.

Comment thread .github/workflows/post-merge.yml Outdated

gh pr comment ${HEAD_PR} -F output.log
else
echo "Nothing was published. Either there is no version update or some error has occurred."

@marcoieni marcoieni Nov 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If errors occur, the CI workflow is green. Will anyone notice and fix the issue?

My preference would be to catch these errors and fail the workflow, but I leave the choice to the author and the reviewer of this PR the final saying. 👍

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps it's worth doing cargo publish --dry-run as part of PR CI? That probably catches the most likely failures, other than transients.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does that do something more interesting other than just building the crate (which we should do as a part of our normal CI)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't quote me on this but I believe it packages a .crate and attempts to build from that, which catches things like incorrect include/exclude in the manifest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we comment on the PR if the publish failed for a reason other than whatever the "already published" message is?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't quote me on this but I believe it packages a .crate and attempts to build from that, which catches things like incorrect include/exclude in the manifest

AFAIK this sounds about right (https://doc.rust-lang.org/cargo/commands/cargo-publish.html#publish-options is a bit light on specifics). In particular it'd check Cargo.toml manifest. (Also use cargo published --locked --dry-run.)

We might want to also cargo package --locked --list to list all the files that goes to the final published artifact eventually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My preference would be to catch these errors and fail the workflow

I share this sentiment, IMO we should fail hard here.

@workingjubilee workingjubilee self-assigned this Nov 11, 2026
@workingjubilee

Copy link
Copy Markdown
Member

Making sure I review this soonish, probably still want our friendly local proto for the actual CI code.

@workingjubilee

Copy link
Copy Markdown
Member

I used a chatbot to generate the if condition line in bash (lol), and the cargo metadata command.

asked the things that produce inscrutable code for inscrutable code. fair play.

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some things

(Disclaimer: reviewed myself first, then also reviewed again with an LLM because GHA + bash is a recipe for hard-to-notice bugs 😓)

View changes since this review

Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Outdated

gh pr comment ${HEAD_PR} -F output.log
else
echo "Nothing was published. Either there is no version update or some error has occurred."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My preference would be to catch these errors and fail the workflow

I share this sentiment, IMO we should fail hard here.

Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
@Kobzol

Kobzol commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

I'm not sure how to reliably detect whether the publish failed because the version is already published, or because of something else. Both seems to return exit code 101.

@Kobzol

Kobzol commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

I guess that we could either:

  1. Check whether the version exists on crates.io
  2. Parse the stderr of Cargo if it fails, and pattern match an error that says the version already exists
  3. Do --dry-run, and if that succeeds, but the follow-up upload fails, then treat that as a duplicate version. But that could still skip and not report invalid uploads that didn't happen.

@jieyouxu

Copy link
Copy Markdown
Member

I guess that we could either:

  1. Check whether the version exists on crates.io
  2. Parse the stderr of Cargo if it fails, and pattern match an error that says the version already exists
  3. Do --dry-run, and if that succeeds, but the follow-up upload fails, then treat that as a duplicate version. But that could still skip and not report invalid uploads that didn't happen.

Hm... I feel like (1) might be worth trying. (2) is essentially fragile to unstable cargo wording, (3) seems to swallow the errors we care about anyway...

@Kobzol

Kobzol commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Ok, added the check.

@workingjubilee

Copy link
Copy Markdown
Member

In particular my desire would be

"I would prefer my PR is not automatically closed by GH's process if it has not actually gone off and published the crate."

Even if that means something wildly unintuitive! I would be fine if I have to manually check and confirm that an "error" in the workflow is Actually Success, then close my own PR. I'm good with that.

It seems we're trying to do something more clever than that, which is fine as long as the item doesn't leave "my desk" (open PRs) before it Actually Succeeds.

@workingjubilee

Copy link
Copy Markdown
Member

I could make the adjustment of checking "already-merged" PRs more and more often than I already do, but I don't want to increase the neuroticism of my interactions with GitHub, for everyone's sake.

@workingjubilee workingjubilee left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

honestly my eyes glazed over a bit reading "bash-in-yaml"... I actually consider myself bash-proficient but for some reason this embedding just throws me, is it really just the lack of syntax highlighting or something...? ...but to the extent I understand this it seems good.

View changes since this review

Comment thread .github/workflows/post-merge.yml Outdated
Comment on lines +107 to +112
echo "backtrace \`${VERSION}\` could not be published to crates.io" > comment.txt
printf "<details>\n<summary>Cargo publish log</summary>\n\n" >> comment.txt
printf '```\n' >> comment.txt
cat "${RUNNER_TEMP}/cargo-log.txt" >> comment.txt
printf '\n```\n' >> comment.txt
printf "</details>\n\n" >> comment.txt

@workingjubilee workingjubilee Nov 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

me, to me: "could this be replaced by a heredoc?"
me, to me: "would that actually make it more legible?"
me, to me: "uhmmm... lol?"

View changes since the review

@Kobzol

Kobzol commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

We could move the publish from the post-merge workflow to the main CI workflow, near the publish toolstate step. Of course the danger there is that if publishing fails (even spuriously), it will cancel the whole bors merge.

@jieyouxu

Copy link
Copy Markdown
Member

Hm. Technically we could say, if stdarch needs publishing it should rollup=never so if it fails main CI it's fine?

@Kobzol

Kobzol commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

I don't follow what would be the difference between the thing being rolled up or not 🤔 "it's fine", as in, at least it won't cancel the merge of other PRs?

@jieyouxu

jieyouxu commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Yeah. But probably doesn't matter though, was just thinking.

Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved
Comment thread .github/workflows/post-merge.yml Resolved

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The step itself looks good to me, thanks. I don't really have a preference for during-merge vs post-merge, as long as it works for @workingjubilee.

View changes since this review

@tgross35

tgross35 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

because GHA + bash is a recipe for hard-to-notice bugs

honestly my eyes glazed over a bit reading "bash-in-yaml"... I actually consider myself bash-proficient but for some reason this embedding just throws me, is it really just the lack of syntax highlighting or something...? ...but to the extent I understand this it seems good.

Any reason this couldn't be a separate script, so it gets shellchecked? As it now uses env. Plus being easier to understand with highlighting.

Do wish there was a way to easily shellcheck in yaml.

@jieyouxu

Copy link
Copy Markdown
Member

Hm true, it could be in its own script.

@Kobzol

Kobzol commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

I was actually thinking of moving it to citool in Rust, but some parts of it are still easier in bash (the gh invocations). We could just invoke gh from Rust though 🤷

@jieyouxu

Copy link
Copy Markdown
Member

That'd work for me 🤷

@Kobzol

Kobzol commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

After taking another look at it, I don't think it's worth it to rewrite the two lines of bash into Rust atm.

@workingjubilee

Copy link
Copy Markdown
Member

I agree with @tgross35. Would it be okay to extract the bash into its own script without going RIIR-crazy? It's 45 lines, no?

fwiw if I have to make an adjustment then I'm ultimately okay with making that adjustment. I'm expressing a staged preference not an inviolate one. I realize that may not have been clear.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. A-testsuite Area: The testsuite used to check the correctness of rustc and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 17, 2026
@Kobzol

Kobzol commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Makes sense, done!

@rust-log-analyzer

This comment has been minimized.

@workingjubilee workingjubilee left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Typos that are barely relevant.

My current mood is that we ship this, try it out for a backtrace release, and then I will have feedback on possible adjustments from practical experience.

View changes since this review

Comment thread src/ci/publish_backtrace.sh Resolved
Comment thread src/ci/publish_backtrace.sh Resolved
Co-authored-by: Jubilee <workingjubilee@gmail.com>
@Kobzol

Kobzol commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Yeah, I would be very surprised if this works on the first try. I'd suggest merging this, then merging rust-lang/team#2941, and then trying to do a release from this PR (will need a backtrace submodule sync).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants