From 5bb24a9b12777cbb977ac1f66edf5c6195368e66 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 11:33:15 +0300 Subject: [PATCH 01/44] WIP --- .github/workflows/pre-commit.yml | 60 ++++++++++++++++ .pre-commit/.just | 2 +- cli/.just | 2 +- helpers/helpers.just | 115 +++++++++++++++++++++++++++++++ just/_helpers.just | 46 ------------- sdk/.just | 2 +- toolkit-rust/.just | 2 +- tools/.just | 2 +- 8 files changed, 180 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 helpers/helpers.just delete mode 100644 just/_helpers.just diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..5cf2e516 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,60 @@ +# GitHub workflow to run the pre-commit hook. + +name: Nexus SDK +on: + pull_request: + push: + branches: + - main + +# Fix for OOM. +env: + CARGO_BUILD_JOBS: 1 + CARGO_INCREMENTAL: 0 + RUSTFLAGS: > + -C codegen-units=1 + +jobs: + detect-changes: + uses: ./.github/workflows/detect_changes.yml + with: + files: | + **/** + + build-and-test: + name: Build and test + runs-on: ubuntu-latest + needs: detect-changes + if: needs.detect-changes.outputs.changed == 'true' + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + # Set up Docker for tests + - name: Set up Docker + uses: docker/setup-docker-action@v4 + + # Install Rust + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable, nightly-2025-01-06 + override: true + components: rustfmt, clippy + + # Install Rust cache + - name: Cache Build + uses: Swatinem/rust-cache@v2 + with: + cache-targets: true + cache-workspace-crates: true + cache-on-failure: true + cache-all-crates: true + + # Install just + - uses: taiki-e/install-action@just + + # Build, fmt, clippy and test the Nexus SDK + - run: cargo +stable --version + - run: cargo +nightly-2025-01-06 --version + - run: ./.pre-commit/pre-commit diff --git a/.pre-commit/.just b/.pre-commit/.just index a3e2f0e0..c78c491d 100644 --- a/.pre-commit/.just +++ b/.pre-commit/.just @@ -1,4 +1,4 @@ -import '../just/_helpers.just' +import '../helpers/helpers.just' [private] _default: diff --git a/cli/.just b/cli/.just index 44cf2e43..a677fca3 100644 --- a/cli/.just +++ b/cli/.just @@ -4,7 +4,7 @@ # Commands related the Nexus CLI # -import '../just/_helpers.just' +import '../helpers/helpers.just' package := 'nexus-cli' diff --git a/helpers/helpers.just b/helpers/helpers.just new file mode 100644 index 00000000..73f29667 --- /dev/null +++ b/helpers/helpers.just @@ -0,0 +1,115 @@ + +[private] +_check-cargo: + #!/usr/bin/env bash + + if ! command -v cargo &> /dev/null + then + echo "cargo could not be found" + echo "Install cargo from https://doc.rust-lang.org/cargo/getting-started/installation.html" + exit 1 + fi + +[private] +_check-cargo-nextest: _check-cargo + #!/usr/bin/env bash + + if ! command -v cargo-nextest &> /dev/null + then + echo "cargo-nextest could not be found" + echo "Install cargo-nextest from https://nexte.st/" + exit 1 + fi + +[private] +_check-markdownlint-cli2: + #!/usr/bin/env bash + + exe=markdownlint-cli2 + if ! command -v $exe &> /dev/null + then + echo "$exe could not be found" + echo "Install $exe from https://github.com/DavidAnson/$exe" + exit 1 + fi + +[private] +_check-typos: + #!/usr/bin/env bash + + exe=typos + if ! command -v $exe &> /dev/null + then + echo "$exe could not be found" + echo "Install $exe from https://github.com/crate-ci/typos" + exit 1 + fi + +[private] +detect-changes +GLOBS: + #!/usr/bin/env bash + + set -euo pipefail + + GLOBS="{{GLOBS}}" + REGEXES=() # technically not needed but useful for debugging + BIG_REGEX="" + + function LOG() { + echo "== $*" >&2 + } + + # Get list of changed files compared to last commit + changed_files=$(git diff --name-only HEAD) + LOG "Changed files: $changed_files" + ## If GLOBS is not set, we just output the changed files + #if [[ -z "${GLOBS}" ]]; then + # echo "$changed_files" + # exit 0 + #fi + + # Convert simple globs to regexes. By simple we mean `**` and `*` stuff. + # + # We support either separate globs: + # + # '**/*.rs' '*.md' + # + # or one big string with space-separated globs: + # + # '**/*.rs' '*.md' + # + # Both will give the same result, one big regex: + # + # '^.*/[^/]*\.rs$|^[^/]*\.md$' + # + for glob in $(echo "$GLOBS"); do + # Escape special characters and convert to regex + regex=$(echo "$glob" |\ + # We do the following transformations: + # 1. escape common regex meta + # 2. create a temporary token for ** + # 3. convert * to [^/]* (matches any character except /) + # 4. convert ** to .* + sed -e 's/[.[\^$()+{}|]/\\&/g' \ + -e 's#\*\*#__GLOBSTAR__#g' \ + -e 's#\*#[^/]*#g' \ + -e 's#__GLOBSTAR__#.*#g') + + # match the whole string, so we add ^ and $ at the beginning and end + regex="^$regex\$" + + if [[ -z "$BIG_REGEX" ]]; then + BIG_REGEX="$regex" + else + BIG_REGEX+="|$regex" + fi + + REGEXES+=("$regex") + + LOG "Glob: $glob => Regex: $regex" + done + + LOG "Big regex: $BIG_REGEX" + LOG "" + + grep -E "$BIG_REGEX" <<< "$changed_files" diff --git a/just/_helpers.just b/just/_helpers.just deleted file mode 100644 index 9d4cbbbe..00000000 --- a/just/_helpers.just +++ /dev/null @@ -1,46 +0,0 @@ - -[private] -_check-cargo: - #!/usr/bin/env bash - - if ! command -v cargo &> /dev/null - then - echo "cargo could not be found" - echo "Install cargo from https://doc.rust-lang.org/cargo/getting-started/installation.html" - exit 1 - fi - -[private] -_check-cargo-nextest: _check-cargo - #!/usr/bin/env bash - - if ! command -v cargo-nextest &> /dev/null - then - echo "cargo-nextest could not be found" - echo "Install cargo-nextest from https://nexte.st/" - exit 1 - fi - -[private] -_check-markdownlint-cli2: - #!/usr/bin/env bash - - exe=markdownlint-cli2 - if ! command -v $exe &> /dev/null - then - echo "$exe could not be found" - echo "Install $exe from https://github.com/DavidAnson/$exe" - exit 1 - fi - -[private] -_check-typos: - #!/usr/bin/env bash - - exe=typos - if ! command -v $exe &> /dev/null - then - echo "$exe could not be found" - echo "Install $exe from https://github.com/crate-ci/typos" - exit 1 - fi diff --git a/sdk/.just b/sdk/.just index b5cff5b6..ebd02905 100644 --- a/sdk/.just +++ b/sdk/.just @@ -4,7 +4,7 @@ # Commands related the Nexus SDK. # -import '../just/_helpers.just' +import '../helpers/helpers.just' package := 'nexus-sdk' diff --git a/toolkit-rust/.just b/toolkit-rust/.just index d266be38..0d27f4b4 100644 --- a/toolkit-rust/.just +++ b/toolkit-rust/.just @@ -4,7 +4,7 @@ # Commands related the Nexus Toolkit for Rust # -import '../just/_helpers.just' +import '../helpers/helpers.just' package := 'nexus-toolkit' diff --git a/tools/.just b/tools/.just index e938bac1..d1754fac 100644 --- a/tools/.just +++ b/tools/.just @@ -4,7 +4,7 @@ # Commands related to native Nexus Tools. # -import '../just/_helpers.just' +import '../helpers/helpers.just' [private] _default: From 7f5020fab9ac2a330c928f4c99eeb3d56fb9cc8c Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 11:35:26 +0300 Subject: [PATCH 02/44] WIP --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5cf2e516..be1fefc5 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,6 +1,6 @@ # GitHub workflow to run the pre-commit hook. -name: Nexus SDK +name: Pre-commit hook on: pull_request: push: From 71d4b00b3247ddbdfac9dd852a84bccb0ba7b764 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 11:51:23 +0300 Subject: [PATCH 03/44] WIP --- .github/workflows/pre-commit.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index be1fefc5..184406ce 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -54,6 +54,10 @@ jobs: # Install just - uses: taiki-e/install-action@just + # Install typos + - name: typos-action + uses: crate-ci/typos@v1.34.0 + # Build, fmt, clippy and test the Nexus SDK - run: cargo +stable --version - run: cargo +nightly-2025-01-06 --version From 612c0b8d30f1cc620f45472f32e4c0b42fa01ce1 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 12:14:40 +0300 Subject: [PATCH 04/44] WIP --- .github/workflows/pre-commit.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 184406ce..c0a7ec39 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -9,6 +9,7 @@ on: # Fix for OOM. env: + RUST_CACHE_VERBOSE: true CARGO_BUILD_JOBS: 1 CARGO_INCREMENTAL: 0 RUSTFLAGS: > @@ -51,8 +52,10 @@ jobs: cache-on-failure: true cache-all-crates: true - # Install just - - uses: taiki-e/install-action@just + # Install cargo-nextest + - uses: taiki-e/install-action@v2 + with: + tool: cargo-binstall,just,cargo-nextest # Install typos - name: typos-action From 11b98ae0be3788619de40267bfb6a1fe412e11e5 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 12:44:49 +0300 Subject: [PATCH 05/44] WIP --- .github/workflows/pre-commit.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index c0a7ec39..06d1b2c8 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -11,7 +11,7 @@ on: env: RUST_CACHE_VERBOSE: true CARGO_BUILD_JOBS: 1 - CARGO_INCREMENTAL: 0 + CARGO_INCREMENTAL: 1 RUSTFLAGS: > -C codegen-units=1 @@ -32,7 +32,7 @@ jobs: uses: actions/checkout@v4 # Set up Docker for tests - - name: Set up Docker + - name: Set up Docker for tests uses: docker/setup-docker-action@v4 # Install Rust @@ -52,16 +52,19 @@ jobs: cache-on-failure: true cache-all-crates: true - # Install cargo-nextest - - uses: taiki-e/install-action@v2 + # Install Rust tools + - name: Install Rust tools + uses: taiki-e/install-action@v2 with: tool: cargo-binstall,just,cargo-nextest # Install typos - - name: typos-action + - name: Install typos uses: crate-ci/typos@v1.34.0 - # Build, fmt, clippy and test the Nexus SDK - - run: cargo +stable --version - - run: cargo +nightly-2025-01-06 --version + # Install markdownlint-cli2 + - name: Install markdownlint-cli2 + uses: DavidAnson/markdownlint-cli2-action@v20 + + - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - run: ./.pre-commit/pre-commit From 94df977261cf4382f786ea3751aaad6800c480e0 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 14:15:42 +0300 Subject: [PATCH 06/44] WIP --- .github/workflows/pre-commit.yml | 9 +++------ .pre-commit/.just | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 06d1b2c8..2df53da2 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -53,18 +53,15 @@ jobs: cache-all-crates: true # Install Rust tools + # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md - name: Install Rust tools uses: taiki-e/install-action@v2 with: - tool: cargo-binstall,just,cargo-nextest - - # Install typos - - name: Install typos - uses: crate-ci/typos@v1.34.0 + tool: cargo-binstall,just,cargo-nextest,typos # Install markdownlint-cli2 - name: Install markdownlint-cli2 - uses: DavidAnson/markdownlint-cli2-action@v20 + run: npm install -g markdownlint-cli2 - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - run: ./.pre-commit/pre-commit diff --git a/.pre-commit/.just b/.pre-commit/.just index c78c491d..c457de0f 100644 --- a/.pre-commit/.just +++ b/.pre-commit/.just @@ -90,7 +90,6 @@ cargo-nextest-build: _check-cargo-nextest # cargo nextest run --locked --fail-fast --workspace --all-features --bins --examples --tests cargo-nextest-run: _check-cargo-nextest # Note that tests require docker to be running. - # TODO: https://github.com/Talus-Network/nexus-sdk/issues/254 cargo nextest run --locked --fail-fast --workspace --all-features --bins --examples --tests From a9e6c58bbad9e9ffaf97d45b6814f3c5e5129698 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 14:45:53 +0300 Subject: [PATCH 07/44] WIP --- .github/workflows/pre-commit.yml | 22 +++++++++++++++++----- helpers/npm-install-g.txt | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 helpers/npm-install-g.txt diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 2df53da2..77d90c9a 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,14 +44,22 @@ jobs: components: rustfmt, clippy # Install Rust cache - - name: Cache Build + - name: Rust cache uses: Swatinem/rust-cache@v2 with: cache-targets: true - cache-workspace-crates: true cache-on-failure: true cache-all-crates: true + # Extra cache for anything that is not cached by rust-cache + - name: Extra cache + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-npm-${{ hashFiles('helpers/npm-install-g.txt') }} + restore-keys: | + ${{ runner.os }}-npm- + # Install Rust tools # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md - name: Install Rust tools @@ -59,9 +67,13 @@ jobs: with: tool: cargo-binstall,just,cargo-nextest,typos - # Install markdownlint-cli2 - - name: Install markdownlint-cli2 - run: npm install -g markdownlint-cli2 + # Install NPM stuff (markdownlint-cli2) + - name: Install NPM stuff (markdownlint-cli2) + run: | + command -v markdownlint-cli2 || \ + while read -r tool; do + npm install -g "$tool" + done < helpers/npm-install-g.txt - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - run: ./.pre-commit/pre-commit diff --git a/helpers/npm-install-g.txt b/helpers/npm-install-g.txt new file mode 100644 index 00000000..f4537ac3 --- /dev/null +++ b/helpers/npm-install-g.txt @@ -0,0 +1 @@ +markdownlint-cli2@0.18.1 From 698b44721f9482ebc150e91be7ec10eeb245ea8c Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 14:57:46 +0300 Subject: [PATCH 08/44] WIP --- .github/workflows/pre-commit.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 77d90c9a..c48217be 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -37,19 +37,20 @@ jobs: # Install Rust - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 + uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 with: toolchain: stable, nightly-2025-01-06 override: true components: rustfmt, clippy +# cache-directories: ~/.npm - # Install Rust cache - - name: Rust cache - uses: Swatinem/rust-cache@v2 - with: - cache-targets: true - cache-on-failure: true - cache-all-crates: true +# # Install Rust cache +# - name: Rust cache +# uses: Swatinem/rust-cache@v2 +# with: +# cache-targets: true +# cache-on-failure: true +# cache-all-crates: true # Extra cache for anything that is not cached by rust-cache - name: Extra cache From dc85228375a6f26b826cc790079b04240c5cee1c Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 15:16:59 +0300 Subject: [PATCH 09/44] WIP --- .github/workflows/pre-commit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index c48217be..227c2578 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -36,13 +36,15 @@ jobs: uses: docker/setup-docker-action@v4 # Install Rust + # Note that it can handle the Rust cache automatically (via Swatinem/rust-cache), + # but we use a custom cache for NPM stuff. - name: Install Rust uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 with: toolchain: stable, nightly-2025-01-06 override: true components: rustfmt, clippy -# cache-directories: ~/.npm + cache-directories: ~/.npm # # Install Rust cache # - name: Rust cache From a8c2abc1f64738a1dbc44711e086af5215e7631e Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 15:43:53 +0300 Subject: [PATCH 10/44] WIP --- .github/workflows/pre-commit.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 227c2578..067c5104 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -54,14 +54,14 @@ jobs: # cache-on-failure: true # cache-all-crates: true - # Extra cache for anything that is not cached by rust-cache - - name: Extra cache - uses: actions/cache@v4 - with: - path: ~/.npm - key: ${{ runner.os }}-npm-${{ hashFiles('helpers/npm-install-g.txt') }} - restore-keys: | - ${{ runner.os }}-npm- +# # Extra cache for anything that is not cached by rust-cache +# - name: Extra cache +# uses: actions/cache@v4 +# with: +# path: ~/.npm +# key: ${{ runner.os }}-npm-${{ hashFiles('helpers/npm-install-g.txt') }} +# restore-keys: | +# ${{ runner.os }}-npm- # Install Rust tools # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md From 132d58c8e10a5c72377a9e6161606da0359ac845 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 17:22:56 +0300 Subject: [PATCH 11/44] WIP --- .github/workflows/pre-commit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 067c5104..0711ad7f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -76,6 +76,7 @@ jobs: command -v markdownlint-cli2 || \ while read -r tool; do npm install -g "$tool" + which "$tool" done < helpers/npm-install-g.txt - run: cargo +stable --version && cargo +nightly-2025-01-06 --version From c91113b0ab5e072ee45d7b386a5aa02b4e4315b7 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 17:28:13 +0300 Subject: [PATCH 12/44] WIP --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 0711ad7f..db08adc8 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -76,7 +76,7 @@ jobs: command -v markdownlint-cli2 || \ while read -r tool; do npm install -g "$tool" - which "$tool" + which "$(echo "$tool" | cut -d'@' -f1)" done < helpers/npm-install-g.txt - run: cargo +stable --version && cargo +nightly-2025-01-06 --version From bf4c621163dbf736ec27c47e1f99bf49d1b1d1ac Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 17:33:42 +0300 Subject: [PATCH 13/44] WIP --- .github/workflows/pre-commit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index db08adc8..9637b2db 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,7 +44,9 @@ jobs: toolchain: stable, nightly-2025-01-06 override: true components: rustfmt, clippy - cache-directories: ~/.npm + cache-directories: | + ~/.npm + /usr/local/bin # # Install Rust cache # - name: Rust cache From 4f45aed0b5093479049ed3d129a7d9b4f08bbb17 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 17:55:40 +0300 Subject: [PATCH 14/44] WIP --- .github/workflows/pre-commit.yml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 9637b2db..68455460 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -7,7 +7,15 @@ on: branches: - main -# Fix for OOM. +# NOTE: The following values seem to be a fix for OOM, in case they are needed again. +# +# RUST_CACHE_VERBOSE: true +# CARGO_BUILD_JOBS: 1 +# CARGO_INCREMENTAL: 0 +# RUSTFLAGS: > +# -C codegen-units=1 +# +# but we have reverted CARGO_INCREMENTAL to 1 to speed up builds. env: RUST_CACHE_VERBOSE: true CARGO_BUILD_JOBS: 1 @@ -16,17 +24,17 @@ env: -C codegen-units=1 jobs: - detect-changes: - uses: ./.github/workflows/detect_changes.yml - with: - files: | - **/** +# detect-changes: +# uses: ./.github/workflows/detect_changes.yml +# with: +# files: | +# **/** build-and-test: - name: Build and test + name: Run pre-commit checks and build runs-on: ubuntu-latest - needs: detect-changes - if: needs.detect-changes.outputs.changed == 'true' +# needs: detect-changes +# if: needs.detect-changes.outputs.changed == 'true' steps: - name: Check out repository code uses: actions/checkout@v4 @@ -36,6 +44,7 @@ jobs: uses: docker/setup-docker-action@v4 # Install Rust + # See: https://github.com/actions-rust-lang/setup-rust-toolchain # Note that it can handle the Rust cache automatically (via Swatinem/rust-cache), # but we use a custom cache for NPM stuff. - name: Install Rust From eff8e5f02335656591b6c86ef5d29c8ae962da9d Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 1 Aug 2025 18:04:58 +0300 Subject: [PATCH 15/44] WIP --- .github/workflows/pre-commit.yml | 37 ++++++-------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 68455460..955a4c8e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -24,17 +24,9 @@ env: -C codegen-units=1 jobs: -# detect-changes: -# uses: ./.github/workflows/detect_changes.yml -# with: -# files: | -# **/** - build-and-test: - name: Run pre-commit checks and build + name: Run pre-commit checks runs-on: ubuntu-latest -# needs: detect-changes -# if: needs.detect-changes.outputs.changed == 'true' steps: - name: Check out repository code uses: actions/checkout@v4 @@ -57,23 +49,6 @@ jobs: ~/.npm /usr/local/bin -# # Install Rust cache -# - name: Rust cache -# uses: Swatinem/rust-cache@v2 -# with: -# cache-targets: true -# cache-on-failure: true -# cache-all-crates: true - -# # Extra cache for anything that is not cached by rust-cache -# - name: Extra cache -# uses: actions/cache@v4 -# with: -# path: ~/.npm -# key: ${{ runner.os }}-npm-${{ hashFiles('helpers/npm-install-g.txt') }} -# restore-keys: | -# ${{ runner.os }}-npm- - # Install Rust tools # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md - name: Install Rust tools @@ -81,13 +56,13 @@ jobs: with: tool: cargo-binstall,just,cargo-nextest,typos - # Install NPM stuff (markdownlint-cli2) - - name: Install NPM stuff (markdownlint-cli2) + # Install NPM stuff from helpers/npm-install-g.txt + - name: Install NPM stuff from helpers/npm-install-g.txt run: | - command -v markdownlint-cli2 || \ while read -r tool; do - npm install -g "$tool" - which "$(echo "$tool" | cut -d'@' -f1)" + if ! command -v "$tool" &> /dev/null; then + npm install -g "$tool" + fi done < helpers/npm-install-g.txt - run: cargo +stable --version && cargo +nightly-2025-01-06 --version From bd236b0d8f5749a1c7948cc71dd18daa79d45c21 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 11:04:02 +0300 Subject: [PATCH 16/44] update pre-commit hook --- .pre-commit/pre-commit | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/.pre-commit/pre-commit b/.pre-commit/pre-commit index 7a4e0637..b814d394 100755 --- a/.pre-commit/pre-commit +++ b/.pre-commit/pre-commit @@ -4,7 +4,7 @@ # Source: https://github.com/loverdos/pre-commit # shellcheck disable=SC2034 -SCRIPT_VERSION=14 +SCRIPT_VERSION=16 # shellcheck disable=SC2034 SCRIPT_ID=AF13AE47-34E0-41FA-8FF8-AF660A922C6A @@ -100,6 +100,14 @@ function backup_file() { mv "$file" "$new_location" } +function sec_to_mmss() { + local time_sec=$1 + local time_min=$((time_sec / 60)) + time_sec=$((time_sec % 60)) + + printf "%02d:%02d" $time_min $time_sec +} + function install() { LOG "Begin installation process from $MY_PATH to $git_root" @@ -169,9 +177,9 @@ function run() { local successes=0 local failures=0 local mark="" - local time_sec=0 - local time_min=0 - local time="" + local script_seconds=0 + local script_time="" + local script_times=() LOG "Running pre-commit hook" SECONDS=0 # bash builtin ;) @@ -188,12 +196,19 @@ function run() { LOG LOG "Run: $script" + script_seconds=$SECONDS + $script status=$? + + script_seconds=$((SECONDS - script_seconds)) cmds+=("$script") cmd_statuses+=("$status") + script_time=$(sec_to_mmss $script_seconds) + script_times+=("$script_time") + if ((status == 0)); then ((successes++)) mark="✅" @@ -206,23 +221,20 @@ function run() { done set -e - time_sec=$SECONDS - time_min=$((time_sec / 60)) - time_sec=$((time_sec % 60)) - time=$(printf "%02d:%02d" $time_min $time_sec) + time=$(sec_to_mmss $SECONDS) LOG LOG "Results: $successes success(es), $failures failure(s)" - LOG " In: $time (min:sec)" + LOG " In: $time [min:sec]" LOG local result=0 for i in "${!cmds[@]}"; do if ((cmd_statuses[i] == 0)); then - LOG "✅ ${cmds[i]}" + LOG "✅ [${script_times[i]}] ${cmds[i]}" else - LOG "❌ ${cmds[i]}" + LOG "❌ [${script_times[i]}] ${cmds[i]}" result=1 fi done From 3b53a539ebff42dc37432a0cbdd50da07e11fcf2 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 11:04:42 +0300 Subject: [PATCH 17/44] WIP --- .github/workflows/pre-commit.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 955a4c8e..1dd73d73 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -36,20 +36,24 @@ jobs: uses: docker/setup-docker-action@v4 # Install Rust + # # See: https://github.com/actions-rust-lang/setup-rust-toolchain # Note that it can handle the Rust cache automatically (via Swatinem/rust-cache), - # but we use a custom cache for NPM stuff. + # and even take care of (=cache) other directories. - name: Install Rust uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 with: toolchain: stable, nightly-2025-01-06 override: true components: rustfmt, clippy + cache-all-crates: true + cache-workspace-crates: true cache-directories: | ~/.npm /usr/local/bin # Install Rust tools + # # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md - name: Install Rust tools uses: taiki-e/install-action@v2 @@ -57,11 +61,18 @@ jobs: tool: cargo-binstall,just,cargo-nextest,typos # Install NPM stuff from helpers/npm-install-g.txt + # + # Why have a separate file? + # The spirit is that we can run things locally and then reuse the same stuff in CI, + # not code everything in CI and then try to reverse engineer how it could run locally. - name: Install NPM stuff from helpers/npm-install-g.txt run: | while read -r tool; do if ! command -v "$tool" &> /dev/null; then + echo "Installing tool: $tool" npm install -g "$tool" + else + echo "Tool already installed: $tool" fi done < helpers/npm-install-g.txt From 89e89ccc363a3ea14d9d9837b9b1b3675441d62d Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 11:21:59 +0300 Subject: [PATCH 18/44] WIP --- .github/workflows/cli.yml | 60 ---------------------------- .github/workflows/pre-commit.yml | 11 +---- .github/workflows/sdk.yml | 62 ----------------------------- .github/workflows/toolkit-rust.yml | 59 --------------------------- .pre-commit/.just | 6 +++ .pre-commit/11-test-cli-completions | 3 ++ cli/.just | 6 --- helpers/npm-install-g.sh | 18 +++++++++ 8 files changed, 29 insertions(+), 196 deletions(-) delete mode 100644 .github/workflows/cli.yml delete mode 100644 .github/workflows/sdk.yml delete mode 100644 .github/workflows/toolkit-rust.yml create mode 100755 .pre-commit/11-test-cli-completions create mode 100644 helpers/npm-install-g.sh diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml deleted file mode 100644 index 0cba14d5..00000000 --- a/.github/workflows/cli.yml +++ /dev/null @@ -1,60 +0,0 @@ -# Github workflow to build and test the Nexus CLI code - -name: Nexus CLI -on: - pull_request: - push: - branches: - - main - -# Fix for OOM. -env: - CARGO_BUILD_JOBS: 1 - CARGO_INCREMENTAL: 0 - RUSTFLAGS: > - -C codegen-units=1 - -jobs: - detect-changes: - uses: ./.github/workflows/detect_changes.yml - with: - files: | - cli/** - # 1. Install Rust - # 2. Install Rust cache - # 3. Install just - # 4. Build, fmt, clippy and test the CLI - build-and-test: - name: Build and test - runs-on: ubuntu-latest - needs: detect-changes - if: needs.detect-changes.outputs.changed == 'true' - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - # 1. - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable, nightly-2025-01-06 - override: true - components: rustfmt, clippy - - # 2. - - name: Cache Build - uses: Swatinem/rust-cache@v2 - with: - workspaces: cli - - # 3 - - uses: taiki-e/install-action@just - - # 4 - - run: cargo +stable --version - - run: cargo +nightly-2025-01-06 --version - - run: just cli check - - run: just cli fmt-check - - run: just cli clippy - - run: just cli test - - run: just cli test-completions diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 1dd73d73..6fefc51c 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -65,16 +65,9 @@ jobs: # Why have a separate file? # The spirit is that we can run things locally and then reuse the same stuff in CI, # not code everything in CI and then try to reverse engineer how it could run locally. + # - name: Install NPM stuff from helpers/npm-install-g.txt - run: | - while read -r tool; do - if ! command -v "$tool" &> /dev/null; then - echo "Installing tool: $tool" - npm install -g "$tool" - else - echo "Tool already installed: $tool" - fi - done < helpers/npm-install-g.txt + run: ./helpers/npm-install-g.sh - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - run: ./.pre-commit/pre-commit diff --git a/.github/workflows/sdk.yml b/.github/workflows/sdk.yml deleted file mode 100644 index c27a5c31..00000000 --- a/.github/workflows/sdk.yml +++ /dev/null @@ -1,62 +0,0 @@ -# Github workflow to build and test the Nexus SDK code - -name: Nexus SDK -on: - pull_request: - push: - branches: - - main - -# Fix for OOM. -env: - CARGO_BUILD_JOBS: 1 - CARGO_INCREMENTAL: 0 - RUSTFLAGS: > - -C codegen-units=1 - -jobs: - detect-changes: - uses: ./.github/workflows/detect_changes.yml - with: - files: | - sdk/** - # 1. Install Rust - # 2. Install Rust cache - # 3. Install just - # 4. Build, fmt, clippy and test the Nexus SDK - build-and-test: - name: Build and test - runs-on: ubuntu-latest - needs: detect-changes - if: needs.detect-changes.outputs.changed == 'true' - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - - name: Set up Docker - uses: docker/setup-docker-action@v4 - - # 1. - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable, nightly-2025-01-06 - override: true - components: rustfmt, clippy - - # 2. - - name: Cache Build - uses: Swatinem/rust-cache@v2 - with: - workspaces: sdk - - # 3. - - uses: taiki-e/install-action@just - - # 4 - - run: cargo +stable --version - - run: cargo +nightly-2025-01-06 --version - - run: just sdk check - - run: just sdk fmt-check - - run: just sdk clippy - - run: just sdk test diff --git a/.github/workflows/toolkit-rust.yml b/.github/workflows/toolkit-rust.yml deleted file mode 100644 index c3bbbe6c..00000000 --- a/.github/workflows/toolkit-rust.yml +++ /dev/null @@ -1,59 +0,0 @@ -# Github workflow to build and test the Nexus Toolkit for Rust code - -name: Nexus Toolkit for Rust -on: - pull_request: - push: - branches: - - main - -# Fix for OOM. -env: - CARGO_BUILD_JOBS: 1 - CARGO_INCREMENTAL: 0 - RUSTFLAGS: > - -C codegen-units=1 - -jobs: - detect-changes: - uses: ./.github/workflows/detect_changes.yml - with: - files: | - toolkit-rust/** - # 1. Install Rust - # 2. Install Rust cache - # 3. Install just - # 4. Build, fmt, clippy and test the Toolkit for Rust - build-and-test: - name: Build and test - runs-on: ubuntu-latest - needs: detect-changes - if: needs.detect-changes.outputs.changed == 'true' - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - # 1. - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable, nightly-2025-01-06 - override: true - components: rustfmt, clippy - - # 2. - - name: Cache Build - uses: Swatinem/rust-cache@v2 - with: - workspaces: toolkit-rust - - # 3. - - uses: taiki-e/install-action@just - - # 4 - - run: cargo +stable --version - - run: cargo +nightly-2025-01-06 --version - - run: just toolkit-rust check - - run: just toolkit-rust fmt-check - - run: just toolkit-rust clippy - - run: just toolkit-rust test diff --git a/.pre-commit/.just b/.pre-commit/.just index c457de0f..a1ee6fdf 100644 --- a/.pre-commit/.just +++ b/.pre-commit/.just @@ -188,3 +188,9 @@ typos: _check-typos cd $(git rev-parse --show-toplevel) typos + +# Test completions (bash for now) +test-cli-completions: + #!/usr/bin/env bash + + source <(cargo +stable run --package nexus-cli completion bash) diff --git a/.pre-commit/11-test-cli-completions b/.pre-commit/11-test-cli-completions new file mode 100755 index 00000000..0ea7a1f7 --- /dev/null +++ b/.pre-commit/11-test-cli-completions @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +exec just pre-commit::test-cli-completions diff --git a/cli/.just b/cli/.just index a677fca3..a61b18f6 100644 --- a/cli/.just +++ b/cli/.just @@ -24,12 +24,6 @@ check: _check-cargo test: _check-cargo cargo +stable test --package {{ package }} -# Test completions (bash for now) -test-completions: build - #!/usr/bin/env bash - - source <(cargo +stable run --package {{ package }} completion bash) - # Run rustfmt on the CLI project fmt-check: _check-cargo cargo +nightly-2025-01-06 fmt --package {{ package }} --check diff --git a/helpers/npm-install-g.sh b/helpers/npm-install-g.sh new file mode 100644 index 00000000..9d2b0f6a --- /dev/null +++ b/helpers/npm-install-g.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Go to the root of the git repository +cd $(git rev-parse --show-toplevel) + +# Install NPM stuff from helpers/npm-install-g.txt +while read -r tool_at_version; do + # Split the tool name and version + tool=$(echo "$tool_at_version" | cut -d'@' -f1) + if ! command -v "$tool" &> /dev/null; then + echo "Installing tool: $tool_at_version" + npm install -g "$tool_at_version" + else + echo "Tool already installed: $tool_at_version" + fi +done < helpers/npm-install-g.txt From d55ceb9c0ed7e5716bd63f437800bb395853a82e Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 11:25:03 +0300 Subject: [PATCH 19/44] WIP --- .github/workflows/tools.yml | 59 ------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 .github/workflows/tools.yml diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml deleted file mode 100644 index de718fe3..00000000 --- a/.github/workflows/tools.yml +++ /dev/null @@ -1,59 +0,0 @@ -# Github workflow to build and test the native Nexus Tools code - -name: Native Nexus Tools -on: - pull_request: - push: - branches: - - main - -# Fix for OOM. -env: - CARGO_BUILD_JOBS: 1 - CARGO_INCREMENTAL: 0 - RUSTFLAGS: > - -C codegen-units=1 - -jobs: - detect-changes: - uses: ./.github/workflows/detect_changes.yml - with: - files: | - tools/** - # 1. Install Rust - # 2. Install Rust cache - # 3. Install just - # 4. Build, fmt, clippy and test the native Nexus Tools - build-and-test: - name: Build and test - runs-on: ubuntu-latest - needs: detect-changes - if: needs.detect-changes.outputs.changed == 'true' - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - # 1. - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable, nightly-2025-01-06 - override: true - components: rustfmt, clippy - - # 2. - - name: Cache Build - uses: Swatinem/rust-cache@v2 - with: - workspaces: tools - - # 3. - - uses: taiki-e/install-action@just - - # 4 - - run: cargo +stable --version - - run: cargo +nightly-2025-01-06 --version - - run: just tools check - - run: just tools fmt-check - - run: just tools clippy - - run: just tools test From cadfb7abee16be4544584c7ba97fc46c562f7fcf Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 11:34:12 +0300 Subject: [PATCH 20/44] WIP --- helpers/npm-install-g.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 helpers/npm-install-g.sh diff --git a/helpers/npm-install-g.sh b/helpers/npm-install-g.sh old mode 100644 new mode 100755 From fb2cf850deb20c82f1dce59ab35620372c18c33f Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 12:04:34 +0300 Subject: [PATCH 21/44] WIP --- .pre-commit/.just | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.pre-commit/.just b/.pre-commit/.just index a1ee6fdf..22448d10 100644 --- a/.pre-commit/.just +++ b/.pre-commit/.just @@ -194,3 +194,31 @@ test-cli-completions: #!/usr/bin/env bash source <(cargo +stable run --package nexus-cli completion bash) + +executable-scripts: + #!/usr/bin/env bash + + set -euo pipefail + + error=0 + + cd $(git rev-parse --show-toplevel) + + for f in $(git ls-files); do + first_line=$(head -n 1 "$f") + + # see if the first line is a shell shebang + if [[ "$first_line" =~ ^(#! *) ]]; then + # ... of the correct format, we checked that in another script. + if [[ "$first_line" =~ ^(#! */usr/bin/env *) ]]; then + if [[ ! -x "$f" ]]; then + echo "❌ $f is not executable" >&2 + error=1 + else + echo "✅ $f" >&2 + fi + fi + fi + done + + exit $error From 1523c33f2eda73b301186924104d0dcfe0c08f93 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 12:20:48 +0300 Subject: [PATCH 22/44] WIP --- .pre-commit/12-executable-scripts | 3 +++ helpers/npm-install-g.sh | 1 + 2 files changed, 4 insertions(+) create mode 100755 .pre-commit/12-executable-scripts diff --git a/.pre-commit/12-executable-scripts b/.pre-commit/12-executable-scripts new file mode 100755 index 00000000..3be7a9e3 --- /dev/null +++ b/.pre-commit/12-executable-scripts @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +exec just pre-commit::executable-scripts diff --git a/helpers/npm-install-g.sh b/helpers/npm-install-g.sh index 9d2b0f6a..5bc0f273 100755 --- a/helpers/npm-install-g.sh +++ b/helpers/npm-install-g.sh @@ -9,6 +9,7 @@ cd $(git rev-parse --show-toplevel) while read -r tool_at_version; do # Split the tool name and version tool=$(echo "$tool_at_version" | cut -d'@' -f1) + if ! command -v "$tool" &> /dev/null; then echo "Installing tool: $tool_at_version" npm install -g "$tool_at_version" From 5c74ca726047948e9531f5eaef35393ec40e3772 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 13:42:33 +0300 Subject: [PATCH 23/44] WIP --- .github/workflows/pre-commit.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 6fefc51c..c047168f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -46,11 +46,6 @@ jobs: toolchain: stable, nightly-2025-01-06 override: true components: rustfmt, clippy - cache-all-crates: true - cache-workspace-crates: true - cache-directories: | - ~/.npm - /usr/local/bin # Install Rust tools # From 926eb1e950d605823d44d9975601f841e5292e60 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 14:14:02 +0300 Subject: [PATCH 24/44] WIP --- .github/workflows/pre-commit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index c047168f..d28c7ae6 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -23,6 +23,7 @@ env: RUSTFLAGS: > -C codegen-units=1 + jobs: build-and-test: name: Run pre-commit checks From b18472077c2c3e98b6012eac98e4126caa4ef97e Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 15:13:56 +0300 Subject: [PATCH 25/44] WIP --- .github/workflows/pre-commit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index d28c7ae6..f7482a46 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -33,8 +33,8 @@ jobs: uses: actions/checkout@v4 # Set up Docker for tests - - name: Set up Docker for tests - uses: docker/setup-docker-action@v4 +# - name: Set up Docker for tests +# uses: docker/setup-docker-action@v4 # Install Rust # From 614825c6e2a5578730a623508f5e521f16da9306 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 15:32:55 +0300 Subject: [PATCH 26/44] WIP --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index f7482a46..fd9a058a 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -28,6 +28,8 @@ jobs: build-and-test: name: Run pre-commit checks runs-on: ubuntu-latest + env: + CARGO_INCREMENTAL: 1 steps: - name: Check out repository code uses: actions/checkout@v4 From 779772d7aa8a9cbedc056833a1cb5a1d5c2a6c92 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 15:41:52 +0300 Subject: [PATCH 27/44] WIP --- .github/workflows/pre-commit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index fd9a058a..83ab4c51 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -25,11 +25,9 @@ env: jobs: - build-and-test: + run-pre-commit: name: Run pre-commit checks runs-on: ubuntu-latest - env: - CARGO_INCREMENTAL: 1 steps: - name: Check out repository code uses: actions/checkout@v4 @@ -69,3 +67,5 @@ jobs: - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - run: ./.pre-commit/pre-commit + env: + CARGO_INCREMENTAL: 1 From a7c6cebb2a57c2c547b24409a1663160d40be5ac Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 16:21:49 +0300 Subject: [PATCH 28/44] WIP --- .github/workflows/pre-commit.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 83ab4c51..054a39e2 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -57,15 +57,13 @@ jobs: tool: cargo-binstall,just,cargo-nextest,typos # Install NPM stuff from helpers/npm-install-g.txt - # - # Why have a separate file? - # The spirit is that we can run things locally and then reuse the same stuff in CI, - # not code everything in CI and then try to reverse engineer how it could run locally. - # - name: Install NPM stuff from helpers/npm-install-g.txt run: ./helpers/npm-install-g.sh + # Just print some versions - run: cargo +stable --version && cargo +nightly-2025-01-06 --version + + # Finally, run the pre-commit hook - run: ./.pre-commit/pre-commit env: CARGO_INCREMENTAL: 1 From c0f0e44d7b09a5e14116985ff0a919c5945d8d7f Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 16:49:42 +0300 Subject: [PATCH 29/44] WIP --- .github/workflows/pre-commit.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 054a39e2..d560c1bb 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -19,7 +19,7 @@ on: env: RUST_CACHE_VERBOSE: true CARGO_BUILD_JOBS: 1 - CARGO_INCREMENTAL: 1 + CARGO_INCREMENTAL: 1 # NOTE: unfortunately this does not propagate to steps below. RUSTFLAGS: > -C codegen-units=1 @@ -32,16 +32,11 @@ jobs: - name: Check out repository code uses: actions/checkout@v4 - # Set up Docker for tests -# - name: Set up Docker for tests -# uses: docker/setup-docker-action@v4 - # Install Rust # # See: https://github.com/actions-rust-lang/setup-rust-toolchain - # Note that it can handle the Rust cache automatically (via Swatinem/rust-cache), - # and even take care of (=cache) other directories. - - name: Install Rust + # Note that it can handle the Rust cache automatically (via Swatinem/rust-cache). + - name: Install Rust and setup Rust cache uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 with: toolchain: stable, nightly-2025-01-06 From c4ddcec6c874f93f23f24ea40aace64cffda74b0 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 17:12:21 +0300 Subject: [PATCH 30/44] WIP --- .github/workflows/pre-commit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index d560c1bb..58621006 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -42,6 +42,7 @@ jobs: toolchain: stable, nightly-2025-01-06 override: true components: rustfmt, clippy + cache-shared-key: v1-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }} # Install Rust tools # From 28839694b645252eb8c5d1b0d20feabcce911155 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 17:45:58 +0300 Subject: [PATCH 31/44] WIP --- .github/workflows/pre-commit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 58621006..dd9e4fab 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -47,6 +47,7 @@ jobs: # Install Rust tools # # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md + - name: Install Rust tools uses: taiki-e/install-action@v2 with: From 938d85753536fc238a888875d7b8e9909b4f40ee Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 23:24:29 +0300 Subject: [PATCH 32/44] WIP --- .github/workflows/pre-commit.yml | 9 +++++---- .pre-commit/.just | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index dd9e4fab..7f2ae34b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -27,7 +27,9 @@ env: jobs: run-pre-commit: name: Run pre-commit checks - runs-on: ubuntu-latest + # arm64 runners are faster + # See: https://github.blog/changelog/2025-01-16-linux-arm64-hosted-runners-now-available-for-free-in-public-repositories-public-preview/ + runs-on: ubuntu-latest-arm64 steps: - name: Check out repository code uses: actions/checkout@v4 @@ -39,15 +41,14 @@ jobs: - name: Install Rust and setup Rust cache uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 with: - toolchain: stable, nightly-2025-01-06 + toolchain: nightly-2025-01-06, stable override: true components: rustfmt, clippy - cache-shared-key: v1-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }} + cache-shared-key: v2-${{ github.repository_id }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }} # Install Rust tools # # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md - - name: Install Rust tools uses: taiki-e/install-action@v2 with: diff --git a/.pre-commit/.just b/.pre-commit/.just index 22448d10..3f6081f1 100644 --- a/.pre-commit/.just +++ b/.pre-commit/.just @@ -71,13 +71,13 @@ check-container-runtime: # cargo clippy --all-targets --all-features cargo-clippy: _check-cargo - cargo clippy --all-targets --all-features + cargo clippy --locked --all-targets --all-features # TODO: Perhaps consider this stricter version in the future. # cargo clippy --all-targets --all-features -- -D warnings cargo-clippy-strict: _check-cargo - cargo clippy --all-targets --all-features -- -D warnings + cargo clippy --locked --all-targets --all-features -- -D warnings # cargo nextest run --locked --no-run --workspace --all-features --bins --examples --tests @@ -193,7 +193,7 @@ typos: _check-typos test-cli-completions: #!/usr/bin/env bash - source <(cargo +stable run --package nexus-cli completion bash) + source <(cargo +stable run --locked --package nexus-cli completion bash) executable-scripts: #!/usr/bin/env bash From d104c2c0d04f1e3798a89f417f091949cf68c552 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Mon, 4 Aug 2025 23:55:32 +0300 Subject: [PATCH 33/44] WIP --- .github/workflows/pre-commit.yml | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 7f2ae34b..58926fa9 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -26,10 +26,8 @@ env: jobs: run-pre-commit: - name: Run pre-commit checks - # arm64 runners are faster - # See: https://github.blog/changelog/2025-01-16-linux-arm64-hosted-runners-now-available-for-free-in-public-repositories-public-preview/ - runs-on: ubuntu-latest-arm64 + name: Run pre-commit hook + runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v4 @@ -44,7 +42,13 @@ jobs: toolchain: nightly-2025-01-06, stable override: true components: rustfmt, clippy - cache-shared-key: v2-${{ github.repository_id }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }} + cache-shared-key: v2-${{ github.repository_id }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml', '**/build.rs') }} + cache-directories: | + ~/.cache/sccache + + # Print cache key + - name: Print cache key + run: echo "v2-${{ github.repository_id }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml', '**/build.rs') }}" # Install Rust tools # @@ -52,14 +56,25 @@ jobs: - name: Install Rust tools uses: taiki-e/install-action@v2 with: - tool: cargo-binstall,just,cargo-nextest,typos + tool: sccache,cargo-binstall,just,cargo-nextest,typos + + # Enable sccache + - name: Enable sccache + run: | + echo "export RUSTC_WRAPPER=$(command -v sccache)" >> $GITHUB_ENV + echo "export CARGO_TARGET_DIR=target" >> $GITHUB_ENV + echo "export SCCACHE_DIR=~/.cache/sccache" >> $GITHUB_ENV + # Install NPM stuff from helpers/npm-install-g.txt - name: Install NPM stuff from helpers/npm-install-g.txt run: ./helpers/npm-install-g.sh - # Just print some versions + # Just print some versions & stuff - run: cargo +stable --version && cargo +nightly-2025-01-06 --version + - run: | + echo "Contents of: $$GITHUB_ENV" + cat $GITHUB_ENV # Finally, run the pre-commit hook - run: ./.pre-commit/pre-commit From 6d71b57a8dffe1f777eb93f8159a1d8c0b35d42d Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 00:01:04 +0300 Subject: [PATCH 34/44] WIP --- .github/workflows/pre-commit.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 58926fa9..f23c57b0 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -62,7 +62,6 @@ jobs: - name: Enable sccache run: | echo "export RUSTC_WRAPPER=$(command -v sccache)" >> $GITHUB_ENV - echo "export CARGO_TARGET_DIR=target" >> $GITHUB_ENV echo "export SCCACHE_DIR=~/.cache/sccache" >> $GITHUB_ENV @@ -73,10 +72,8 @@ jobs: # Just print some versions & stuff - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - run: | - echo "Contents of: $$GITHUB_ENV" + echo "Contents of: $GITHUB_ENV" cat $GITHUB_ENV # Finally, run the pre-commit hook - run: ./.pre-commit/pre-commit - env: - CARGO_INCREMENTAL: 1 From e45f6cc4fa8d1c08eac468cbc414575e714c036d Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 00:04:09 +0300 Subject: [PATCH 35/44] WIP --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index f23c57b0..5a35a6da 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,7 +44,7 @@ jobs: components: rustfmt, clippy cache-shared-key: v2-${{ github.repository_id }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml', '**/build.rs') }} cache-directories: | - ~/.cache/sccache + $HOME/.cache/sccache # Print cache key - name: Print cache key From 5ade59d5cdcd4abf061d3b1a52db2f34e12e83ce Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 00:48:00 +0300 Subject: [PATCH 36/44] WIP --- .github/workflows/pre-commit.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5a35a6da..c671d8ab 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -42,13 +42,9 @@ jobs: toolchain: nightly-2025-01-06, stable override: true components: rustfmt, clippy - cache-shared-key: v2-${{ github.repository_id }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml', '**/build.rs') }} + cache-shared-key: v3-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml', '**/build.rs') }} cache-directories: | - $HOME/.cache/sccache - - # Print cache key - - name: Print cache key - run: echo "v2-${{ github.repository_id }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml', '**/build.rs') }}" + ~/.cache/sccache # Install Rust tools # @@ -69,11 +65,16 @@ jobs: - name: Install NPM stuff from helpers/npm-install-g.txt run: ./helpers/npm-install-g.sh - # Just print some versions & stuff + # Print stable,nightly versions - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - - run: | - echo "Contents of: $GITHUB_ENV" - cat $GITHUB_ENV # Finally, run the pre-commit hook - - run: ./.pre-commit/pre-commit + - run: | + echo $RUSTC_WRAPPER + echo $SCCACHE_DIR + echo "Running pre-commit hook..." + ./.pre-commit/pre-commit + + # Show sccache stats + - name: Show sccache stats + run: sccache --show-stats From cde97ca848cf45845ec92f15f18133afc6bbbacf Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 01:09:30 +0300 Subject: [PATCH 37/44] WIP --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index c671d8ab..a6851a61 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -42,7 +42,7 @@ jobs: toolchain: nightly-2025-01-06, stable override: true components: rustfmt, clippy - cache-shared-key: v3-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml', '**/build.rs') }} + cache-shared-key: v4-${{ hashFiles('**/build.rs') }} cache-directories: | ~/.cache/sccache From bc318b243d9f16a1865a6ef040955be1ffcc8152 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 12:55:13 +0300 Subject: [PATCH 38/44] WIP --- .pre-commit/.just | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit/.just b/.pre-commit/.just index 3f6081f1..dd90d707 100644 --- a/.pre-commit/.just +++ b/.pre-commit/.just @@ -32,7 +32,7 @@ check-container-runtime: # We of course assume the (test) code is written in a # container runtime agnostic way but this will require some # investigation, so: - # TODO: https://github.com/Talus-Network/nexus-sdk/issues/262 + # NOTE: https://github.com/Talus-Network/nexus-sdk/issues/262 runtimes=(docker podman) # colima etc ... check_commands=( From 7d9ad26cc9d51ab901c8e80c7d493a0265c099e0 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 13:22:06 +0300 Subject: [PATCH 39/44] WIP --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a6851a61..654a384e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,7 +44,7 @@ jobs: components: rustfmt, clippy cache-shared-key: v4-${{ hashFiles('**/build.rs') }} cache-directories: | - ~/.cache/sccache + /home/runner/.cache/sccache # Install Rust tools # From ac5ad6c6ec7ebb19f28cb90edcc5dce88ecc4d78 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 13:42:15 +0300 Subject: [PATCH 40/44] WIP --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 654a384e..cd835cd4 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,7 +44,7 @@ jobs: components: rustfmt, clippy cache-shared-key: v4-${{ hashFiles('**/build.rs') }} cache-directories: | - /home/runner/.cache/sccache + ${{ env.HOME }}/.cache/sccache # Install Rust tools # From 7c8c000b43b6c36d12e72481e964b7c3de851fa7 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Tue, 5 Aug 2025 14:06:54 +0300 Subject: [PATCH 41/44] WIP --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index cd835cd4..654a384e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,7 +44,7 @@ jobs: components: rustfmt, clippy cache-shared-key: v4-${{ hashFiles('**/build.rs') }} cache-directories: | - ${{ env.HOME }}/.cache/sccache + /home/runner/.cache/sccache # Install Rust tools # From 96ed9725a10361312c7d3bfb31e010c4c26ef187 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Wed, 6 Aug 2025 23:57:02 +0300 Subject: [PATCH 42/44] WIP --- .github/workflows/pre-commit.yml | 80 --------------------- .github/workflows/pre-commit_(PR).yml | 95 +++++++++++++++++++++++++ .github/workflows/pre-commit_(main).yml | 87 ++++++++++++++++++++++ 3 files changed, 182 insertions(+), 80 deletions(-) delete mode 100644 .github/workflows/pre-commit.yml create mode 100644 .github/workflows/pre-commit_(PR).yml create mode 100644 .github/workflows/pre-commit_(main).yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml deleted file mode 100644 index 654a384e..00000000 --- a/.github/workflows/pre-commit.yml +++ /dev/null @@ -1,80 +0,0 @@ -# GitHub workflow to run the pre-commit hook. - -name: Pre-commit hook -on: - pull_request: - push: - branches: - - main - -# NOTE: The following values seem to be a fix for OOM, in case they are needed again. -# -# RUST_CACHE_VERBOSE: true -# CARGO_BUILD_JOBS: 1 -# CARGO_INCREMENTAL: 0 -# RUSTFLAGS: > -# -C codegen-units=1 -# -# but we have reverted CARGO_INCREMENTAL to 1 to speed up builds. -env: - RUST_CACHE_VERBOSE: true - CARGO_BUILD_JOBS: 1 - CARGO_INCREMENTAL: 1 # NOTE: unfortunately this does not propagate to steps below. - RUSTFLAGS: > - -C codegen-units=1 - - -jobs: - run-pre-commit: - name: Run pre-commit hook - runs-on: ubuntu-latest - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - # Install Rust - # - # See: https://github.com/actions-rust-lang/setup-rust-toolchain - # Note that it can handle the Rust cache automatically (via Swatinem/rust-cache). - - name: Install Rust and setup Rust cache - uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 - with: - toolchain: nightly-2025-01-06, stable - override: true - components: rustfmt, clippy - cache-shared-key: v4-${{ hashFiles('**/build.rs') }} - cache-directories: | - /home/runner/.cache/sccache - - # Install Rust tools - # - # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md - - name: Install Rust tools - uses: taiki-e/install-action@v2 - with: - tool: sccache,cargo-binstall,just,cargo-nextest,typos - - # Enable sccache - - name: Enable sccache - run: | - echo "export RUSTC_WRAPPER=$(command -v sccache)" >> $GITHUB_ENV - echo "export SCCACHE_DIR=~/.cache/sccache" >> $GITHUB_ENV - - - # Install NPM stuff from helpers/npm-install-g.txt - - name: Install NPM stuff from helpers/npm-install-g.txt - run: ./helpers/npm-install-g.sh - - # Print stable,nightly versions - - run: cargo +stable --version && cargo +nightly-2025-01-06 --version - - # Finally, run the pre-commit hook - - run: | - echo $RUSTC_WRAPPER - echo $SCCACHE_DIR - echo "Running pre-commit hook..." - ./.pre-commit/pre-commit - - # Show sccache stats - - name: Show sccache stats - run: sccache --show-stats diff --git a/.github/workflows/pre-commit_(PR).yml b/.github/workflows/pre-commit_(PR).yml new file mode 100644 index 00000000..95342c7a --- /dev/null +++ b/.github/workflows/pre-commit_(PR).yml @@ -0,0 +1,95 @@ +name: Pre-commit hook (PR) +on: + pull_request: + +# Fix for OOM. +env: + RUST_CACHE_VERBOSE: true + CARGO_BUILD_JOBS: 1 + CARGO_INCREMENTAL: 0 + RUSTFLAGS: > + -C codegen-units=1 + +jobs: + run-pre-commit: + name: Run pre-commit hook (PR branch) + runs-on: ubuntu-latest + steps: + - name: Get architecture + id: get-arch + run: echo "ARCH=$(uname -m)" >> $GITHUB_OUTPUT + + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Compute cache keys + id: cache-keys + run: | + # `main` branch cache keys + echo "MAIN_CACHE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_OUTPUT + echo "MAIN_CACHE_RESTORE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-" >> $GITHUB_OUTPUT + ## Older key -- Delete once this PR is in main and the cache is updated according to MAIN_CACHE_KEY + echo "MAIN_CACHE_RESTORE_KEY0=v6-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-" >> $GITHUB_OUTPUT + # `pr` branch cache keys + echo "PR_CACHE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-PR-${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_OUTPUT + echo "PR_CACHE_RESTORE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-PR-" >> $GITHUB_OUTPUT + ## Older key -- Delete once this PR is in main and the cache is updated according to PR_CACHE_KEY + echo "PR_CACHE_RESTORE_KEY0=v6-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-" >> $GITHUB_OUTPUT + + # Restoring the PR cache takes into account: + # + # 1. The PR cache itself, which is used to speed up the PR development cycle. + # 2. In case the above is missing, the main branch cache, which is used to bootstrap the PR cache. + - name: Restore cache (PR) + id: cache-restore + uses: actions/cache/restore@v4.2.3 + with: + key: ${{ steps.cache-keys.outputs.PR_CACHE_KEY }} + restore-keys: | + ${{ steps.cache-keys.outputs.PR_CACHE_RESTORE_KEY }} + ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY }} + ${{ steps.cache-keys.outputs.PR_CACHE_RESTORE_KEY0 }} + ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY0 }} + + path: | + ~/.cache/sccache + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/work/**/target + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 + with: + toolchain: nightly-2025-01-06, stable + override: true + components: rustfmt, clippy + cache: 'false' + + - name: Install Rust tools + uses: taiki-e/install-action@v2.57.8 + with: + tool: cargo-binstall,just,cargo-nextest,typos + + - name: Install NPM stuff from helpers/npm-install-g.txt + run: ./helpers/npm-install-g.sh + + # Here it is ... + - name: Run pre-commit hook + run: ./.pre-commit/pre-commit + + - name: Save cache (PR) + uses: actions/cache/save@v4.2.3 + if: ${{ always() }} + with: + key: ${{ steps.cache-restore.outputs.cache-primary-key }} + path: | + ~/.cache/sccache + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/work/**/target diff --git a/.github/workflows/pre-commit_(main).yml b/.github/workflows/pre-commit_(main).yml new file mode 100644 index 00000000..599d8c79 --- /dev/null +++ b/.github/workflows/pre-commit_(main).yml @@ -0,0 +1,87 @@ +name: Pre-commit hook (main) +on: + push: + branches: + - main + +# Fix for OOM. +env: + RUST_CACHE_VERBOSE: true + CARGO_BUILD_JOBS: 1 + CARGO_INCREMENTAL: 0 + RUSTFLAGS: > + -C codegen-units=1 + +jobs: + run-pre-commit: + name: Run pre-commit hook (main branch) + runs-on: ubuntu-latest + steps: + - name: Get architecture + id: get-arch + run: echo "ARCH=$(uname -m)" >> $GITHUB_OUTPUT + + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Compute cache keys + id: cache-keys + run: | + echo "MAIN_CACHE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_OUTPUT + echo "MAIN_CACHE_RESTORE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-" >> $GITHUB_OUTPUT + # Older key -- Delete once this PR is in main and the cache is updated according to MAIN_CACHE_KEY + echo "MAIN_CACHE_RESTORE_KEY0=v6-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-" >> $GITHUB_OUTPUT + + # Useful docs: + # - https://github.com/actions/cache/blob/main/caching-strategies.md + - name: Restore cache (main) + id: cache-restore + uses: actions/cache/restore@v4.2.3 + with: + key: ${{ steps.cache-keys.outputs.MAIN_CACHE_KEY }} + restore-keys: | + ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY }} + ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY0 }} + path: | + ~/.cache/sccache + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/work/**/target + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 + with: + toolchain: nightly-2025-01-06, stable + override: true + components: rustfmt, clippy + cache: 'false' + + # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md + - name: Install Rust tools + uses: taiki-e/install-action@v2.57.8 + with: + tool: cargo-binstall,just,cargo-nextest,typos + + - name: Install NPM stuff from helpers/npm-install-g.txt + run: ./helpers/npm-install-g.sh + + # Here it is ... + - name: Run pre-commit hook + run: ./.pre-commit/pre-commit + + - name: Save cache (main) + uses: actions/cache/save@v4.2.3 + if: ${{ always() }} + with: + key: ${{ steps.cache-restore.outputs.cache-primary-key }} + path: | + ~/.cache/sccache + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/work/**/target From bae9eaefc418860b0deedb7772f0a08e52cf4806 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 8 Aug 2025 10:28:54 +0300 Subject: [PATCH 43/44] WIP --- .github/actions/cache/restore/action.yml | 30 ++++++++++++ .github/actions/cache/save/action.yml | 21 +++++++++ .../pre-commit/dependencies/action.yml | 23 +++++++++ .github/workflows/pre-commit_(PR).yml | 47 +++---------------- .github/workflows/pre-commit_(main).yml | 47 ++++--------------- 5 files changed, 89 insertions(+), 79 deletions(-) create mode 100644 .github/actions/cache/restore/action.yml create mode 100644 .github/actions/cache/save/action.yml create mode 100644 .github/actions/pre-commit/dependencies/action.yml diff --git a/.github/actions/cache/restore/action.yml b/.github/actions/cache/restore/action.yml new file mode 100644 index 00000000..609c61cf --- /dev/null +++ b/.github/actions/cache/restore/action.yml @@ -0,0 +1,30 @@ +name: Restore cache +description: Restore cache using actions/cache/restore +inputs: + key: + description: 'An explicit key for restoring the cache' + required: true + restore-keys: + description: 'An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' + required: true +outputs: + cache-primary-key: + description: 'A resolved cache key for which cache match was attempted' + value: ${{ steps.cache-action-restore.outputs.cache-primary-key }} + +runs: + using: "composite" + steps: + - id: cache-action-restore + uses: actions/cache/restore@v4.2.3 + with: + key: ${{ inputs.key }} + restore-keys: ${{ inputs.restore-keys }} + path: | + ~/.cache/sccache + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/work/**/target diff --git a/.github/actions/cache/save/action.yml b/.github/actions/cache/save/action.yml new file mode 100644 index 00000000..caab50cc --- /dev/null +++ b/.github/actions/cache/save/action.yml @@ -0,0 +1,21 @@ +name: Save cache +description: Save cache using actions/cache/save +inputs: + key: + description: 'An explicit key for saving the cache' + required: true + +runs: + using: "composite" + steps: + - uses: actions/cache/save@v4.2.3 + with: + key: ${{ inputs.key }} + path: | + ~/.cache/sccache + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/work/**/target diff --git a/.github/actions/pre-commit/dependencies/action.yml b/.github/actions/pre-commit/dependencies/action.yml new file mode 100644 index 00000000..5d939944 --- /dev/null +++ b/.github/actions/pre-commit/dependencies/action.yml @@ -0,0 +1,23 @@ +name: Install pre-commit dependencies +description: Install pre-commit dependencies + +runs: + using: "composite" + steps: + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 + with: + toolchain: nightly-2025-01-06, stable + override: true + components: rustfmt, clippy + cache: 'false' + + # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md + - name: Install Rust tools + uses: taiki-e/install-action@v2.57.8 + with: + tool: cargo-binstall,just,cargo-nextest,typos + + - name: Install NPM stuff from helpers/npm-install-g.txt + shell: bash + run: ./helpers/npm-install-g.sh diff --git a/.github/workflows/pre-commit_(PR).yml b/.github/workflows/pre-commit_(PR).yml index 95342c7a..9b92956d 100644 --- a/.github/workflows/pre-commit_(PR).yml +++ b/.github/workflows/pre-commit_(PR).yml @@ -10,6 +10,7 @@ env: RUSTFLAGS: > -C codegen-units=1 + jobs: run-pre-commit: name: Run pre-commit hook (PR branch) @@ -28,13 +29,9 @@ jobs: # `main` branch cache keys echo "MAIN_CACHE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_OUTPUT echo "MAIN_CACHE_RESTORE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-" >> $GITHUB_OUTPUT - ## Older key -- Delete once this PR is in main and the cache is updated according to MAIN_CACHE_KEY - echo "MAIN_CACHE_RESTORE_KEY0=v6-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-" >> $GITHUB_OUTPUT - # `pr` branch cache keys + # PR branch cache keys echo "PR_CACHE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-PR-${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_OUTPUT echo "PR_CACHE_RESTORE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-PR-" >> $GITHUB_OUTPUT - ## Older key -- Delete once this PR is in main and the cache is updated according to PR_CACHE_KEY - echo "PR_CACHE_RESTORE_KEY0=v6-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-" >> $GITHUB_OUTPUT # Restoring the PR cache takes into account: # @@ -42,54 +39,22 @@ jobs: # 2. In case the above is missing, the main branch cache, which is used to bootstrap the PR cache. - name: Restore cache (PR) id: cache-restore - uses: actions/cache/restore@v4.2.3 + uses: ./.github/actions/cache/restore with: key: ${{ steps.cache-keys.outputs.PR_CACHE_KEY }} restore-keys: | ${{ steps.cache-keys.outputs.PR_CACHE_RESTORE_KEY }} ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY }} - ${{ steps.cache-keys.outputs.PR_CACHE_RESTORE_KEY0 }} - ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY0 }} - - path: | - ~/.cache/sccache - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/work/**/target - - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 - with: - toolchain: nightly-2025-01-06, stable - override: true - components: rustfmt, clippy - cache: 'false' - - - name: Install Rust tools - uses: taiki-e/install-action@v2.57.8 - with: - tool: cargo-binstall,just,cargo-nextest,typos - - name: Install NPM stuff from helpers/npm-install-g.txt - run: ./helpers/npm-install-g.sh + - name: Install pre-commit dependencies + uses: ./.github/actions/pre-commit/dependencies # Here it is ... - name: Run pre-commit hook run: ./.pre-commit/pre-commit - name: Save cache (PR) - uses: actions/cache/save@v4.2.3 + uses: ./.github/actions/cache/save if: ${{ always() }} with: key: ${{ steps.cache-restore.outputs.cache-primary-key }} - path: | - ~/.cache/sccache - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/work/**/target diff --git a/.github/workflows/pre-commit_(main).yml b/.github/workflows/pre-commit_(main).yml index 599d8c79..88ee2859 100644 --- a/.github/workflows/pre-commit_(main).yml +++ b/.github/workflows/pre-commit_(main).yml @@ -27,61 +27,32 @@ jobs: - name: Compute cache keys id: cache-keys run: | + # `main` branch cache keys echo "MAIN_CACHE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_OUTPUT echo "MAIN_CACHE_RESTORE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-main-" >> $GITHUB_OUTPUT - # Older key -- Delete once this PR is in main and the cache is updated according to MAIN_CACHE_KEY - echo "MAIN_CACHE_RESTORE_KEY0=v6-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-" >> $GITHUB_OUTPUT + # PR branch cache keys + echo "PR_CACHE_RESTORE_KEY=v7-${{ runner.os }}-${{ steps.get-arch.outputs.ARCH }}-PR-" >> $GITHUB_OUTPUT - # Useful docs: - # - https://github.com/actions/cache/blob/main/caching-strategies.md - name: Restore cache (main) id: cache-restore - uses: actions/cache/restore@v4.2.3 + uses: ./.github/actions/cache/restore with: key: ${{ steps.cache-keys.outputs.MAIN_CACHE_KEY }} restore-keys: | ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY }} ${{ steps.cache-keys.outputs.MAIN_CACHE_RESTORE_KEY0 }} - path: | - ~/.cache/sccache - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/work/**/target + ${{ steps.cache-keys.outputs.PR_CACHE_RESTORE_KEY }} - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 - with: - toolchain: nightly-2025-01-06, stable - override: true - components: rustfmt, clippy - cache: 'false' - - # For more tools, see: https://github.com/taiki-e/install-action/blob/main/TOOLS.md - - name: Install Rust tools - uses: taiki-e/install-action@v2.57.8 - with: - tool: cargo-binstall,just,cargo-nextest,typos - - - name: Install NPM stuff from helpers/npm-install-g.txt - run: ./helpers/npm-install-g.sh + - name: Install pre-commit dependencies + uses: ./.github/actions/pre-commit/dependencies # Here it is ... - name: Run pre-commit hook run: ./.pre-commit/pre-commit + - name: Save cache (main) - uses: actions/cache/save@v4.2.3 + uses: ./.github/actions/cache/save if: ${{ always() }} with: key: ${{ steps.cache-restore.outputs.cache-primary-key }} - path: | - ~/.cache/sccache - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/work/**/target From de1289607883340652ca0b385b8f2d76ddca623f Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Fri, 8 Aug 2025 10:52:56 +0300 Subject: [PATCH 44/44] WIP --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ba4e126..7061078e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - CONTRIBUTING.md - CODE_OF_CONDUCT.md -- `pre-commit` hook +- `pre-commit` hook (also in CI) ### `nexus-cli`