From 5511404f551e20678443ccd940635b6af4bd329d Mon Sep 17 00:00:00 2001 From: STEVAN Antoine <antoine.stevan@isae-supaero.fr> Date: Wed, 29 Jan 2025 14:13:23 +0000 Subject: [PATCH] refactor CI and Makefile for Nushell installation (dragoon/komodo!192) the idea is to make the installation of Nushell easier to maintain, especially regarding versions, currently pinned to `0.95.0` > successful run on GitHub: [13032726635](https://github.com/dragoon-rs/komodo/actions/runs/13032726635) this is also to allow easier testing locally with the same Nushell version as in the CI, e.g. ```bash # install in `~/.local/bin/` and have multiple versions make install-nu hash=$(/tmp/nu --no-config-file --commands 'version | get commit_hash') nu_bin=$"$HOME/.local/bin/nu-$hash" cp /tmp/nu $nu_bin make NU=$nu_bin show test ``` or ```bash # install in the repo and overwrite each time make NU_DEST=. install-nu make NU=./nu show test ``` # changelog - Makefile - split the global `.PHONY` rule into _atomic_ rules next to each _phony_ rule - define `NU` and `NU_FLAGS` to allow changing which and how Nushell runs - define `NU_ARCH`, `NU_VERSION`, `NU_BUILD` and `NU_DEST` for Nushell installation - tweak the output of `make show` a bit - add `print-%` rules to print `Makefile` variables, e.g. `make print-NU_FLAGS` would print `--no-config-file` - add `make install-nu` to replace the ones from the CIs - GitLab CI - use `make install-nu` - export `PATH` with `make print-NU_DEST` - GitHub CI - use `make install-nu` instead of [github.com:hustcer/setup-nu](https://github.com/hustcer/setup-nu) - export `PATH` with `make print-NU_DEST` and `GITHUB_ENV` --- .github/workflows/ci.yml | 12 ++++++---- .gitlab-ci.yml | 15 ++---------- Makefile | 49 +++++++++++++++++++++++++++++++--------- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23eb542d..3299c954 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,11 +31,13 @@ jobs: sudo apt update --yes sudo apt upgrade --yes sudo apt install protobuf-compiler --yes - - uses: hustcer/setup-nu@v3 - with: - version: "0.95" + - name: Install Nushell + run: | + # looks like the following PATH export does not work and `NU` still needs to be set for some reason to invoke `make`... + echo "PATH=\"$(make print-NU_DEST):$PATH\"" >> $GITHUB_ENV + make install-nu - name: Show configuration - run: make show + run: make NU="$(make print-NU_DEST)/nu" show - name: Run tests run: | - make check clippy test example + make NU="$(make print-NU_DEST)/nu" check clippy test example diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8377911e..625f83b2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,10 +4,6 @@ stages: - fmt - test -variables: - NUSHELL_ARCH: "x86_64-unknown-linux-musl" - NUSHELL_VERSION: "0.95.0" - workflow: rules: - if: $CI_COMMIT_MESSAGE =~ /^(draft|no-ci):/ @@ -31,15 +27,8 @@ test: - apt update --yes - apt upgrade --yes - apt install protobuf-compiler --yes - - - export NUSHELL_BUILD="nu-$NUSHELL_VERSION-$NUSHELL_ARCH" - - export PATH="/tmp/:$PATH" - - # install Nushell - - curl -fLo /tmp/nu.tar.gz "https://github.com/nushell/nushell/releases/download/$NUSHELL_VERSION/$NUSHELL_BUILD.tar.gz" - - tar xvf /tmp/nu.tar.gz --directory /tmp - - cp "/tmp/$NUSHELL_BUILD/nu" /tmp/nu - + - export PATH="$(make print-NU_DEST):$PATH" + - make install-nu - make show script: diff --git a/Makefile b/Makefile index 79b06bb6..2a89ea42 100644 --- a/Makefile +++ b/Makefile @@ -1,46 +1,73 @@ -.PHONY: fmt fmt-check check clippy test-rs test-nu test example show doc build-examples +NU="nu" +NU_FLAGS="--no-config-file" + +NU_ARCH="x86_64-unknown-linux-musl" +NU_VERSION="0.95.0" +NU_BUILD="nu-${NU_VERSION}-${NU_ARCH}" +NU_DEST="/tmp/" DEFAULT_GOAL: fmt-check check clippy test-rs +.PHONY: fmt-check fmt-check: cargo fmt --all -- --check +.PHONY: fmt fmt: cargo fmt --all +.PHONY: install-nu +install-nu: + mkdir -p "${NU_DEST}" + curl -fLo "${NU_DEST}/nu.tar.gz" "https://github.com/nushell/nushell/releases/download/${NU_VERSION}/${NU_BUILD}.tar.gz" + tar xvf "${NU_DEST}/nu.tar.gz" --directory "${NU_DEST}" + cp "${NU_DEST}/${NU_BUILD}/nu" "${NU_DEST}/nu" + +.PHONY: check check: - nu scripts/check-nushell-files.nu + ${NU} ${NU_FLAGS} scripts/check-nushell-files.nu cargo check --workspace --all-targets cargo check --workspace --all-targets --features kzg cargo check --workspace --all-targets --features aplonk cargo check --workspace --all-targets --all-features +.PHONY: clippy clippy: cargo clippy --workspace --all-targets --all-features -- -D warnings +.PHONY: test-rs test-rs: cargo test --workspace --verbose --all-features cargo test --examples --verbose +.PHONY: test-nu test-nu: - nu bins/saclin/tests/cli.nu - nu bins/saclin/tests/binary.nu + ${NU} ${NU_FLAGS} bins/saclin/tests/cli.nu + ${NU} ${NU_FLAGS} bins/saclin/tests/binary.nu +.PHONY: test test: test-rs test-nu +.PHONY: example example: - nu bins/saclin/examples/cli.nu + ${NU} ${NU_FLAGS} bins/saclin/examples/cli.nu +.PHONY: show show: - rustup --version - rustup show --verbose - rustc --version - cargo --version - cargo clippy --version - nu --version + @rustup --version 2> /dev/null + @rustup show active-toolchain + @rustc --version + @cargo --version + @cargo clippy --version + @${NU} ${NU_FLAGS} --commands "version" +.PHONY: doc doc: cargo doc --document-private-items --no-deps --open +.PHONY: build-examples build-examples: cargo build --examples --release + +print-%: + @echo $($*) -- GitLab