Skip to content

Commit

Permalink
chore(CI): Refactor rust CI workflows into a hierarchy (#1616)
Browse files Browse the repository at this point in the history
* chore(CI): Refactor rust CI workflows into a hierarchy

* update name

* update old paths-filter action

* tweaks

* remove rust cache from license check

* update external too

* add hierarchy top level workflow and gate other big workflows behind dprint

* Add more to the hierarchy

* parallelize more

* more reworking

* remove excess diff job

* cleanup

* more

* move clippy back

* move license check up

* simplify call

* Update .github/workflows/_e2e.yml

Co-authored-by: Thoralf-M <[email protected]>

* use diff for license check

* add doc filter and update filters for workflows

---------

Co-authored-by: Mario Sarcevic <[email protected]>
Co-authored-by: Thibault Martinez <[email protected]>
Co-authored-by: Thoralf-M <[email protected]>
  • Loading branch information
4 people authored Aug 14, 2024
1 parent 8007a24 commit 9bcaeb1
Show file tree
Hide file tree
Showing 19 changed files with 408 additions and 450 deletions.
16 changes: 12 additions & 4 deletions .github/actions/diffs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- name: Detect Changes
uses: dorny/paths-filter@v2.10.2
uses: dorny/paths-filter@v3
id: diff
with:
filters: |
Expand All @@ -32,13 +32,20 @@ runs:
- "external-crates/**"
- "narwhal/**"
- "iota-execution/**"
- ".github/workflows/hierarchy.yml"
- ".github/workflows/codecov.yml"
- ".github/workflows/rust.yml"
- ".github/workflows/external.yml"
- ".github/workflows/_rust.yml"
- ".github/workflows/_rust_tests.yml"
- ".github/workflows/_rust_lints.yml"
- ".github/workflows/_external_rust_tests.yml"
- ".github/workflows/_external_rust_lints.yml"
- ".github/workflows/_mysticeti_tests.yml"
isDoc:
- "docs/content/**"
- "docs/site/**"
- "*.mdx"
- ".github/workflows/docs.yml"
- ".github/workflows/_docs_lint.yml"
- ".github/workflows/_docusaurus.yml"
isOldDoc:
- "doc/**"
- "*.md"
Expand All @@ -50,6 +57,7 @@ runs:
- "Cargo.toml"
- "examples/**"
- "iota_programmability/**"
- ".github/workflows/_move_tests.yml"
isReleaseNotesEligible:
- "consensus/**"
- "crates/**"
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/_docs_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Docs spellcheck and linting

on: workflow_call

jobs:
spelling:
name: Lint documentation
runs-on: [self-hosted]

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- name: Spell Check Docs
uses: crate-ci/[email protected]
with:
files: ./docs/content
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
name: Docusaurus Build

on:
push:
branches: [develop]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/develop' }}
on: workflow_call

jobs:
build:
Expand Down
46 changes: 22 additions & 24 deletions .github/workflows/e2e.yml → .github/workflows/_e2e.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
name: TS End-to-end Tests

on:
pull_request:
workflow_call:
inputs:
isRust:
type: boolean
required: true
isExplorer:
type: boolean
required: true
isTypescriptSDK:
type: boolean
required: true
isWallet:
type: boolean
required: true
isGraphQlTransport:
type: boolean
required: true

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
diff:
runs-on: self-hosted
outputs:
isWallet: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), 'iota-wallet')) }}
isExplorer: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), 'iota-explorer')) }}
isTypescriptSDK: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), '@iota/iota-sdk')) }}
isGraphQlTransport: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), '@iota/graphql-transport')) }}
isRust: ${{ steps.diff.outputs.isRust }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- name: Detect Changes (turbo)
uses: "./.github/actions/turbo-diffs"
id: turbo
- name: Detect Changes (diff)
uses: "./.github/actions/diffs"
id: diff

# Run e2e test against localnet built on the develop branch
localnet:
name: Localnet
needs: diff
if: needs.diff.outputs.isExplorer == 'true' || needs.diff.outputs.isTypescriptSDK == 'true' || needs.diff.outputs.isWallet == 'true' || needs.diff.outputs.isRust == 'true'
if: inputs.isExplorer || inputs.isTypescriptSDK || inputs.isWallet || inputs.isRust
runs-on: self-hosted
services:
postgres:
Expand Down Expand Up @@ -66,20 +64,20 @@ jobs:
echo "E2E_RUN_LOCAL_NET_CMD=(RUST_LOG=info RUST_BACKTRACE=1 $(echo $PWD/target/debug/iota-test-validator) --with-indexer --pg-port 5432 --pg-db-name iota_indexer_v2 --graphql-host 127.0.0.1 --graphql-port 9125)" >> $GITHUB_ENV
- name: Run TS SDK e2e tests
if: ${{ needs.diff.outputs.isTypescriptSDK == 'true' || needs.diff.outputs.isRust == 'true'}}
if: inputs.isTypescriptSDK || inputs.isRust
run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/iota-sdk test:e2e'

- name: Run RPC/GraphQL compatibility e2e tests
if: ${{ needs.diff.outputs.isGraphQlTransport == 'true' || needs.diff.outputs.isRust == 'true'}}
if: inputs.isGraphQlTransport || inputs.isRust
run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/graphql-transport test:e2e'

- name: Build explorer
if: ${{ needs.diff.outputs.isTypescriptSDK == 'true' || needs.diff.outputs.isExplorer == 'true' || needs.diff.outputs.isRust == 'true'}}
if: ${{ inputs.isTypescriptSDK || inputs.isExplorer || inputs.isRust}}
run: pnpm turbo --filter=iota-explorer build

- name: Run Explorer e2e tests
# need to run Explorer e2e when its upstream(TS SDK and Rust) or itself is changed
if: ${{ needs.diff.outputs.isTypescriptSDK == 'true' || needs.diff.outputs.isExplorer == 'true' || needs.diff.outputs.isRust == 'true'}}
if: ${{ inputs.isTypescriptSDK || inputs.isExplorer || inputs.isRust}}
run: pnpm --filter iota-explorer playwright test
- uses: actions/upload-artifact@v3
if: always()
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/_execution_cut.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Execution cut

on: workflow_call

jobs:
execution-cut:
name: cutting a new execution layer
runs-on: [self-hosted]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- name: Install cargo-hakari, and cache the binary
uses: baptiste0928/cargo-install@1cd874a5478fdca35d868ccc74640c5aabbb8f1b # [email protected]
with:
crate: cargo-hakari
locked: true
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- name: Make cut
run: ./scripts/execution_layer.py cut for_ci_test
- name: Check execution builds
run: cargo build -p iota-execution
35 changes: 35 additions & 0 deletions .github/workflows/_external_rust_lints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Rust lints

on: workflow_call

jobs:
rustfmt:
runs-on: [self-hosted]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- name: Install latest nightly
run: rustup toolchain install nightly --component rustfmt --allow-downgrade
- name: Check Rust formatting
run: |
cargo +nightly ci-fmt-external
cargo-deny:
name: cargo-deny (advisories, licenses, bans, ...)
runs-on: [self-hosted]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- uses: EmbarkStudios/cargo-deny-action@v1

clippy:
needs:
- rustfmt
- cargo-deny
runs-on: [self-hosted]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- run: rustup component add clippy

# See '.cargo/config' for list of enabled/disabled clippy lints
- name: cargo move-clippy
run: |
cargo ci-clippy-external
44 changes: 44 additions & 0 deletions .github/workflows/_external_rust_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Rust tests

on: workflow_call

jobs:
changes:
runs-on: [self-hosted]
outputs:
components: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dorny/paths-filter@v3
id: filter
with:
list-files: "json"
filters: .github/external-crates-filters.yml

test:
name: Test ${{ matrix.components }}
needs: changes
if: needs.changes.outputs.components != '[]'
env:
# Tests written with #[sim_test] are often flaky if run as #[tokio::test] - this var
# causes #[sim_test] to only run under the deterministic `simtest` job, and not the
# non-deterministic `test` job.
IOTA_SKIP_SIMTESTS: 1
strategy:
matrix:
components: ${{ fromJson(needs.changes.outputs.components) }}
fail-fast: false
runs-on: [self-hosted]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: taiki-e/install-action@nextest
- name: Install python dependencies
run: pip install pyopenssl --upgrade
- name: cargo test
run: >
cargo nextest run
--config-file .config/nextest.toml
--manifest-path external-crates/move/Cargo.toml
-E '!test(prove) and !test(run_all::simple_build_with_docs/args.txt) and !test(run_test::nested_deps_bad_parent/Move.toml) and rdeps(${{matrix.components}})'
-p ${{matrix.components}}
--profile ci
17 changes: 17 additions & 0 deletions .github/workflows/_move_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Move tests

on: workflow_call

jobs:
# This job ensures that Move unit tests are run if there are changes
# to Move code but not Rust code (If there are Rust changes, they
# will be run as part of a larger test suite).
move-test:
timeout-minutes: 10
runs-on: [self-hosted]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- uses: taiki-e/install-action@nextest
- name: Run move tests
run: |
cargo nextest run -p iota-framework-tests -- unit_tests::
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
name: Mysticeti tests

on:
push:
branches:
- "develop"
- "devnet"
- "testnet"
- "mainnet"
- "releases/iota-*-release"
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_call:
workflow_dispatch:
inputs:
iota_repo_ref:
Expand Down Expand Up @@ -88,23 +80,7 @@ jobs:
- name: cargo test
run: cargo nextest run --profile ci -E 'rdeps(${{matrix.components}})' -p ${{matrix.components}}

diff:
runs-on: [self-hosted]
outputs:
isRust: ${{ steps.diff.outputs.isRust }}
isMove: ${{ steps.diff.outputs.isMove }}
isReleaseNotesEligible: ${{ steps.diff.outputs.isReleaseNotesEligible }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
with:
ref: ${{ github.event.inputs.iota_repo_ref || github.ref }}
- name: Detect Changes
uses: "./.github/actions/diffs"
id: diff

test-extra:
needs: diff
if: needs.diff.outputs.isRust == 'true'
timeout-minutes: 45
env:
# Tests written with #[sim_test] are often flaky if run as #[tokio::test] - this var
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/_rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Rust crates

on: workflow_call

env:
CARGO_TERM_COLOR: always
# Disable incremental compilation.
#
# Incremental compilation is useful as part of an edit-build-test-edit cycle,
# as it lets the compiler avoid recompiling code that hasn't changed. However,
# on CI, we're not making small edits; we're almost always building the entire
# project from scratch. Thus, incremental compilation on CI actually
# introduces *additional* overhead to support making future builds
# faster...but no future builds will ever occur in any given CI environment.
#
# See https://matklad.github.io/2021/09/04/fast-rust-builds.html#ci-workflow
# for details.
CARGO_INCREMENTAL: 0
# Allow more retries for network requests in cargo (downloading crates) and
# rustup (installing toolchains). This should help to reduce flaky CI failures
# from transient network timeouts or other issues.
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
RUSTDOCFLAGS: -D warnings

jobs:
rust-lints:
uses: ./.github/workflows/_rust_lints.yml

external-lints:
uses: ./.github/workflows/_external_rust_lints.yml

rust-tests:
needs:
- rust-lints
- external-lints
uses: ./.github/workflows/_rust_tests.yml

external-tests:
needs:
- rust-lints
- external-lints
uses: ./.github/workflows/_external_rust_tests.yml

mysticeti-tests:
needs:
- rust-lints
- external-lints
uses: ./.github/workflows/_mysticeti_tests.yml

execution-cut:
needs:
- rust-tests
- external-tests
- mysticeti-tests
uses: ./.github/workflows/_execution_cut.yml
Loading

0 comments on commit 9bcaeb1

Please sign in to comment.