Skip to content

Commit 677cb00

Browse files
authored
[41.0.0] Migrate this workspace to using trusted publishing (#12277)
* Migrate this workspace to using trusted publishing (#12257) 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. * Update cargo-vet with trusted publishing support (#12285) This updates the `cargo vet` used in CI to include support for trusted publishing. This is necessary now that the latest version of Wasmtime (40.0.1) is published with trusted publishing. I'm not entirely sure why this is necessary, but it's going to be inevitable in the future anyway as we transition to trusted publishing. The `cargo vet` tool is now installed from git and new wildcard audits for all wasmtime, wasm-tools, and wit-bindgen crates are added for the appropriate trusted-publisher. Maintainers will need to install cargo-vet from git as well, but unfortunately after the publish of 40.0.1 yesterday I don't think we have an option as otherwise CI is broken.
1 parent 83ff6b8 commit 677cb00

File tree

5 files changed

+636
-55
lines changed

5 files changed

+636
-55
lines changed

.github/actions/install-cargo-vet/action.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
version:
66
description: 'Version to install'
77
required: false
8-
default: '0.10.0'
8+
default: '8b40d6351ed9758a73a4a0bf2c930c17a35c5e15'
99

1010
runs:
1111
using: composite
@@ -16,5 +16,11 @@ runs:
1616
key: cargo-vet-bin-${{ inputs.version }}
1717
- run: echo "${{ runner.tool_cache }}/cargo-vet/bin" >> $GITHUB_PATH
1818
shell: bash
19-
- run: cargo install --root ${{ runner.tool_cache }}/cargo-vet --version ${{ inputs.version }} cargo-vet --locked
19+
- run: |
20+
cargo install \
21+
--root ${{ runner.tool_cache }}/cargo-vet \
22+
--rev ${{ inputs.version }} \
23+
--git https://github.com/mozilla/cargo-vet \
24+
--locked \
25+
cargo-vet
2026
shell: bash

.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 & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const CRATES_TO_PUBLISH: &[&str] = &[
3131
"cranelift-bforest",
3232
"cranelift-codegen-shared",
3333
"cranelift-codegen-meta",
34-
"cranelift-egraph",
3534
"cranelift-control",
3635
"cranelift-codegen",
3736
"cranelift-reader",
@@ -52,8 +51,6 @@ const CRATES_TO_PUBLISH: &[&str] = &[
5251
// wiggle
5352
"wiggle-generate",
5453
"wiggle-macro",
55-
// winch
56-
"winch",
5754
// wasmtime
5855
"wasmtime-internal-error",
5956
"wasmtime-internal-versioned-export-macros",
@@ -472,34 +469,6 @@ fn publish(krate: &Crate) -> bool {
472469
return false;
473470
}
474471

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

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

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

0 commit comments

Comments
 (0)