diff --git a/.config/nextest.toml b/.config/nextest.toml index c22751e91e..f7ca24a955 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -5,5 +5,7 @@ failure-output = "immediate-final" fail-fast = false # Show all tests in the CI output. status-level = "all" +# Test statuses at the end of the run. +final-status-level = "slow" # Retries the test n times, tests that succeed on a subsequent attempt will be marked as flaky retries = 10 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d3e4fcc5f..dc5d963bc6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,14 @@ on: - 'book/**' env: + RUST_LATEST_STABLE_VERSION: 1.65 CARGO_TERM_COLOR: always RUSTFLAGS: -D warnings RUST_BACKTRACE: 1 CARGO_INCREMENTAL: 0 + CARGO_FLAGS: --verbose --locked + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 15 + jobs: cancel: @@ -40,25 +44,29 @@ jobs: build_on_linux: name: Build Catalyst Core on Linux runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked steps: - name: Checkout code uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} + + - name: Cache rust + uses: Swatinem/rust-cache@v2 + with: + shared-key: "build_cache" + save-if: ${{ github.ref == 'refs/heads/main' }} - name: Install deps run: sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - name: Build on Linux - uses: actions-rs/toolchain@v1 - with: - toolchain: "1.65" - - run: cargo build + run: cargo build ${{env.CARGO_FLAGS}} build_on_windows: name: Build Catalyst Core on Windows @@ -89,7 +97,8 @@ jobs: reg add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f git config --system core.longpaths true - - uses: Swatinem/rust-cache@v2 + - name: Cache rust + uses: Swatinem/rust-cache@v2 with: workspaces: "C:\\${{ github.event.repository.name }}" @@ -108,10 +117,11 @@ jobs: run: | "PQ_LIB_DIR=${env:PROGRAMFILES}\PostgreSQL\14\lib" >> $env:GITHUB_ENV - - uses: actions-rs/toolchain@v1 + - name: Install rust + uses: actions-rs/toolchain@v1 with: - toolchain: "1.65" + toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - name: Build on Windows working-directory: "C:\\${{ github.event.repository.name }}" - run: cargo build --workspace + run: cargo build --workspace ${{env.CARGO_FLAGS}} diff --git a/.github/workflows/ci-tests-n-coverage.yml b/.github/workflows/ci-tests-n-coverage.yml index 78f4ecd486..3bdc53d7af 100644 --- a/.github/workflows/ci-tests-n-coverage.yml +++ b/.github/workflows/ci-tests-n-coverage.yml @@ -6,10 +6,14 @@ on: - cron: '5 0 * * *' env: + RUST_LATEST_STABLE_VERSION: 1.65 CARGO_TERM_COLOR: always RUSTFLAGS: -D warnings RUST_BACKTRACE: 1 CARGO_INCREMENTAL: 0 + CARGO_FLAGS: --verbose --locked + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 15 + concurrency: group: ${{ github.sha }} @@ -20,25 +24,37 @@ jobs: name: Unit Tests runs-on: ubuntu-latest needs: [integration-tests] - env: - CARGO_FLAGS: --verbose --locked + services: + postgres: + image: postgres:14 + env: + POSTGRES_PASSWORD: 123456 + options: + >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 steps: - name: Checkout code uses: actions/checkout@v3 - - uses: Swatinem/rust-cache@v2 - with: - shared-key: "cov" - save-if: "true" - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: "1.65" # it says it can read the rust-toolchain file, but it fails if we omit this + toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} # it says it can read the rust-toolchain file, but it fails if we omit this components: llvm-tools-preview - - name: Install cargo-nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin + - name: Cache rust + uses: Swatinem/rust-cache@v2 + with: + shared-key: "build_cache" + save-if: "false" + + - name: Install nextest + uses: taiki-e/install-action@nextest - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov @@ -48,6 +64,8 @@ jobs: sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - name: Run unit tests + env: + TEST_DB: postgres run: | cargo llvm-cov nextest --no-report --manifest-path ./src/catalyst-toolbox/catalyst-toolbox/Cargo.toml --profile ci cargo llvm-cov nextest --no-report --manifest-path ./src/catalyst-toolbox/snapshot-lib/Cargo.toml --profile ci @@ -82,6 +100,7 @@ jobs: cargo llvm-cov nextest --no-report --manifest-path ./src/jormungandr/jormungandr/Cargo.toml --profile ci cargo llvm-cov report --lcov --output-path ./lcov.info + - name: Upload code coverage to coveralls.io uses: coverallsapp/github-action@master with: @@ -91,25 +110,37 @@ jobs: integration-tests: name: Integration Tests runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked + services: + postgres: + image: postgres:14 + env: + POSTGRES_PASSWORD: postgres + options: + >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 steps: - name: Checkout code uses: actions/checkout@v3 - - uses: Swatinem/rust-cache@v2 - with: - shared-key: "cov" - save-if: "true" - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: "1.65" # it says it can read the rust-toolchain file, but it fails if we omit this + toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} # it says it can read the rust-toolchain file, but it fails if we omit this components: llvm-tools-preview - - name: Install cargo-nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin + - name: Cache rust + uses: Swatinem/rust-cache@v2 + with: + shared-key: "build_cache" + save-if: "false" + + - name: Install nextest + uses: taiki-e/install-action@nextest - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov @@ -119,6 +150,8 @@ jobs: sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - name: Run integration tests + env: + TEST_DATABASE_URL: postgres://postgres:postgres@localhost run: | source <(cargo llvm-cov show-env --export-prefix) cargo build -p jcli -p jormungandr -p explorer -p vit-servicing-station-cli -p vit-servicing-station-server diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index f7de137610..533da025af 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -25,10 +25,12 @@ env: RUSTFLAGS: -D warnings RUST_BACKTRACE: 1 CARGO_INCREMENTAL: 0 + CARGO_FLAGS: --verbose --locked + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 15 jobs: cancel: - name: 'Cancel Previous Runs' + name: Cancel previous runs runs-on: ubuntu-latest timeout-minutes: 3 steps: @@ -36,177 +38,190 @@ jobs: with: access_token: ${{ github.token }} - vit_servicing_station: - name: Vit Servicing Station Tests + build-test-dependencies: + name: Build test dependencies runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked steps: - name: Checkout code uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install Nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Install deps - run: - sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - - name: Run vit-ss tests + - name: Install rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - - run: | - cargo build -p vit-servicing-station-cli -p vit-servicing-station-server - cargo nextest run \ - -p vit-servicing-station-cli \ - -p vit-servicing-station-lib \ - -p vit-servicing-station-tests \ - -p vit-servicing-station-server \ - --profile ci - - catalyst_toolbox: - name: Catalyst Toolbox Tests - runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked - steps: - - name: Checkout code - uses: actions/checkout@v3 + + - name: Cache rust + uses: Swatinem/rust-cache@v2 with: - ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install Nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Install deps + shared-key: "test_cache" + save-if: ${{ github.ref == 'refs/heads/main' }} + + - name: Install dependencies run: sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - - name: Run catalyst-toolbox tests - uses: actions-rs/toolchain@v1 + - name: Build external dependencies + run: + cargo build -p vit-servicing-station-cli -p vit-servicing-station-server -p jcli -p jormungandr -p explorer + + - name: Save external dependencies + uses: actions/cache/save@v3 with: - toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - - run: cargo nextest run -p catalyst-toolbox -p snapshot-lib --profile ci + path: | + target/debug/vit-servicing-station-cli + target/debug/vit-servicing-station-server + target/debug/jcli + target/debug/jormungandr + target/debug/explorer + key: deps-${{ github.run_id }}-${{ github.run_attempt }} + - voting_tools: - name: Voting Tools Tests + build-tests-artifacts: + name: Build test artifacts runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked steps: - name: Checkout code uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install Nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Install deps - run: - sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - - name: Run voting-tools tests + - name: Install rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - - run: cargo nextest run -p voting_tools_rs --profile ci - chain-libs: - name: Chain Libs Tests - runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked - steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Cache rust + uses: Swatinem/rust-cache@v2 with: - ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install Nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Install deps + shared-key: "test_cache" + save-if: ${{ github.ref == 'refs/heads/main' }} + + - name: Install nextest + uses: taiki-e/install-action@nextest + + - name: Install dependencies run: sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - - name: Run chain-libs tests - uses: actions-rs/toolchain@v1 + - name: Build and archive tests + run: cargo nextest archive --archive-file nextest-archive.tar.zst + + - name: Save test archive + uses: actions/cache/save@v3 with: - toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - - run: cargo nextest run -p "chain-*" --profile ci + path: nextest-archive.tar.zst + key: nextest-archive-${{ github.run_id }}-${{ github.run_attempt }} - jormungandr: - name: Jormungandr Tests + catalyst-core-tests: + name: Catalyst Core tests runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked + needs: [build-tests-artifacts, build-test-dependencies] + services: + postgres: + image: postgres:14 + env: + POSTGRES_PASSWORD: 123456 + options: + >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + strategy: + matrix: + partition: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] steps: - name: Checkout code uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install Nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Install deps - run: - sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - - name: Run jormungandr tests + - name: Install rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - - run: cargo nextest run -p jormungandr --profile ci - jormungandr-integration: - name: Jormungandr Integration Tests - runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked - steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Cache rust + uses: Swatinem/rust-cache@v2 with: - ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install Nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Install deps + shared-key: "test_cache" + save-if: ${{ github.ref == 'refs/heads/main' }} + + - name: Restore test archive + id: archive-cache + uses: actions/cache/restore@v3 + with: + path: nextest-archive.tar.zst + key: nextest-archive-${{ github.run_id }}-${{ github.run_attempt }} + + - name: Restore external dependencies + id: deps-cache + uses: actions/cache/restore@v3 + with: + path: | + target/debug/vit-servicing-station-cli + target/debug/vit-servicing-station-server + target/debug/jcli + target/debug/jormungandr + target/debug/explorer + key: deps-${{ github.run_id }}-${{ github.run_attempt }} + + - name: Install nextest + uses: taiki-e/install-action@nextest + + - name: Install dependencies run: sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - - name: Run jormungandr-integration tests - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - - run: | - cargo build -p jcli -p jormungandr -p explorer - cargo nextest run -p jormungandr-integration-tests --profile ci + - name: Build external dependencies + if: steps.deps-cache.outputs.cache-hit != 'true' + run: + cargo build -p vit-servicing-station-cli -p vit-servicing-station-server -p jcli -p jormungandr -p explorer + + - name: Build and archive tests + if: steps.archive-cache.outputs.cache-hit != 'true' + run: cargo nextest archive --archive-file nextest-archive.tar.zst + + - name: Run Catalyst Core tests + env: + TEST_DB: postgres + TEST_DATABASE_URL: postgres://postgres:123456@localhost + ## removing test ui_test because of bug https://github.com/rust-lang/cargo/issues/10352 + run: | + cargo nextest run \ + -E "not (package(vitup) + package(mainnet-lib) + package(jortestkit) + package(integration-tests) \ + + test(multi_voteplan_ok_private) + test(ui_test))" \ + --archive-file nextest-archive.tar.zst --extract-to ${{ github.workspace }} \ + --extract-overwrite --partition hash:${{ matrix.partition }}/10 --profile ci - jcli: - name: Jcli Tests + cleanup-cache: + name: Clean up run cache runs-on: ubuntu-latest - env: - CARGO_FLAGS: --verbose --locked + permissions: + actions: write + needs: catalyst-core-tests + if: always() steps: - name: Checkout code uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install Nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Install deps - run: - sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config - - name: Run jcli tests - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} - - run: | - cargo build -p jcli - cargo nextest run -p jcli --profile ci + - name: Clean up archive and deps cache + run: | + gh extension install actions/gh-actions-cache + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + gh actions-cache delete nextest-archive-${{ github.run_id }}-${{ github.run_attempt }} --confirm + gh actions-cache delete deps-${{ github.run_id }}-${{ github.run_attempt }} --confirm + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} wallet-js-binding: name: Wallet JS Binding Tests @@ -248,13 +263,21 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: Swatinem/rust-cache@v2 - - name: Install deps + + - name: Cache rust + uses: Swatinem/rust-cache@v2 + with: + shared-key: "build_cache" + save-if: ${{ github.ref == 'refs/heads/main' }} + + - name: Install dependencies run: sudo apt install -y protobuf-compiler libssl-dev libpq-dev libsqlite3-dev pkg-config + - name: Clippy and fmt uses: actions-rs/toolchain@v1 with: toolchain: ${{env.RUST_LATEST_STABLE_VERSION}} components: rustfmt, clippy + - run: scripts/check-fmt.sh \ No newline at end of file