ci.yml
1 env: 2 RUST_STABLE_VER: "1.86" 3 4 # Rationale 5 # 6 # We don't run clippy with --all-targets because then even --lib and --bins are compiled with 7 # dev dependencies enabled, which does not match how they would be compiled by users. 8 # A dev dependency might enable a feature that we need for a regular dependency, 9 # and checking with --all-targets would not find our feature requirements lacking. 10 # This problem still applies to cargo resolver version 2. 11 # Thus we split all the targets into two steps, one with --lib --bins 12 # and another with --tests --benches --examples. 13 # Also, we can't give --lib --bins explicitly because then cargo will error on binary-only packages. 14 # Luckily the default behavior of cargo with no explicit targets is the same but without the error. 15 # 16 # We use cargo-hack for a similar reason. Cargo's --workspace will do feature unification across 17 # the whole workspace. While cargo-hack will instead check each workspace package separately. 18 # 19 # Using cargo-hack also allows us to more easily test the feature matrix of our packages. 20 # We use --each-feature & --optional-deps which will run a separate check for every feature. 21 # 22 # The MSRV jobs run only cargo check because different clippy versions can disagree on goals and 23 # running tests introduces dev dependencies which may require a higher MSRV than the bare package. 24 # Checking is limited to packages that are intended for publishing to keep MSRV as low as possible. 25 # 26 # If the workspace uses debug_assertions then we verify code twice, with it set to true or false. 27 # We always keep it true for external dependencies so that we can reuse the cache for faster builds. 28 # 29 # We don't save caches in the merge-group cases, because those caches will never be re-used (apart 30 # from the very rare cases where there are multiple PRs in the merge queue). 31 # This is because GitHub doesn't share caches between merge queues and the main branch. 32 33 name: CI 34 35 on: 36 pull_request: 37 merge_group: 38 # We run on push, even though the commit is the same as when we ran in merge_group. 39 # This allows the cache to be primed. 40 # See https://github.com/orgs/community/discussions/66430 41 push: 42 branches: 43 - main 44 45 jobs: 46 fmt: 47 name: formatting 48 runs-on: ubuntu-latest 49 steps: 50 - name: Checkout repository 51 uses: actions/checkout@v4 52 53 - name: Install Rust ${{ env.RUST_STABLE_VER }} 54 uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b 55 with: 56 toolchain: ${{ env.RUST_STABLE_VER }} 57 components: rustfmt 58 59 - name: Run cargo fmt 60 run: cargo fmt --all --check 61 62 - name: Install Taplo 63 uses: uncenter/setup-taplo@09968a8ae38d66ddd3d23802c44bf6122d7aa991 # v1 64 with: 65 version: "0.9.3" 66 67 - name: Run taplo fmt 68 run: taplo fmt --check --diff 69 70 - name: Install ripgrep 71 run: | 72 sudo apt update 73 sudo apt install ripgrep 74 75 clippy-stable: 76 name: cargo clippy 77 runs-on: ${{ matrix.os }} 78 strategy: 79 matrix: 80 os: [windows-latest, macos-latest, ubuntu-latest] 81 steps: 82 - name: Checkout repository 83 uses: actions/checkout@v4 84 85 - name: Install Rust ${{ env.RUST_STABLE_VER }} 86 uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b 87 with: 88 toolchain: ${{ env.RUST_STABLE_VER }} 89 components: clippy 90 91 - name: Restore cache 92 uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 93 with: 94 save-if: ${{ github.event_name != 'merge_group' }} 95 96 - name: Run cargo clippy 97 run: cargo clippy --workspace --locked -- -D warnings 98 99 - name: Run cargo clippy (auxiliary) 100 run: cargo clippy --workspace --locked --tests --benches --examples -- -D warnings 101 102 - name: Run cargo clippy (no debug_assertions) 103 if: env.USING_DEBUG_ASSERTIONS == 'true' 104 run: cargo clippy --workspace --locked -- -D warnings 105 env: 106 CARGO_PROFILE_CI_DEBUG_ASSERTIONS: "false" 107 108 - name: Run cargo clippy (auxiliary) (no debug_assertions) 109 if: env.USING_DEBUG_ASSERTIONS == 'true' 110 run: cargo clippy --workspace --locked --tests --benches --examples -- -D warnings 111 env: 112 CARGO_PROFILE_CI_DEBUG_ASSERTIONS: "false" 113 114 test-stable: 115 name: cargo test 116 runs-on: ${{ matrix.os }} 117 strategy: 118 fail-fast: false 119 matrix: 120 os: [windows-latest, macos-latest, ubuntu-latest] 121 steps: 122 - name: Checkout repository 123 uses: actions/checkout@v4 124 125 - name: Restore cache 126 uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 127 with: 128 save-if: ${{ github.event_name != 'merge_group' }} 129 130 - name: Run cargo test 131 run: cargo test --workspace --locked --all-features --no-fail-fast 132 env: 133 # We do not run the masonry render tests on platforms without a working GPU, 134 # because those require Vello rendering to be working 135 # See also https://github.com/linebender/vello/pull/610 136 SKIP_RENDER_TESTS: ${{ matrix.skip_gpu }} 137 138 doc: 139 name: cargo doc 140 # NOTE: We don't have any platform specific docs in this workspace, so we only run on Ubuntu. 141 # If we get per-platform docs (win/macos/linux/wasm32/..) then doc jobs should match that. 142 runs-on: ubuntu-latest 143 steps: 144 - name: Checkout repository 145 uses: actions/checkout@v4 146 147 - name: Install Rust nightly 148 uses: dtolnay/rust-toolchain@nightly 149 150 - name: Restore cache 151 uses: Swatinem/rust-cache@v2 152 with: 153 save-if: ${{ github.event_name != 'merge_group' }} 154 155 # We test documentation using nightly to match docs.rs. 156 - name: Run cargo doc 157 run: cargo doc --workspace --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples 158 env: 159 RUSTDOCFLAGS: '--cfg docsrs -D warnings' 160 161 # If this fails, consider changing your text or adding something to .typos.toml. 162 typos: 163 runs-on: ubuntu-latest 164 steps: 165 - name: Checkout repository 166 uses: actions/checkout@v4 167 168 - name: Check typos 169 uses: crate-ci/typos@v1.31.1