Skip to content

Commit 8c97ae8

Browse files
authored
Migrate this workspace to using trusted publishing (#12257) (#12280)
This commit updates CI config and such to ensure that we're compatible with crates.io-based trusted publishing. Eventually we'll want the restriction that only `wasmtime-publish` is the user on all of our crates, but for now this needs to land and get backported before that's done. Changes here are: * The `publish-to-cratesio.yml` workflow now uses `rust-lang/crates-io-auth-action@v1` to get a crates.io-based token. The in-repository secret is no longer used. * The `publish-to-cratesio.yml` workflow has a new github "Environment" it runs in named `publish` * The publish script no longer adds the `github:bytecodealliance:wasmtime-publish` user to crates. * The publish script now verifies that the `wasmtime-publish` github users is on all crates. * Eventually the publish script will verify that it's the only user on all the crates, but that's left for a future PR. External changes are: * A new `publish` "Environment" was added to this repository. * All crates are configured on crates.io to have a trusted publishing workflow for this repository. * All crates now require being published through a trusted publishing workflow. My plan is to backport this to the 40.0.0 branch, run a point release, fix anything that comes up, and then backport this to all supported branches of Wasmtime.
1 parent 17d037f commit 8c97ae8

File tree

2 files changed

+41
-47
lines changed

2 files changed

+41
-47
lines changed

.github/workflows/publish-to-cratesio.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,32 @@ on:
99
tags:
1010
- 'v*'
1111

12+
permissions:
13+
id-token: write
14+
1215
jobs:
1316
publish:
1417
if: github.repository == 'bytecodealliance/wasmtime'
1518
runs-on: ubuntu-latest
19+
environment: publish
1620
steps:
1721
- uses: actions/checkout@v4
1822
with:
1923
submodules: true
2024
- run: rustup update stable && rustup default stable
25+
- uses: rust-lang/crates-io-auth-action@v1
26+
id: auth
2127
- run: |
2228
rustc scripts/publish.rs
2329
./publish publish
2430
env:
25-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
26-
31+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
32+
2733
# Manifest and publish the wasi-preview1-component-adapter-provider
2834
- uses: ./.github/actions/fetch-run-id
2935
- uses: ./.github/actions/build-adapter-provider
3036
with:
3137
run-id: ${{ env.COMMIT_RUN_ID }}
3238
- run: cargo publish -p wasi-preview1-component-adapter-provider --allow-dirty
3339
env:
34-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
40+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

scripts/publish.rs

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -471,34 +471,6 @@ fn publish(krate: &Crate) -> bool {
471471
return false;
472472
}
473473

474-
// After we've published then make sure that the `wasmtime-publish` group is
475-
// added to this crate for future publications. If it's already present
476-
// though we can skip the `cargo owner` modification.
477-
let Some(output) = curl(&format!(
478-
"https://crates.io/api/v1/crates/{}/owners",
479-
krate.name
480-
)) else {
481-
return false;
482-
};
483-
if output.contains("wasmtime-publish") {
484-
println!(
485-
"wasmtime-publish already listed as an owner of {}",
486-
krate.name
487-
);
488-
return true;
489-
}
490-
491-
// Note that the status is ignored here. This fails most of the time because
492-
// the owner is already set and present, so we only want to add this to
493-
// crates which haven't previously been published.
494-
run_cmd(
495-
Command::new("cargo")
496-
.arg("owner")
497-
.arg("-a")
498-
.arg("github:bytecodealliance:wasmtime-publish")
499-
.arg(&krate.name),
500-
);
501-
502474
true
503475
}
504476

@@ -613,26 +585,42 @@ fn verify(crates: &[Crate]) {
613585
fn verify_crates_io(krate: &Crate) {
614586
let name = &krate.name;
615587
let Some(owners) = curl(&format!("https://crates.io/api/v1/crates/{name}/owners")) else {
616-
panic!("failed to get owners for {name}", name = name);
588+
panic!(
589+
"
590+
failed to get owners for {name}
591+
592+
If this crate does not exist on crates.io yet please ping wasmtime maintainers
593+
to add the crate on crates.io as a small shim. When doing so please remind them
594+
that the trusted publishing workflow must be configured as well.
595+
",
596+
name = name,
597+
);
617598
};
618599

619-
let assert_owner = |owner: &str| {
620-
let owner_json = format!("\"{owner}\"");
621-
if !owners.contains(&owner_json) {
622-
panic!(
623-
"
624-
crate {name} is not owned by {owner}, please run:
600+
// This is the id of the `wasmtime-publish` user on crates.io
601+
if !owners.contains("\"id\":73222,") {
602+
panic!(
603+
"
604+
crate {name} is not owned by wasmtime-publish, please run:
625605
626-
cargo owner -a {owner} {name}
606+
cargo owner -a wasmtime-publish {name}
627607
",
628-
name = name
629-
);
630-
}
631-
};
608+
name = name,
609+
);
610+
}
611+
612+
// TODO: waiting for trusted publishing to be proven to work before
613+
// activating this.
614+
if false && owners.split("\"id\"").count() != 2 {
615+
panic!(
616+
"
617+
crate {name} is not exclusively owned by wasmtime-publish
632618
633-
// the wasmtime-publish github user
634-
assert_owner("wasmtime-publish");
635-
// the BA team which can publish crates
636-
assert_owner("github:bytecodealliance:wasmtime-publish");
619+
Please contact wasmtime maintainers to ensure that `wasmtime-publish` is the
620+
only listed owner of the crate.
621+
",
622+
name = name,
623+
);
624+
}
637625
}
638626
}

0 commit comments

Comments
 (0)