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

Add workflow to publish Cargo automatically #14202

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Publish Cargo to crates.io whenever a new tag is pushed. Tags are pushed by
# the Rust release process (https://github.com/rust-lang/promote-release),
# which will cause this workflow to run.
Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

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

I believe I am allowed to manually create tags. Would that also trigger this workflow and how should we prevent it?

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes you creating tags would trigger the workflow. I guess we could setup a ruleset only allowing promote-release to create tags in the repository, but I'm not sure if it's worth it.

In the other repositories we have auto-publish configured in (rust-lang/infra-team#117) we let everyone with write access to the repo publish releases. Also, having the Cargo team be able to issue new patch releases of Cargo if problems with the crates.io-published versions are discovered (like a wrong dependency) could reduce friction.

@Mark-Simulacrum do you have any concerns?

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, I think across all of our repositories we would require 2 people to approve release issuance. For most of the repositories we have that's hard though. (And 2 people is still somewhat weak in terms of mechanism).

Maybe we can at least restrict publication to just cargo team members? e.g., triagebot needs write access, but ideally would not be able to publish a release (at least trivially). If we gated it behind an environment with manual approval (similar to what we're planning to do for bors production deployments), that could be just the Cargo team. And I'd feel a little better about the approval being an intentional UI click rather than "just" git push ... with a typo that makes it a tag.

Copy link
Member Author

Choose a reason for hiding this comment

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

So you'd like to require the Cargo team's approval even during normal releases (i.e. when pushed by promote-release)?

Copy link
Member

Choose a reason for hiding this comment

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

No, not necessarily. I'm comfortable with automation making releases, that seems fine to do without approvals (though with if required is likely also ok). But manual publishes I think do need more than just write access.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created a repository rule to only allow promote-release to push tags to this repository.


name: Release
on:
push:
tags:
- "**"

# Prevent multiple releases from starting at the same time.
concurrency:
group: release

jobs:
crates-io:
name: Publish on crates.io
runs-on: ubuntu-latest
permissions:
contents: read

# Gain access to the crates.io publishing token.
environment:
name: release

steps:
- name: Checkout the source code
uses: actions/checkout@v4

- name: Publish Cargo to crates.io
run: ./publish.py
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
3 changes: 3 additions & 0 deletions publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from urllib.error import HTTPError


# Whenever you add a new crate to this list that does NOT start with "cargo-"
# you must reach out to the infra team to add the crate to the list of crates
# allowed to be published from the "cargo CI" crates.io token.
TO_PUBLISH = [
'credential/cargo-credential',
'credential/cargo-credential-libsecret',
Expand Down