CI #537
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 * * *"] | |
| permissions: | |
| contents: read | |
| env: | |
| #RUSTFLAGS: -Dwarnings | |
| RUST_BACKTRACE: short | |
| CARGO_NET_RETRY: 10 | |
| RUSTUP_MAX_RETRIES: 10 | |
| jobs: | |
| 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, nightly-2024-08-02] | |
| timeout-minutes: 45 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{matrix.rust}} | |
| - name: Download modified by pre-ci Cargo.toml files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: modified-cargo-files | |
| # 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' | |
| # not sure why dtolnay has this | |
| #- run: cargo check --locked | |
| - 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 | |
| - name: Download modified by pre-ci Cargo.toml files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: modified-cargo-files | |
| - run: RUSTDOCFLAGS="-Dwarnings" cargo doc --no-deps | |
| clippy: | |
| name: Clippy | |
| needs: pre_ci | |
| if: needs.pre_ci.outputs.continue && github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download modified by pre-ci Cargo.toml files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: modified-cargo-files | |
| - uses: dtolnay/rust-toolchain@clippy | |
| - run: cargo clippy --tests -- -Dclippy::all #-Dclippy::pedantic | |
| 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 | |
| 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 | |
| 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. Switch to color-eyre, it's always a superset." | |
| fi | |
| 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 |