Skip to content

Commit

Permalink
add a Justfile for reproducing CI locally, use it for CI (#10235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekleog-NEAR authored Nov 29, 2023
1 parent dd80b4c commit 176b92f
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 41 deletions.
61 changes: 29 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
pull_request:
merge_group:

env:
CI_HACKS: 1

# BE CAREFUL IF EDITING THIS FILE:
# If you add/remove python tests from here, you should also update `check_pytests.py`’s list of GHA_TESTS
# so that it stays in-sync, to make sure no tests are lost.
Expand All @@ -24,29 +27,28 @@ jobs:
id: linux
cache_id: linux
os: ubuntu-22.04-16core
flags: ""
run_integ_tests: true
type: stable
runs_integ_tests: true
- name: Linux Nightly
id: linux-nightly
cache_id: linux
os: ubuntu-22.04-16core
flags: "--features nightly,test_features"
run_integ_tests: true
type: nightly
runs_integ_tests: true
- name: MacOS
id: macos
cache_id: macos
os: macos-latest-xlarge
# FIXME: some of these tests don't work very well on MacOS at the moment. Should fix
# them at earliest convenience :)
# Note that run_integ_tests also leads to coverage not being uploaded to codecov below,
# the corresponding step is commented-out.
flags: "--exclude node-runtime --exclude runtime-params-estimator --exclude near-network --exclude estimator-warehouse"
run_integ_tests: false
type: stable
runs_integ_tests: false
timeout-minutes: 90
steps:
- uses: actions/checkout@v4

# Install all the required tools
- uses: baptiste0928/cargo-install@21a18ba3bf4a184d1804e8b759930d3471b1c941
with:
crate: just
- uses: baptiste0928/cargo-install@21a18ba3bf4a184d1804e8b759930d3471b1c941
with:
crate: cargo-nextest
Expand All @@ -62,23 +64,16 @@ jobs:
with:
prefix-key: "0" # change this to invalidate CI cache
shared-key: "cargo_nextest-${{ matrix.cache_id }}"
- run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV"
- run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV"
# Run unit tests
- run: cargo nextest run --locked --workspace --exclude integration-tests --cargo-profile dev-release --profile ci ${{ matrix.flags }}
env:
RUST_BACKTRACE: short
- run: cargo llvm-cov report --profile dev-release --codecov --output-path unit-${{ matrix.id }}.json
# See https://github.com/taiki-e/cargo-llvm-cov/issues/292
- run: find target -name '*.profraw' -delete

# Run integration tests
- run: cargo nextest run --locked --package integration-tests --cargo-profile dev-release --profile ci ${{ matrix.flags }}
if: matrix.run_integ_tests
env:
RUST_BACKTRACE: short
- run: cargo llvm-cov report --profile dev-release --codecov --output-path integration-${{ matrix.id }}.json
if: matrix.run_integ_tests
# Run the tests
- run: just codecov "nextest-unit ${{ matrix.type }}"
- run: mv codecov.json unit-${{ matrix.id }}.json
- run: just codecov "nextest-integration ${{ matrix.type }}"
if: matrix.runs_integ_tests
- run: mv codecov.json integration-${{ matrix.id }}.json
if: matrix.runs_integ_tests

# Upload the coverage
- uses: actions/upload-artifact@v3
with:
name: coverage
Expand Down Expand Up @@ -227,15 +222,15 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: baptiste0928/cargo-install@21a18ba3bf4a184d1804e8b759930d3471b1c941
with:
crate: just
- uses: actions/setup-python@v4
with:
python-version: 3.11
cache: pip
- run: pip3 install --user -r pytest/requirements.txt
- run: python3 scripts/check_nightly.py
- run: python3 scripts/check_pytests.py
- run: python3 scripts/fix_nightly_feature_flags.py
- run: ./scripts/formatting --check
- run: just python-style-checks

py_upgradability:
name: "Upgradability"
Expand Down Expand Up @@ -276,8 +271,10 @@ jobs:
prefix-key: "0" # change this to invalidate CI cache
shared-key: "cargo_nextest-linux"
save-if: "false" # use the cache from nextest, but don’t double-save
- run: ./chain/jsonrpc/build_errors_schema.sh
- run: git diff --quiet ./chain/jsonrpc/res/rpc_errors_schema.json || exit 1
- uses: baptiste0928/cargo-install@21a18ba3bf4a184d1804e8b759930d3471b1c941
with:
crate: just
- run: just check-rpc-errors-schema

lychee_checks:
name: "Lychee Lints"
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# FIXME: some of these tests don't work very well on MacOS at the moment. Should fix
# them at earliest convenience :)
# Also in addition to this, the `nextest-integration` test is currently disabled on macos
with_macos_excludes := if os() == "macos" {
"--exclude node-runtime --exclude runtime-params-estimator --exclude near-network --exclude estimator-warehouse"
} else {
""
}
nightly_flags := "--features nightly,test_features"

export RUST_BACKTRACE := env("RUST_BACKTRACE", "short")
ci_hack_nextest_profile := if env("CI_HACKS", "0") == "1" { "--profile ci" } else { "" }

# all the tests, as close to CI as possible
test: test-ci test-extra

# only the tests that are exactly the same as the ones in CI
test-ci: (nextest "stable") (nextest "nightly") python-style-checks

# tests that are as close to CI as possible, but not exactly the same code
test-extra: check-lychee

# all cargo tests, TYPE is "stable" or "nightly"
nextest TYPE *FLAGS: (nextest-unit TYPE FLAGS) (nextest-integration TYPE FLAGS)

# cargo unit tests, TYPE is "stable" or "nightly"
nextest-unit TYPE *FLAGS:
cargo nextest run \
--locked \
--workspace \
--exclude integration-tests \
--cargo-profile dev-release \
{{ ci_hack_nextest_profile }} \
{{ with_macos_excludes }} \
{{ if TYPE == "nightly" { nightly_flags } \
else if TYPE == "stable" { "" } \
else { error("TYPE is neighter 'nightly' nor 'stable'") } }} \
{{ FLAGS }}

# cargo integration tests, TYPE is "stable" or "nightly"
[linux]
nextest-integration TYPE *FLAGS:
cargo nextest run \
--locked \
--package integration-tests \
--cargo-profile dev-release \
{{ ci_hack_nextest_profile }} \
{{ if TYPE == "nightly" { nightly_flags } \
else if TYPE == "stable" { "" } \
else { error("TYPE is neither 'nightly' nor 'stable'") } }} \
{{ FLAGS }}
# Note: when re-enabling this on macos, ci.yml will need to be adjusted to report code coverage again
[macos]
nextest-integration TYPE *FLAGS:
@echo "Nextest integration tests are currently disabled on macos!"

# generate a codecov report for RULE
codecov RULE:
#!/usr/bin/env bash
set -euxo pipefail
# Note: macos seems to not support `source <()` as a way to set environment variables, but
# this variant seems to work on both linux and macos.
# TODO: remove the RUSTFLAGS hack, see also https://github.com/rust-lang/cargo/issues/13040
cargo llvm-cov show-env --export-prefix | grep -v RUSTFLAGS > env
source ./env
export RUSTC_WORKSPACE_WRAPPER="{{ absolute_path("scripts/rustc-coverage-wrapper.sh") }}"
{{ just_executable() }} {{ RULE }}
cargo llvm-cov report --profile dev-release --codecov --output-path codecov.json
# See https://github.com/taiki-e/cargo-llvm-cov/issues/292
find target -name '*.profraw' -delete
# style checks from python scripts
python-style-checks:
python3 scripts/check_nightly.py
python3 scripts/check_pytests.py
python3 scripts/fix_nightly_feature_flags.py
./scripts/formatting --check

# lychee-based url validity checks
check-lychee:
# This is not actually run in CI. GITHUB_TOKEN can still be set locally by people who want
# to reproduce CI behavior in a better way.
lychee . {{ if env("GITHUB_TOKEN", "") != "" { "" } else { "-a 429" } }}
@echo {{ if env("GITHUB_TOKEN", "") != "" { "" } \
else { "Note: 'Too Many Requests' errors are allowed here but not in CI, set GITHUB_TOKEN to check them" } }}

# build target/rpc_errors_schema.json
build-rpc-errors-schema:
rm -f target/rpc_errors_schema.json
cargo check -p near-jsonrpc --features dump_errors_schema

# update chain/jsonrpc/res/rpc_errors_schema.json
update-rpc-errors-schema: build-rpc-errors-schema
cp target/rpc_errors_schema.json chain/jsonrpc/res/rpc_errors_schema.json

# check chain/jsonrpc/res/rpc_errors_schema.json
check-rpc-errors-schema: build-rpc-errors-schema
diff target/rpc_errors_schema.json chain/jsonrpc/res/rpc_errors_schema.json
5 changes: 0 additions & 5 deletions chain/jsonrpc/build_errors_schema.sh

This file was deleted.

0 comments on commit 176b92f

Please sign in to comment.