From 6e0709ce622de84e0be6e411b0c3b54923f10e42 Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Mon, 3 Nov 2025 13:55:07 +0100 Subject: [PATCH] chore: make typos version fixed - add a script to properly install the correct version --- Makefile | 6 ++-- scripts/install_typos.sh | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100755 scripts/install_typos.sh diff --git a/Makefile b/Makefile index 998260e37..96c265250 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ WASM_PACK_VERSION="0.13.1" WASM_BINDGEN_VERSION:=$(shell cargo tree --target wasm32-unknown-unknown -e all --prefix none | grep "wasm-bindgen v" | head -n 1 | cut -d 'v' -f2) WEB_RUNNER_DIR=web-test-runner WEB_SERVER_DIR=tfhe/web_wasm_parallel_tests +TYPOS_VERSION=1.39.0 # This is done to avoid forgetting it, we still precise the RUSTFLAGS in the commands to be able to # copy paste the command in the terminal and change them if required without forgetting the flags export RUSTFLAGS?=-C target-cpu=native @@ -174,9 +175,8 @@ install_cargo_audit: install_rs_build_toolchain .PHONY: install_typos_checker # Install typos checker install_typos_checker: install_rs_build_toolchain - @typos --version > /dev/null 2>&1 || \ - cargo $(CARGO_RS_BUILD_TOOLCHAIN) install --locked typos-cli || \ - ( echo "Unable to install typos-cli, unknown error." && exit 1 ) + @./scripts/install_typos.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \ + --typos-version $(TYPOS_VERSION) .PHONY: install_zizmor # Install zizmor workflow security checker install_zizmor: install_rs_build_toolchain diff --git a/scripts/install_typos.sh b/scripts/install_typos.sh new file mode 100755 index 000000000..bba4396d6 --- /dev/null +++ b/scripts/install_typos.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +set -e + +rust_toolchain= +required_typos_version="" + +function usage() { + echo "$0: install typos-cli" + echo + echo "--help Print this message" + echo "--rust-toolchain The toolchain to use" + echo "--typos-version Version of typos-cli to install" + echo +} + +while [ -n "$1" ] +do + case "$1" in + "--rust-toolchain" ) + shift + rust_toolchain="$1" + ;; + + "--typos-version" ) + shift + required_typos_version="$1" + ;; + + *) + echo "Unknown param : $1" + exit 1 + ;; + esac + shift +done + +if [[ "${rust_toolchain::1}" != "+" ]]; then + rust_toolchain=${rust_toolchain:"+${rust_toolchain}"} +fi + +if ! which typos ; then + cargo ${rust_toolchain:+"$rust_toolchain"} install --locked typos-cli --version ~"${required_typos_version}" || \ + ( echo "Unable to install typos-cli, unknown error." && exit 1 ) + + exit 0 +fi + +ver_string="$(typos --version | cut -d ' ' -f 2)" + +ver_major="$(echo "${ver_string}" | cut -d '.' -f 1)" +ver_minor="$(echo "${ver_string}" | cut -d '.' -f 2)" + +min_ver_major="$(echo "${required_typos_version}" | cut -d '.' -f 1)" +min_ver_minor="$(echo "${required_typos_version}" | cut -d '.' -f 2)" + +if [[ "${ver_major}" -gt "${min_ver_major}" ]]; then + exit 0 +elif [[ "${ver_major}" -eq "${min_ver_major}" ]] && [[ "${ver_minor}" -ge "${min_ver_minor}" ]]; then + exit 0 +else + cargo ${rust_toolchain:+"$rust_toolchain"} install --locked typos-cli --version ~"${required_typos_version}" || \ + ( echo "Unable to install typos-cli, unknown error." && exit 1 ) +fi