main.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 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-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 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-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 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. 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 libayatana-appindicator3-dev libxdo-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 libayatana-appindicator3-dev libxdo-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. steps:
  190. # Do our best to cache the toolchain and node install steps
  191. - uses: actions/checkout@v4
  192. - uses: actions/setup-node@v4
  193. with:
  194. node-version: 16
  195. - name: Install Rust
  196. uses: dtolnay/rust-toolchain@1.86.0
  197. with:
  198. toolchain: stable
  199. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  200. - uses: Swatinem/rust-cache@v2
  201. with:
  202. cache-all-crates: "true"
  203. cache-on-failure: "true"
  204. - name: Playwright
  205. working-directory: ./packages/playwright-tests
  206. run: |
  207. npm ci
  208. npm install -D @playwright/test
  209. npx playwright install --with-deps
  210. rm -rf ./target/dx
  211. npx playwright test
  212. - uses: actions/upload-artifact@v4
  213. if: always()
  214. with:
  215. name: playwright-report
  216. path: ./packages/playwright-tests/playwright-report/
  217. retention-days: 30
  218. matrix_test:
  219. runs-on: ${{ matrix.platform.os }}
  220. if: github.event.pull_request.draft == false
  221. env:
  222. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  223. strategy:
  224. matrix:
  225. platform:
  226. - {
  227. target: aarch64-apple-darwin,
  228. os: macos-latest,
  229. toolchain: "1.86.0",
  230. cross: false,
  231. command: "test",
  232. args: "--all --tests",
  233. }
  234. - {
  235. target: x86_64-apple-darwin,
  236. os: macos-13,
  237. toolchain: "1.86.0",
  238. cross: false,
  239. command: "test",
  240. args: "--all --tests",
  241. }
  242. - {
  243. target: aarch64-apple-ios,
  244. os: macos-latest,
  245. toolchain: "1.86.0",
  246. cross: false,
  247. command: "build",
  248. args: "--package dioxus-mobile",
  249. }
  250. - {
  251. target: x86_64-unknown-linux-gnu,
  252. os: ubuntu-24.04,
  253. toolchain: "1.86.0",
  254. cross: false,
  255. command: "build",
  256. args: "--all --tests",
  257. }
  258. - {
  259. target: aarch64-unknown-linux-gnu,
  260. os: ubuntu-24.04-arm,
  261. toolchain: "1.86.0",
  262. cross: false,
  263. command: "build",
  264. args: "--all --tests",
  265. }
  266. - {
  267. target: aarch64-linux-android,
  268. os: ubuntu-24.04,
  269. toolchain: "1.86.0",
  270. cross: true,
  271. command: "build",
  272. args: "--package dioxus-mobile",
  273. }
  274. steps:
  275. - uses: actions/checkout@v4
  276. - name: install stable
  277. uses: dtolnay/rust-toolchain@master
  278. with:
  279. toolchain: ${{ matrix.platform.toolchain }}
  280. targets: ${{ matrix.platform.target }}
  281. components: rustfmt
  282. - name: Install nasm for windows (tls)
  283. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  284. uses: ilammy/setup-nasm@v1
  285. - name: Free Disk Space
  286. if: ${{ matrix.platform.os == 'ubuntu-24.04' || matrix.platform.os == 'ubuntu-24.04-arm' }}
  287. uses: ./.github/actions/free-disk-space
  288. - uses: awalsh128/cache-apt-pkgs-action@latest
  289. if: ${{ matrix.platform.os == 'ubuntu-24.04' || matrix.platform.os == 'ubuntu-24.04-arm' }}
  290. with:
  291. packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  292. version: 1.0
  293. - name: Install cross
  294. if: ${{ matrix.platform.cross == true }}
  295. uses: taiki-e/install-action@cross
  296. - uses: Swatinem/rust-cache@v2
  297. with:
  298. key: "matrix-${{ matrix.platform.target }}"
  299. cache-all-crates: "true"
  300. - name: test
  301. run: |
  302. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}
  303. # borrowed from uv
  304. # https://raw.githubusercontent.com/astral-sh/uv/refs/heads/main/.github/workflows/ci.yml
  305. cargo-test-windows:
  306. if: github.event.pull_request.draft == false
  307. runs-on:
  308. labels: "windows-latest"
  309. name: "cargo test | windows"
  310. steps:
  311. - uses: actions/checkout@v4
  312. - uses: dtolnay/rust-toolchain@1.86.0
  313. with:
  314. components: rustfmt, clippy
  315. - uses: Swatinem/rust-cache@v2
  316. with:
  317. workspaces: ${{ env.UV_WORKSPACE }}
  318. cache-all-crates: "true"
  319. - name: "Install Rust toolchain"
  320. working-directory: ${{ env.UV_WORKSPACE }}
  321. run: rustup show
  322. - name: "Cargo test"
  323. working-directory: ${{ env.UV_WORKSPACE }}
  324. run: |
  325. cargo test --workspace --tests
  326. # Only run semver checks if the PR is not a draft and does not have the breaking label
  327. # Breaking PRs don't need to follow semver since they are breaking changes
  328. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  329. # likely make future backporting difficult
  330. #
  331. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  332. #
  333. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  334. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  335. #
  336. # semver:
  337. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  338. # name: Semver Check
  339. # runs-on: ubuntu-24.04
  340. # steps:
  341. # - uses: actions/checkout@v4
  342. # - uses: dtolnay/rust-toolchain@1.86.0
  343. # - uses: Swatinem/rust-cache@v2
  344. # with:
  345. # cache-all-crates: "true"
  346. # cache-on-failure: "true"
  347. # - name: Check semver
  348. # uses: obi1kenobi/cargo-semver-checks-action@v2
  349. # with:
  350. # manifest-path: ./Cargo.toml
  351. # exclude: "dioxus-cli, dioxus-ext"