diff --git a/.github/workflows/rust-publish-dry-run-v2.yml b/.github/workflows/rust-publish-dry-run-v2.yml new file mode 100644 index 0000000..2225973 --- /dev/null +++ b/.github/workflows/rust-publish-dry-run-v2.yml @@ -0,0 +1,91 @@ +name: Publish Dry Run v2 + +on: + workflow_call: + inputs: + crates: + description: 'Space separated list of crate names in the order to be published.' + required: true + type: string + runs-on: + required: false + default: 'ubuntu-latest' + type: string + target: + required: false + default: 'x86_64-unknown-linux-gnu' + type: string + cargo-hack-feature-options: + required: false + default: '--feature-powerset' + type: string + +jobs: + + publish-dry-run: + runs-on: ${{ inputs.runs-on }} + defaults: + run: + shell: bash + env: + CARGO_BUILD_TARGET: ${{ inputs.target }} + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc + steps: + - uses: actions/checkout@v3 + + - uses: stellar/actions/rust-cache@main + + - run: rustup update + - run: rustup target add ${{ inputs.target }} + - if: inputs.target == 'aarch64-unknown-linux-gnu' + run: sudo apt-get update && sudo apt-get -y install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - uses: stellar/binaries@v12 + with: + name: cargo-hack + version: 0.5.16 + + # Vendor all the dependencies into the vendor/ folder. Temporarily remove + # [patch.crates-io] entries in the workspace Cargo.toml that reference git + # repos. These will be removed when published. + - name: Vendor Dependencies + run: | + cp Cargo.toml Cargo.toml.bak + sed -r '/(git|rev) ?=/d' Cargo.toml.bak > Cargo.toml + cargo vendor --versioned-dirs + rm Cargo.toml + mv Cargo.toml.bak Cargo.toml + + # Package the crates that will be published. Verification is disabled + # because we aren't ready to verify yet. Add each crate that was packaged to + # the vendor/ directory. + - name: Package Crates ${{ inputs.crates }} + run: | + for name in ${{ inputs.crates }} + do + version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="'$name'") | .version') + cargo package \ + --no-verify \ + --package $name \ + --config "source.crates-io.replace-with = 'vendored-sources'" \ + --config "source.vendored-sources.directory = 'vendor'" + path="target/package/${name}-${version}.crate" + tar xvfz "$path" -C vendor/ + # Crates in the vendor directory require a checksum file, but it doesn't + # matter if it is empty. + echo '{"files":{}}' > vendor/$name-$version/.cargo-checksum.json + done + + # Rerun the package command but with verification enabled this time. Tell + # cargo to use the local vendor/ directory as the source for all packages. Run + # the package command on the full feature powerset so that all features of + # each crate are verified to compile. + - name: Verify Crates with ${{ inputs.cargo-hack-feature-options }} + run: > + cargo-hack hack + ${{ inputs.cargo-hack-feature-options }} + --ignore-private + --config "source.crates-io.replace-with = 'vendored-sources'" + --config "source.vendored-sources.directory = 'vendor'" + package + --target ${{ inputs.target }} diff --git a/.github/workflows/rust-publish-dry-run.yml b/.github/workflows/rust-publish-dry-run.yml index fdc4066..0047f85 100644 --- a/.github/workflows/rust-publish-dry-run.yml +++ b/.github/workflows/rust-publish-dry-run.yml @@ -1,3 +1,10 @@ +# WARNING: This publish dry run process will not work on repositories that have +# a crate containing bin targets that are dependent on other crates in the +# repository. Please use `rust-publish-dry-run-v2` for any repository containing +# binaries. +# +# For more details, see https://github.com/rust-lang/cargo/issues/11181. + name: Publish Dry Run on: diff --git a/README-rust-release.md b/README-rust-release.md index 4bab3cb..9c0dd0d 100644 --- a/README-rust-release.md +++ b/README-rust-release.md @@ -23,11 +23,13 @@ The following workflows support the release process: | Name | Description | | ---- | ----------- | | [rust-bump-version] | Updates the version in Rust crates to a input version. | -| [rust-publish-dry-run] | Run a package verification on all crates in a workspace in their published form. | +| [rust-publish-dry-run] | Run a package verification on all crates in a workspace in their published form that automatically figures out the crate dependencies and order to publish (works only for repos without a binary). | +| [rust-publish-dry-run-v2] | Run a package verification on all crates in a workspace in their published form that requires an explicit list of crates to publish (works with all repos). | | [rust-publish] | Publish all crates in a workspace. | [rust-bump-version]: ./rust-bump-version/workflow.yml [rust-publish-dry-run]: ./rust-publish-dry-run/workflow.yml +[rust-publish-dry-run-v2]: ./rust-publish-dry-run-v2/workflow.yml [rust-publish]: ./rust-publish/workflow.yml ## Release Types @@ -86,10 +88,11 @@ release. This will probably involve: released that the crates are dependent on. - Update any docs. -_CI will run the [rust-publish-dry-run] checks on `release/*` branches to verify -that when the crates are published their publish will succeed. This means you -might see errors on CI that didn't exist before. These errors need resolving. If -you see any errors you don't understand, ask in [#lang-rust]._ +_CI will run the [rust-publish-dry-run] or [rust-publish-dry-run-v2] checks on +`release/*` branches to verify that when the crates are published their publish +will succeed. This means you might see errors on CI that didn't exist before. +These errors need resolving. If you see any errors you don't understand, ask in +[#lang-rust]._ ## 3. Merge PR @@ -101,8 +104,8 @@ the `main` branch. ## 4. Create Release on GitHub -First check that the `publish-dry-run` CI jobs have succeeded for the commit to -be released. +First check that the `publish-dry-run` or `publish-dry-run-v2` CI jobs have +succeeded for the commit to be released. Draft a new release on GitHub for the repository by clicking on the relevant release link in the description of the PR from step 2. diff --git a/README.md b/README.md index fa46648..6b34840 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,8 @@ workflows. | Name | Type | Description | | ---- | ---- | ----------- | | [rust-bump-version] | Workflow | Updates the version in Rust crates to a input version. | -| [rust-publish-dry-run] | Workflow | Run a package verification on all crates in a workspace in their published form. | +| [rust-publish-dry-run] | Run a package verification on all crates in a workspace in their published form that automatically figures out the crate dependencies and order to publish (works only for repos without a binary). | +| [rust-publish-dry-run-v2] | Run a package verification on all crates in a workspace in their published form that requires an explicit list of crates to publish (works with all repos). | | [rust-publish] | Workflow | Publish all crates in a workspace. | ### Project Management @@ -64,6 +65,7 @@ workflows. [rust-set-rust-version]: ./.github/workflows/rust-set-rust-version.yml [rust-bump-version]: ./.github/workflows/rust-bump-version.yml [rust-publish-dry-run]: ./.github/workflows/rust-publish-dry-run.yml +[rust-publish-dry-run-v2]: ./.github/workflows/rust-publish-dry-run-v2.yml [rust-publish]: ./.github/workflows/rust-publish.yml [update-completed-sprint-on-issue-closed]: ./.github/workflows/update-completed-sprint-on-issue-closed.yml diff --git a/rust-publish-dry-run-v2/workflow.yml b/rust-publish-dry-run-v2/workflow.yml new file mode 120000 index 0000000..a1d636d --- /dev/null +++ b/rust-publish-dry-run-v2/workflow.yml @@ -0,0 +1 @@ +../.github/workflows/rust-publish-dry-run-v2.yml \ No newline at end of file