Skip to content

Commit

Permalink
Merge main-v0.13.2 into main (#981)
Browse files Browse the repository at this point in the history
* feat: add publish crates script (#893)

* feat: implement unpublished crates verification (#894)

* chore(ci): tune boostraping cache (#949)

* chore(infra): add bootstrap flow to the ci (#941)

* Merge remote-tracking branch 'origin/main-v0.13.2' into noa/merge-main-v0.13.2-into-main-1727176225

* No conflicts in main-v0.13.2 -> main merge, this commit is for any change needed to pass the CI.

Co-Authored-By: Nadin Jbara <93648739+nadin-Starkware@users.noreply.github.com>
Co-Authored-By: alon-dotan-starkware <alon.dotan@starkware.co>
  • Loading branch information
3 people committed Sep 24, 2024
1 parent dfabef0 commit e395a89
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runs:
using: "composite"
steps:
- name: Install rust.
uses: ./.github/actions/install_rust
5 changes: 5 additions & 0 deletions .github/actions/install_rust/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
name: Bootsrap rust installation
description: Setup rust environment and its components, also caching the build results.

runs:
using: "composite"
steps:
- uses: moonrepo/setup-rust@v1
with:
cache-base: main(-v[0-9].*)?
4 changes: 2 additions & 2 deletions .github/workflows/blockifier_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ jobs:
runs-on: starkware-ubuntu-20-04-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- run: cargo build -p blockifier
- run: cargo test -p blockifier

native-blockifier-artifacts-push:
runs-on: starkware-ubuntu-20-04-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- name: Build native blockifier
run: ./build_native_in_docker.sh scripts/build_native_blockifier.sh

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/blockifier_compiled_cairo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
runs-on: starkware-ubuntu-20-04-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap

# Setup pypy and link to the location expected by .cargo/config.toml.
- uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/blockifier_post-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: starkware-ubuntu-20-04-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- uses: Noelware/setup-protoc@1.1.0

# Setup pypy and link to the location expected by .cargo/config.toml.
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/committer_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ concurrency:

jobs:
run-regression-tests:
runs-on: starkware-ubuntu-latest-small
runs-on: starkware-ubuntu-latest-medium
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap

- id: auth
uses: "google-github-actions/auth@v2"
Expand All @@ -55,7 +55,7 @@ jobs:
- run: cargo test -p committer_cli --release -- --include-ignored test_regression

benchmarking:
runs-on: starkware-ubuntu-latest-small
runs-on: starkware-ubuntu-latest-medium
if: ${{ github.event_name == 'pull_request' }}
steps:
# Checkout the base branch to get the old code.
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
runs-on: starkware-ubuntu-20-04-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap

# Commit hash on pull request event would be the head commit of the branch.
- name: Get commit hash prefix for PR update
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV

# Install rust components.
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap

# Run tests.
- name: "Run rustfmt and clippy"
Expand All @@ -88,10 +88,10 @@ jobs:


run-workspace-tests:
runs-on: starkware-ubuntu-latest-small
runs-on: starkware-ubuntu-latest-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- run: cargo test -p workspace_tests

run-tests:
Expand All @@ -101,7 +101,7 @@ jobs:
with:
# Fetch the entire history.
fetch-depth: 0
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- uses: Noelware/setup-protoc@1.1.0

# Setup pypy and link to the location expected by .cargo/config.toml.
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
with:
# Fetch the entire history.
fetch-depth: 0
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- name: Set-Up
run: |
sudo apt-get update
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/papyrus_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
runs-on: starkware-ubuntu-latest-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- uses: Noelware/setup-protoc@1.1.0
with:
version: ${{env.PROTOC_VERSION}}
Expand All @@ -64,7 +64,7 @@ jobs:
runs-on: starkware-ubuntu-latest-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- uses: Noelware/setup-protoc@1.1.0
with:
version: ${{env.PROTOC_VERSION}}
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
runs-on: starkware-ubuntu-latest-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- uses: Noelware/setup-protoc@1.1.0
with:
version: ${{env.PROTOC_VERSION}}
Expand All @@ -116,7 +116,7 @@ jobs:
runs-on: starkware-ubuntu-latest-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- uses: Noelware/setup-protoc@1.1.0

- run: |
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
filters: |
target_directory:
- 'crates/papyrus_storage/src/db/**'
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
# repeat this job 32 times. this is a random test for part of the code that may cause a corrupted database.
- run: for run in {1..32}; do cargo test -r -p papyrus_storage -- --include-ignored common_prefix_compare_with_simple_table_random; done
if: steps.changes.outputs.target_directory == 'true'
2 changes: 1 addition & 1 deletion .github/workflows/papyrus_nightly-tests-call.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- run: sudo apt update; sudo apt -y install libclang-dev
# Install libclang-dev that is not a part of the ubuntu vm in github actions.
if: runner.os == 'Linux'
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/papyrus_nightly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
GW-integration-test-ubuntu:
uses: ./.github/workflows/papyrus_nightly-tests-call.yml
with:
os: starkware-ubuntu-latest-small
os: starkware-ubuntu-latest-medium
secrets:
INTEGRATION_TESTNET_NODE_URL: ${{ secrets.INTEGRATION_TESTNET_NODE_URL }}
INTEGRATION_TESTNET_SENDER_PRIVATE_KEY: ${{ secrets.INTEGRATION_TESTNET_SENDER_PRIVATE_KEY }}
Expand All @@ -37,7 +37,7 @@ jobs:
if: github.event.schedule == '30 0 * * *'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap

- run: mkdir data

Expand All @@ -56,7 +56,7 @@ jobs:
if: github.event.schedule == '30 0 * * *'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- run: npm install -g ganache@7.4.3

- run: brew install protobuf@$PROTOC_VERSION
Expand All @@ -71,15 +71,15 @@ jobs:
if: github.event.schedule == '30 0 * * *'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- run: cargo build -r -p papyrus_load_test

integration-test:
runs-on: macos-latest
if: github.event.schedule == '30 0 * * *'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- run: >
cargo test -r
--test latency_histogram
Expand All @@ -91,8 +91,8 @@ jobs:
# TODO(dvir): make this run only if the path 'crates/papyrus_storage/src/db/**' (same path as in the CI) was changed on the
# last day and increase the number of repetitions.
random-table-test:
runs-on: starkware-ubuntu-latest-small
runs-on: starkware-ubuntu-latest-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- run: for run in {1..100}; do cargo test -r -p papyrus_storage -- --include-ignored common_prefix_compare_with_simple_table_random; done
2 changes: 1 addition & 1 deletion .github/workflows/verify-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install_rust
- uses: ./.github/actions/bootstrap
- name: Update Dependencies
run: cargo update --verbose
- name: Build
Expand Down
115 changes: 115 additions & 0 deletions scripts/publish_crates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import argparse
import subprocess
import sys
from typing import List, Tuple
import toml
import json
import asyncio


async def crate_version_exists(crate_name: str, version: str) -> bool:

response = subprocess.run(
["curl", "-s", f"https://crates.io/api/v1/crates/{crate_name}"],
capture_output=True,
text=True,
)

crate_metadata = json.loads(response.stdout)
already_published = version in [v["num"] for v in crate_metadata["versions"]]
print(
f"Crate {crate_name} version {version} "
f"{'exists' if already_published else 'does not exist'} on crates.io"
)
return already_published


def get_workspace_version() -> str:
try:
cargo_data = toml.load("Cargo.toml")

return cargo_data["workspace"]["package"]["version"]
except (KeyError, TypeError):
raise ValueError("Version key not found in Cargo.toml")


async def verify_unpublished(crates: List[str]):
"""
Asserts that none of the crates in the set have been published.
"""

version = get_workspace_version()

tasks = [crate_version_exists(crate_name=crate, version=version) for crate in crates]
results = await asyncio.gather(*tasks)

already_published = [crate for crate, unpublished in zip(crates, results) if unpublished]

assert (
not already_published
), f"Crates {already_published} have already been published with {version=}."


def get_package_and_dependencies_in_order(crate: str) -> List[str]:
"""
Returns a list of all local (member) crates that the input crate depends on, in topological
order. I.e, if crate A depends on crate B, then B will appear before A in the list.
The output list also includes the input crate (last element).
"""
# We use the `depth` prefix to easily sort the dependencies in topological order: higher depth
# means the crate is depended on by the crate at the lower depth.
prefixed_tree = (
subprocess.check_output(["cargo", "tree", "-p", crate, "--prefix", "depth"])
.decode()
.splitlines()
)
# Clean up the lines to only keep the *local* crate names with their depth prefix.
# Skip all non-local crates ('(/home' should appear in lines describing local crates).
prefixed_local_crates = [line.split()[0].strip() for line in prefixed_tree if "(/home" in line]

# Reverse order to iterate in descending depth order.
ordered_dependencies = []
for dependency_with_depth in reversed(sorted(prefixed_local_crates)):
# Strip the leading depth number (package names do not start with integers).
dependency = dependency_with_depth.lstrip("0123456789")
# The same package may appear multiple times, and with different depths. Always keep the
# highest depth only.
if dependency not in ordered_dependencies:
ordered_dependencies.append(dependency)
return ordered_dependencies


async def publish_crate_and_dependencies(crate: str, dry_run: bool):
dependencies = get_package_and_dependencies_in_order(crate=crate)
assert crate == dependencies[-1], f"{crate} should be the last element of '{dependencies}'."

# Do not attempt to publish anything if even one of the dependencies is already published.
await verify_unpublished(crates=dependencies)

base_command_template = "cargo publish -p {crate}" + f"{' --dry-run' if dry_run else ''}"
# Publish order is important.
cmd = " && ".join(
[base_command_template.format(crate=dependency) for dependency in dependencies]
)

print(f"Publishing {crate} ({dry_run=}) and its dependencies: {dependencies}...")
print(cmd, flush=True)
subprocess.run(cmd, check=True, shell=True)
print(f"Done.")


async def main():
parser = argparse.ArgumentParser(
description="Publish a crate and it's dependencies in the local workspace."
)
parser.add_argument(
"--crate", type=str, help="Crate to publish (dependencies will also be published)."
)
parser.add_argument("--dry_run", required=False, action="store_true", help="Dry run.")
args = parser.parse_args()

await publish_crate_and_dependencies(crate=args.crate, dry_run=args.dry_run)


if __name__ == "__main__":
sys.exit(asyncio.run(main()))

0 comments on commit e395a89

Please sign in to comment.