main.yml 13 KB

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