closes #3 #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| pull_request: | |
| workflow_dispatch: | |
| schedule: [cron: "40 1 * * 0"] # run weekly | |
| permissions: | |
| contents: read | |
| jobs: | |
| tokei: | |
| name: Reasonable Amount of Comments | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install tokei | |
| run: | | |
| cargo install tokei | |
| - name: Run tokei and save output to json file | |
| run: tokei -o json > tokei_output.json | |
| - name: Install jq | |
| run: sudo apt-get install -y jq | |
| - name: Check Rust comments | |
| #TODO!!!!!!: Generalize to other languages. Want to dynamically determinee the most used language in the repo (excluding markdown, jupiter, etc.). | |
| run: | | |
| comments=$(jq '.Rust.comments' tokei_output.json) | |
| code=$(jq '.Rust.code' tokei_output.json) | |
| if [ $((comments * 10)) -ge $code ]; then | |
| echo "Number of comments should be less than 10% of code" | |
| exit 1 | |
| else | |
| echo "Check passed: Number of comments is less than 10% of code" | |
| fi | |
| pre_ci: | |
| uses: valeratrades/.github/.github/workflows/pre_ci.yml@master | |
| test: | |
| name: Rust ${{matrix.rust}} | |
| needs: pre_ci | |
| if: needs.pre_ci.outputs.continue | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| rust: [nightly, stable, nightly-2024-10-10] | |
| timeout-minutes: 45 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{matrix.rust}} | |
| # test this works | |
| - name: Set RUSTFLAGS for release branch | |
| run: echo "RUSTFLAGS=-Dwarnings" >> $GITHUB_ENV | |
| if: github.ref == 'refs/heads/release' | |
| - name: Enable type layout randomization | |
| run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout\ --cfg=exhaustive >> $GITHUB_ENV | |
| if: matrix.rust == 'nightly' | |
| - run: cargo update | |
| - run: cargo check | |
| - run: cargo test | |
| #TODO: figure this out | |
| # if: matrix.os == 'ubuntu' && matrix.rust == 'nightly' | |
| #- run: cargo run -- expand --manifest-path tests/Cargo.toml > expand.rs && diff tests/lib.expand.rs expand.rs | |
| doc: | |
| name: Documentation | |
| needs: pre_ci | |
| if: needs.pre_ci.outputs.continue | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| env: | |
| RUSTDOCFLAGS: -Dwarnings | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@nightly | |
| - uses: dtolnay/install@cargo-docs-rs | |
| - run: cargo docs-rs | |
| miri: | |
| name: Miri | |
| needs: pre_ci | |
| if: needs.pre_ci.outputs.continue | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@miri | |
| - run: cargo miri setup | |
| - run: cargo miri test | |
| env: | |
| MIRIFLAGS: -Zmiri-strict-provenance | |
| clippy: | |
| name: Clippy | |
| needs: pre_ci | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' | |
| timeout-minutes: 45 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@clippy | |
| - run: cargo clippy --tests -- -Dclippy::all #-Dclippy::pedantic | |
| sort: | |
| name: Cargo Sorted | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install cargo-sort | |
| run: | | |
| cargo install cargo-sort | |
| - name: Check if Cargo.toml is sorted | |
| run: | | |
| cargo sort -wc | |
| exit_code=$? | |
| if [ $exit_code != 0 ]; then | |
| echo "Cargo.toml is not sorted. Run `cargo sort -w` to fix it." | |
| exit $exit_code | |
| fi | |
| machete: | |
| name: Cargo Machete | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check for unused dependencies | |
| uses: bnjbvr/cargo-machete@main | |
| bad_practices: | |
| name: Bad Practices | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Ripgrep (rg) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ripgrep | |
| - name: tokio::spawn Check | |
| run: | | |
| results=$(rg -I --glob '!.git' 'tokio::spawn' . | awk '!/^[[:space:]]*\/\//') | |
| if [ -z "$results" ]; then | |
| echo "No instances of tokio::spawn found outside of comments." | |
| exit 0 | |
| else | |
| echo "WARNING: Found instances of tokio::spawn, switch all of them to JoinSet::spawn immediately:" | |
| echo "$results" | |
| exit 1 | |
| fi | |
| - name: Outdated error-handling crates | |
| run: | | |
| if rg -E 'anyhow|^eyre' Cargo.toml; then | |
| echo "WARNING: Found anyhow or eyre in Cargo.toml. Consider switching to color-eyre for improved error handling and reporting." | |
| echo "To switch, replace anyhow or eyre with color-eyre in your Cargo.toml and update your code accordingly." | |
| fi | |
| env: | |
| #RUSTFLAGS: -Dwarnings | |
| CARGO_INCREMENTAL: 0 # on large changes this just bloats ./target | |
| RUST_BACKTRACE: short | |
| CARGO_NET_RETRY: 10 | |
| RUSTUP_MAX_RETRIES: 10 |