From 8c80c9b94a65577fa3d8c34886385066c0613400 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Thu, 2 Nov 2023 19:30:07 +0100 Subject: [PATCH] ci/Speed up typos checks (#907) --- .github/workflows/test.yml | 16 +++++++++++++++- burn-autodiff/src/graph/base.rs | 2 +- burn-autodiff/src/utils.rs | 2 +- burn-tensor/src/tensor/backend/mod.rs | 2 +- burn-train/src/metric/base.rs | 2 +- burn-train/src/metric/state.rs | 2 +- run-checks.ps1 | 2 +- run-checks.sh | 2 +- xtask/src/publish.rs | 6 +----- xtask/src/runchecks.rs | 15 +++++++++++++-- 10 files changed, 36 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1987e6050..7fe0d8240 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -116,5 +116,19 @@ jobs: - name: checkout uses: actions/checkout@v4 + - name: caching + uses: Swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-typos-${{ hashFiles('**/Cargo.toml') }} + prefix-key: "v5-rust" + + - name: Install typos + env: + TYPOS_LINK: https://github.com/crate-ci/typos/releases/download + TYPOS_VERSION: v1.16.20 + run: | + curl -L "$TYPOS_LINK/$TYPOS_VERSION/typos-$TYPOS_VERSION-x86_64-unknown-linux-musl.tar.gz" | + tar xz -C $HOME/.cargo/bin + - name: run spelling checks using typos - run: cargo xtask run-checks typos + run: CI_RUN=1 cargo xtask run-checks typos diff --git a/burn-autodiff/src/graph/base.rs b/burn-autodiff/src/graph/base.rs index 31685e686..1e8e989f3 100644 --- a/burn-autodiff/src/graph/base.rs +++ b/burn-autodiff/src/graph/base.rs @@ -37,7 +37,7 @@ impl Graph { /// This is a owned method, so the current graph will be freed. However, the steps can /// be shared with other graphs, therefore they are going to be cleared. /// - /// This is usefull, since the graph is supposed to be consumed only once for backprop, and + /// This is useful, since the graph is supposed to be consumed only once for backprop, and /// keeping all the tensors alive for multiple backward call is a heavy waste of resources. pub fn steps(self) -> NodeSteps { let mut map_drain = HashMap::new(); diff --git a/burn-autodiff/src/utils.rs b/burn-autodiff/src/utils.rs index 2cc856cd3..617c101e2 100644 --- a/burn-autodiff/src/utils.rs +++ b/burn-autodiff/src/utils.rs @@ -4,7 +4,7 @@ use crate::graph::NodeRef; /// /// # Notes /// -/// This is usefull since you don't have to keep N cloned references alive event if just 1 node +/// This is useful since you don't have to keep N cloned references alive event if just 1 node /// will be updated. /// /// If the object is a tensor and if one reference exists, it can be updated inplace. diff --git a/burn-tensor/src/tensor/backend/mod.rs b/burn-tensor/src/tensor/backend/mod.rs index b0253f480..303a2b526 100644 --- a/burn-tensor/src/tensor/backend/mod.rs +++ b/burn-tensor/src/tensor/backend/mod.rs @@ -1,5 +1,5 @@ mod base; pub use base::*; -// Not needed for now, usefull for different tensor memory layout +// Not needed for now, useful for different tensor memory layout // pub mod conversion; diff --git a/burn-train/src/metric/base.rs b/burn-train/src/metric/base.rs index d84c03951..1d0f2ca49 100644 --- a/burn-train/src/metric/base.rs +++ b/burn-train/src/metric/base.rs @@ -67,7 +67,7 @@ pub trait Adaptor { /// Declare a metric to be numeric. /// -/// This is usefull to plot the values of a metric during training. +/// This is useful to plot the values of a metric during training. pub trait Numeric { /// Returns the numeric value of the metric. fn value(&self) -> f64; diff --git a/burn-train/src/metric/state.rs b/burn-train/src/metric/state.rs index 567249275..9a188198d 100644 --- a/burn-train/src/metric/state.rs +++ b/burn-train/src/metric/state.rs @@ -1,6 +1,6 @@ use crate::metric::{format_float, MetricEntry, Numeric}; -/// Usefull utility to implement numeric metrics. +/// Useful utility to implement numeric metrics. /// /// # Notes /// diff --git a/run-checks.ps1 b/run-checks.ps1 index 297d20a60..b6fbfad55 100644 --- a/run-checks.ps1 +++ b/run-checks.ps1 @@ -3,7 +3,7 @@ # # Run `run-checks` using this command: # -# ./scripts/run-checks environment +# ./run-checks.ps1 environment # # where `environment` can assume **ONLY** the following values: # diff --git a/run-checks.sh b/run-checks.sh index feb7a20a8..55f8abb99 100755 --- a/run-checks.sh +++ b/run-checks.sh @@ -8,7 +8,7 @@ set -e # # Run `run-checks` using this command: # -# ./scripts/run-checks environment +# ./run-checks.sh environment # # where `environment` can assume **ONLY** the following values: # diff --git a/xtask/src/publish.rs b/xtask/src/publish.rs index 75dac293c..bff567216 100644 --- a/xtask/src/publish.rs +++ b/xtask/src/publish.rs @@ -1,12 +1,8 @@ //! This script publishes a crate on `crates.io`. //! -//! To build this script, run the following command: -//! -//! rustc scripts/publish.rs --crate-type bin --out-dir scripts -//! //! To run the script: //! -//! ./scripts/publish crate_name +//! cargo xtask publish INPUT_CRATE use std::env; use std::process::{Command, Stdio}; diff --git a/xtask/src/runchecks.rs b/xtask/src/runchecks.rs index 112049556..cf0c3364d 100644 --- a/xtask/src/runchecks.rs +++ b/xtask/src/runchecks.rs @@ -3,6 +3,7 @@ //! It is used to check that the code compiles and passes all tests. //! //! It is also used to check that the code is formatted correctly and passes clippy. + use std::env; use std::process::{Child, Command, Stdio}; use std::str; @@ -289,8 +290,18 @@ fn std_checks() { } fn check_typos() { - // Install typos-cli - cargo_install(["typos-cli", "--version", "1.16.5"].into()); + // This path defines where typos-cl is installed on different + // operating systems. + let typos_cli_path = std::env::var("CARGO_HOME") + .map(|v| std::path::Path::new(&v).join("bin/typos-cli")) + .unwrap(); + + // Do not run cargo install on CI to speed up the computation. + // Check whether the file has been installed on + if std::env::var("CI_RUN").is_err() && !typos_cli_path.exists() { + // Install typos-cli + cargo_install(["typos-cli", "--version", "1.16.5"].into()); + } println!("Running typos check \n\n");