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 Publish Dry Run v2 #54

Merged
merged 17 commits into from
Jun 17, 2023
91 changes: 91 additions & 0 deletions .github/workflows/rust-publish-dry-run-v2.yml
Original file line number Diff line number Diff line change
@@ -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 }}
7 changes: 7 additions & 0 deletions .github/workflows/rust-publish-dry-run.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 10 additions & 7 deletions README-rust-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions rust-publish-dry-run-v2/workflow.yml