main.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. # Whenever an open PR is updated, the workflow will be triggered
  2. #
  3. # This can get expensive, so we do a lot of caching and checks to prevent unnecessary runs
  4. name: Rust CI
  5. on:
  6. push:
  7. branches:
  8. - main
  9. paths:
  10. - packages/**
  11. - examples/**
  12. - docs/guide/**
  13. - src/**
  14. - .github/**
  15. - lib.rs
  16. - Cargo.toml
  17. - Makefile.toml
  18. pull_request:
  19. types: [opened, synchronize, reopened, ready_for_review]
  20. branches:
  21. - main
  22. paths:
  23. - packages/**
  24. - examples/**
  25. - src/**
  26. - .github/**
  27. - lib.rs
  28. - Cargo.toml
  29. # workflow_dispatch:
  30. concurrency:
  31. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  32. cancel-in-progress: true
  33. env:
  34. CARGO_TERM_COLOR: always
  35. CARGO_INCREMENTAL: 0 # todo(jon): cargo-cache wipes incremental artifacts, but we eventually want to cache them
  36. RUST_BACKTRACE: 1
  37. rust_nightly: nightly-2025-04-07
  38. jobs:
  39. check-msrv:
  40. if: github.event.pull_request.draft == false
  41. name: Check MSRV
  42. runs-on: ubuntu-latest
  43. steps:
  44. - uses: actions/checkout@v4
  45. - uses: dtolnay/rust-toolchain@1.86.0
  46. - uses: Swatinem/rust-cache@v2
  47. with:
  48. cache-all-crates: "true"
  49. # https://github.com/foresterre/cargo-msrv/blob/4345edfe3f4fc91cc8ae6c7d6804c0748fae92ae/.github/workflows/msrv.yml
  50. - name: install_cargo_msrv
  51. run: cargo install cargo-msrv --all-features --version 0.16.3 --locked
  52. - name: version_of_cargo_msrv
  53. run: cargo msrv --version
  54. - name: run_cargo_msrv
  55. run: cargo msrv --output-format json verify -- cargo check
  56. - name: run_cargo_msrv_on_verify_failure
  57. if: ${{ failure() }}
  58. run: cargo msrv --output-format json -- cargo check
  59. test:
  60. if: github.event.pull_request.draft == false
  61. name: Test Suite
  62. runs-on: ubuntu-latest
  63. steps:
  64. - uses: actions/checkout@v4
  65. - name: Free Disk Space
  66. uses: ./.github/actions/free-disk-space
  67. - uses: awalsh128/cache-apt-pkgs-action@latest
  68. with:
  69. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  70. version: 1.0
  71. - uses: dtolnay/rust-toolchain@1.86.0
  72. with:
  73. components: rustfmt, clippy
  74. - uses: Swatinem/rust-cache@v2
  75. with:
  76. cache-all-crates: "true"
  77. - uses: browser-actions/setup-firefox@latest
  78. - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile
  79. release-test:
  80. if: github.event.pull_request.draft == false
  81. name: Test Suite with Optimizations
  82. runs-on: ubuntu-latest
  83. steps:
  84. - uses: actions/checkout@v4
  85. - name: Free Disk Space
  86. uses: ./.github/actions/free-disk-space
  87. - uses: awalsh128/cache-apt-pkgs-action@latest
  88. with:
  89. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  90. version: 1.0
  91. - uses: dtolnay/rust-toolchain@1.86.0
  92. with:
  93. components: rustfmt, clippy
  94. - uses: Swatinem/rust-cache@v2
  95. with:
  96. cache-all-crates: "true"
  97. - uses: browser-actions/setup-firefox@latest
  98. - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile --profile release-unoptimized
  99. fmt:
  100. if: github.event.pull_request.draft == false
  101. name: Rustfmt
  102. runs-on: ubuntu-latest
  103. steps:
  104. - uses: actions/checkout@v4
  105. - uses: dtolnay/rust-toolchain@1.86.0
  106. with:
  107. components: rustfmt
  108. - uses: Swatinem/rust-cache@v2
  109. with:
  110. cache-all-crates: "true"
  111. - run: cargo fmt --all -- --check
  112. docs:
  113. if: github.event.pull_request.draft == false
  114. name: Docs
  115. runs-on: ubuntu-latest
  116. steps:
  117. - uses: actions/checkout@v4
  118. - uses: awalsh128/cache-apt-pkgs-action@latest
  119. with:
  120. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  121. version: 1.0
  122. - name: Install Rust ${{ env.rust_nightly }}
  123. uses: dtolnay/rust-toolchain@nightly
  124. with:
  125. toolchain: ${{ env.rust_nightly }}
  126. - uses: Swatinem/rust-cache@v2
  127. with:
  128. cache-all-crates: "true"
  129. - name: "doc --lib --all-features"
  130. run: |
  131. cargo doc --workspace --no-deps --all-features --document-private-items
  132. # env:
  133. # RUSTFLAGS: --cfg docsrs
  134. # RUSTDOCFLAGS: --cfg docsrs
  135. # todo: re-enable warnings, private items
  136. # RUSTDOCFLAGS: --cfg docsrs -Dwarnings
  137. # --document-private-items
  138. check:
  139. if: github.event.pull_request.draft == false
  140. name: Check
  141. runs-on: ubuntu-latest
  142. steps:
  143. - uses: actions/checkout@v4
  144. - uses: awalsh128/cache-apt-pkgs-action@latest
  145. with:
  146. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  147. version: 1.0
  148. - uses: dtolnay/rust-toolchain@1.86.0
  149. - uses: Swatinem/rust-cache@v2
  150. with:
  151. cache-all-crates: "true"
  152. - run: cargo check --workspace --all-features --all-targets
  153. clippy:
  154. if: github.event.pull_request.draft == false
  155. name: Clippy
  156. runs-on: ubuntu-latest
  157. steps:
  158. - uses: actions/checkout@v4
  159. - uses: awalsh128/cache-apt-pkgs-action@latest
  160. with:
  161. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  162. version: 1.0
  163. - uses: dtolnay/rust-toolchain@1.86.0
  164. with:
  165. components: rustfmt, clippy
  166. - uses: Swatinem/rust-cache@v2
  167. with:
  168. cache-all-crates: "true"
  169. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  170. nix:
  171. if: github.event.pull_request.draft == false
  172. runs-on: ${{ matrix.os }}
  173. strategy:
  174. matrix:
  175. os: [ubuntu-latest, macos-latest]
  176. steps:
  177. - uses: actions/checkout@v4
  178. - uses: nixbuild/nix-quick-install-action@master
  179. - uses: nix-community/cache-nix-action@main
  180. with:
  181. primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
  182. restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}
  183. - name: Install omnix
  184. run: nix --accept-flake-config profile install "github:juspay/omnix"
  185. - name: Build all flake outputs
  186. run: om ci
  187. - name: Ensure devShell has all build deps
  188. run: nix develop -c cargo build -p dioxus-cli --features no-downloads
  189. playwright:
  190. if: github.event.pull_request.draft == false
  191. name: Playwright Tests
  192. runs-on: macos-latest
  193. steps:
  194. # Do our best to cache the toolchain and node install steps
  195. - uses: actions/checkout@v4
  196. - uses: actions/setup-node@v4
  197. with:
  198. node-version: 16
  199. - name: Install Rust
  200. uses: dtolnay/rust-toolchain@1.86.0
  201. with:
  202. toolchain: stable
  203. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  204. - uses: Swatinem/rust-cache@v2
  205. with:
  206. cache-all-crates: "true"
  207. cache-on-failure: "true"
  208. - name: Playwright
  209. working-directory: ./packages/playwright-tests
  210. run: |
  211. npm ci
  212. npm install -D @playwright/test
  213. npx playwright install --with-deps
  214. npx playwright test
  215. - uses: actions/upload-artifact@v4
  216. if: always()
  217. with:
  218. name: playwright-report
  219. path: ./packages/playwright-tests/playwright-report/
  220. retention-days: 30
  221. matrix_test:
  222. runs-on: ${{ matrix.platform.os }}
  223. if: github.event.pull_request.draft == false
  224. env:
  225. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  226. strategy:
  227. matrix:
  228. platform:
  229. - {
  230. target: aarch64-apple-darwin,
  231. os: macos-latest,
  232. toolchain: "1.86.0",
  233. cross: false,
  234. command: "test",
  235. args: "--all --tests",
  236. }
  237. - {
  238. target: x86_64-apple-darwin,
  239. os: macos-13,
  240. toolchain: "1.86.0",
  241. cross: false,
  242. command: "test",
  243. args: "--all --tests",
  244. }
  245. - {
  246. target: aarch64-apple-ios,
  247. os: macos-latest,
  248. toolchain: "1.86.0",
  249. cross: false,
  250. command: "build",
  251. args: "--package dioxus-mobile",
  252. }
  253. - {
  254. target: aarch64-linux-android,
  255. os: ubuntu-latest,
  256. toolchain: "1.86.0",
  257. cross: true,
  258. command: "build",
  259. args: "--package dioxus-mobile",
  260. }
  261. steps:
  262. - uses: actions/checkout@v4
  263. - name: install stable
  264. uses: dtolnay/rust-toolchain@master
  265. with:
  266. toolchain: ${{ matrix.platform.toolchain }}
  267. targets: ${{ matrix.platform.target }}
  268. components: rustfmt
  269. - name: Install nasm for windows (tls)
  270. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  271. uses: ilammy/setup-nasm@v1
  272. - name: Install cross
  273. if: ${{ matrix.platform.cross == true }}
  274. uses: taiki-e/install-action@cross
  275. - uses: Swatinem/rust-cache@v2
  276. with:
  277. key: "matrix-${{ matrix.platform.target }}"
  278. cache-all-crates: "true"
  279. - name: test
  280. run: |
  281. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}
  282. # borrowed from uv
  283. # https://raw.githubusercontent.com/astral-sh/uv/refs/heads/main/.github/workflows/ci.yml
  284. cargo-test-windows:
  285. if: github.event.pull_request.draft == false
  286. runs-on:
  287. labels: "windows-latest"
  288. name: "cargo test | windows"
  289. steps:
  290. - uses: actions/checkout@v4
  291. - uses: dtolnay/rust-toolchain@1.86.0
  292. with:
  293. components: rustfmt, clippy
  294. - uses: Swatinem/rust-cache@v2
  295. with:
  296. workspaces: ${{ env.UV_WORKSPACE }}
  297. cache-all-crates: "true"
  298. - name: "Install Rust toolchain"
  299. working-directory: ${{ env.UV_WORKSPACE }}
  300. run: rustup show
  301. - name: "Cargo test"
  302. working-directory: ${{ env.UV_WORKSPACE }}
  303. run: |
  304. cargo test --workspace --tests
  305. # Only run semver checks if the PR is not a draft and does not have the breaking label
  306. # Breaking PRs don't need to follow semver since they are breaking changes
  307. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  308. # likely make future backporting difficult
  309. #
  310. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  311. #
  312. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  313. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  314. #
  315. # semver:
  316. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  317. # name: Semver Check
  318. # runs-on: ubuntu-latest
  319. # steps:
  320. # - uses: actions/checkout@v4
  321. # - uses: dtolnay/rust-toolchain@1.86.0
  322. # - uses: Swatinem/rust-cache@v2
  323. # with:
  324. # cache-all-crates: "true"
  325. # cache-on-failure: "true"
  326. # - name: Check semver
  327. # uses: obi1kenobi/cargo-semver-checks-action@v2
  328. # with:
  329. # manifest-path: ./Cargo.toml
  330. # exclude: "dioxus-cli, dioxus-ext"