main.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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-24.04
  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-24.04
  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 libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-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-24.04
  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 libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-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-24.04
  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-24.04
  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 libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-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. RUSTDOCFLAGS: -Dwarnings --document-private-items
  134. check:
  135. if: github.event.pull_request.draft == false
  136. name: Check
  137. runs-on: ubuntu-24.04
  138. steps:
  139. - uses: actions/checkout@v4
  140. - uses: awalsh128/cache-apt-pkgs-action@latest
  141. with:
  142. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
  143. version: 1.0
  144. - uses: dtolnay/rust-toolchain@1.86.0
  145. - uses: Swatinem/rust-cache@v2
  146. with:
  147. cache-all-crates: "true"
  148. - run: cargo check --workspace --all-features --all-targets
  149. clippy:
  150. if: github.event.pull_request.draft == false
  151. name: Clippy
  152. runs-on: ubuntu-24.04
  153. steps:
  154. - uses: actions/checkout@v4
  155. - uses: awalsh128/cache-apt-pkgs-action@latest
  156. with:
  157. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
  158. version: 1.0
  159. - uses: dtolnay/rust-toolchain@1.86.0
  160. with:
  161. components: rustfmt, clippy
  162. - uses: Swatinem/rust-cache@v2
  163. with:
  164. cache-all-crates: "true"
  165. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  166. nix:
  167. if: github.event.pull_request.draft == false
  168. runs-on: ${{ matrix.os }}
  169. strategy:
  170. matrix:
  171. os: [ubuntu-24.04, macos-latest]
  172. steps:
  173. - uses: actions/checkout@v4
  174. - uses: nixbuild/nix-quick-install-action@master
  175. - uses: nix-community/cache-nix-action@main
  176. with:
  177. primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
  178. restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}
  179. - name: Install omnix
  180. run: nix --accept-flake-config profile install "github:juspay/omnix"
  181. - name: Build all flake outputs
  182. run: om ci
  183. - name: Ensure devShell has all build deps
  184. run: nix develop -c cargo build -p dioxus-cli --features no-downloads
  185. playwright:
  186. if: github.event.pull_request.draft == false
  187. name: Playwright Tests
  188. runs-on: macos-latest
  189. strategy:
  190. matrix:
  191. platform:
  192. - { toolchain: 1.86.0 }
  193. - { toolchain: beta }
  194. steps:
  195. # Do our best to cache the toolchain and node install steps
  196. - uses: actions/checkout@v4
  197. - uses: actions/setup-node@v4
  198. with:
  199. node-version: 16
  200. - name: Install Rust
  201. uses: dtolnay/rust-toolchain@master
  202. with:
  203. toolchain: ${{ matrix.platform.toolchain }}
  204. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  205. - uses: Swatinem/rust-cache@v2
  206. with:
  207. key: "playwright-${{ matrix.platform.toolchain }}-${{ runner.os }}"
  208. cache-all-crates: "true"
  209. cache-on-failure: "true"
  210. - name: Wipe dx cache
  211. run: |
  212. rm -rf ./target/dx
  213. - name: Playwright
  214. working-directory: ./packages/playwright-tests
  215. env:
  216. # The hot patch test requires incremental compilation
  217. CARGO_INCREMENTAL: 1
  218. run: |
  219. npm ci
  220. npm install -D @playwright/test
  221. npx playwright install --with-deps
  222. npx playwright test
  223. - uses: actions/upload-artifact@v4
  224. if: always()
  225. with:
  226. name: playwright-report-${{ matrix.platform.toolchain }}-${{ runner.os }}
  227. path: ./packages/playwright-tests/playwright-report/
  228. retention-days: 30
  229. matrix_test:
  230. runs-on: ${{ matrix.platform.os }}
  231. if: github.event.pull_request.draft == false
  232. env:
  233. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  234. strategy:
  235. matrix:
  236. platform:
  237. - {
  238. target: aarch64-apple-darwin,
  239. os: macos-latest,
  240. toolchain: "1.86.0",
  241. cross: false,
  242. command: "test",
  243. args: "--all --tests",
  244. }
  245. - {
  246. target: x86_64-apple-darwin,
  247. os: macos-13,
  248. toolchain: "1.86.0",
  249. cross: false,
  250. command: "test",
  251. args: "--all --tests",
  252. }
  253. - {
  254. target: aarch64-apple-ios,
  255. os: macos-latest,
  256. toolchain: "1.86.0",
  257. cross: false,
  258. command: "build",
  259. args: "--package dioxus-mobile",
  260. }
  261. - {
  262. target: x86_64-unknown-linux-gnu,
  263. os: ubuntu-24.04,
  264. toolchain: "1.86.0",
  265. cross: false,
  266. command: "build",
  267. args: "--all --tests",
  268. }
  269. - {
  270. target: aarch64-unknown-linux-gnu,
  271. os: ubuntu-24.04-arm,
  272. toolchain: "1.86.0",
  273. cross: false,
  274. command: "build",
  275. args: "--all --tests",
  276. }
  277. - {
  278. target: aarch64-linux-android,
  279. os: ubuntu-24.04,
  280. toolchain: "1.86.0",
  281. cross: true,
  282. command: "build",
  283. args: "--package dioxus-mobile",
  284. }
  285. steps:
  286. - uses: actions/checkout@v4
  287. - name: install stable
  288. uses: dtolnay/rust-toolchain@master
  289. with:
  290. toolchain: ${{ matrix.platform.toolchain }}
  291. targets: ${{ matrix.platform.target }}
  292. components: rustfmt
  293. - name: Install nasm for windows (tls)
  294. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  295. uses: ilammy/setup-nasm@v1
  296. - name: Free Disk Space
  297. if: ${{ matrix.platform.os == 'ubuntu-24.04' || matrix.platform.os == 'ubuntu-24.04-arm' }}
  298. uses: ./.github/actions/free-disk-space
  299. - uses: awalsh128/cache-apt-pkgs-action@latest
  300. if: ${{ matrix.platform.os == 'ubuntu-24.04' || matrix.platform.os == 'ubuntu-24.04-arm' }}
  301. with:
  302. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
  303. version: ${{ matrix.platform.target }}-${{ matrix.platform.os }} # disambiguate since we're in a matrix and this caching action doesn't factor in these variables
  304. - name: Install cross
  305. if: ${{ matrix.platform.cross == true }}
  306. uses: taiki-e/install-action@cross
  307. - uses: Swatinem/rust-cache@v2
  308. with:
  309. key: "matrix-${{ matrix.platform.target }}"
  310. cache-all-crates: "true"
  311. - name: test
  312. run: |
  313. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}
  314. # borrowed from uv
  315. # https://raw.githubusercontent.com/astral-sh/uv/refs/heads/main/.github/workflows/ci.yml
  316. cargo-test-windows:
  317. if: github.event.pull_request.draft == false
  318. runs-on:
  319. labels: "windows-latest"
  320. name: "cargo test | windows"
  321. steps:
  322. - uses: actions/checkout@v4
  323. - uses: dtolnay/rust-toolchain@1.86.0
  324. with:
  325. components: rustfmt, clippy
  326. - uses: Swatinem/rust-cache@v2
  327. with:
  328. workspaces: ${{ env.UV_WORKSPACE }}
  329. cache-all-crates: "true"
  330. - name: "Install Rust toolchain"
  331. working-directory: ${{ env.UV_WORKSPACE }}
  332. run: rustup show
  333. - name: "Cargo test"
  334. working-directory: ${{ env.UV_WORKSPACE }}
  335. run: |
  336. cargo test --workspace --tests
  337. # Only run semver checks if the PR is not a draft and does not have the breaking label
  338. # Breaking PRs don't need to follow semver since they are breaking changes
  339. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  340. # likely make future backporting difficult
  341. #
  342. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  343. #
  344. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  345. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  346. #
  347. # semver:
  348. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  349. # name: Semver Check
  350. # runs-on: ubuntu-24.04
  351. # steps:
  352. # - uses: actions/checkout@v4
  353. # - uses: dtolnay/rust-toolchain@1.86.0
  354. # - uses: Swatinem/rust-cache@v2
  355. # with:
  356. # cache-all-crates: "true"
  357. # cache-on-failure: "true"
  358. # - name: Check semver
  359. # uses: obi1kenobi/cargo-semver-checks-action@v2
  360. # with:
  361. # manifest-path: ./Cargo.toml
  362. # exclude: "dioxus-cli, dioxus-ext"