Skip to content

Commit 916c5a4

Browse files
committed
Auto merge of #14202 - pietroalbini:pa-publish, r=weihanglo
Add workflow to publish Cargo automatically One of the last manual pieces of the Rust release process is publishing Cargo, and as it happens after the release itself it is often forgotten (I am often guilty of that). This PR aims to fully automate that. Nowadays tagging Cargo happens automatically, as the release process creates and pushes a signed tag for the release. So the only piece remaining is automatically executing the `publish.py` script. This PR adds a workflow triggered by the tag push to run `publish.py` with a [rust-lang-owner](https://crates.io/users/rust-lang-owner) scoped token. The secret is stored in the [`release` environment](https://github.com/rust-lang/cargo/settings/environments/3357627654/edit), which can only be used during tag pushes. cc `@Mark-Simulacrum`
2 parents 67a452b + a28baaf commit 916c5a4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Publish Cargo to crates.io whenever a new tag is pushed. Tags are pushed by
2+
# the Rust release process (https://github.com/rust-lang/promote-release),
3+
# which will cause this workflow to run.
4+
5+
name: Release
6+
on:
7+
push:
8+
tags:
9+
- "**"
10+
11+
# Prevent multiple releases from starting at the same time.
12+
concurrency:
13+
group: release
14+
15+
jobs:
16+
crates-io:
17+
name: Publish on crates.io
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
22+
# Gain access to the crates.io publishing token.
23+
environment:
24+
name: release
25+
26+
steps:
27+
- name: Checkout the source code
28+
uses: actions/checkout@v4
29+
30+
- name: Publish Cargo to crates.io
31+
run: ./publish.py
32+
env:
33+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

publish.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
from urllib.error import HTTPError
1616

1717

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

0 commit comments

Comments
 (0)