main.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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: 1 # todo(jon): cargo-cache wipes incremental artifacts, but we eventually want to cache them
  36. RUST_BACKTRACE: 1
  37. rust_nightly: nightly-2024-10-20
  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.84.0
  46. # - uses: Swatinem/rust-cache@v2
  47. # with:
  48. # cache-all-crates: "true"
  49. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  50. with:
  51. cache-all-crates: "true"
  52. incremental: "true"
  53. # https://github.com/foresterre/cargo-msrv/blob/4345edfe3f4fc91cc8ae6c7d6804c0748fae92ae/.github/workflows/msrv.yml
  54. - name: install_cargo_msrv
  55. run: cargo install cargo-msrv --all-features --version 0.16.3 --locked
  56. - name: version_of_cargo_msrv
  57. run: cargo msrv --version
  58. - name: run_cargo_msrv
  59. run: cargo msrv --output-format json verify -- cargo check
  60. - name: run_cargo_msrv_on_verify_failure
  61. if: ${{ failure() }}
  62. run: cargo msrv --output-format json -- cargo check
  63. test:
  64. if: github.event.pull_request.draft == false
  65. name: Test Suite
  66. runs-on: ubuntu-latest
  67. steps:
  68. - uses: actions/checkout@v4
  69. - name: Free Disk Space (Ubuntu)
  70. uses: jlumbroso/free-disk-space@v1.3.1
  71. with: # speed things up a bit
  72. large-packages: false
  73. docker-images: false
  74. swap-storage: false
  75. - run: sudo apt-get update
  76. # todo: cache these?
  77. # https://stackoverflow.com/questions/59269850/caching-apt-packages-in-github-actions-workflow
  78. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  79. - uses: dtolnay/rust-toolchain@1.84.0
  80. with:
  81. components: rustfmt, clippy
  82. # - uses: Swatinem/rust-cache@v2
  83. # with:
  84. # cache-all-crates: "true"
  85. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  86. with:
  87. cache-all-crates: "true"
  88. incremental: "true"
  89. - uses: browser-actions/setup-firefox@latest
  90. - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile
  91. release-test:
  92. if: github.event.pull_request.draft == false
  93. name: Test Suite with Optimizations
  94. runs-on: ubuntu-latest
  95. steps:
  96. - uses: actions/checkout@v4
  97. - name: Free Disk Space (Ubuntu)
  98. uses: jlumbroso/free-disk-space@v1.3.1
  99. with: # speed things up a bit
  100. large-packages: false
  101. docker-images: false
  102. swap-storage: false
  103. - run: sudo apt-get update
  104. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  105. - uses: dtolnay/rust-toolchain@1.84.0
  106. with:
  107. components: rustfmt, clippy
  108. # - uses: Swatinem/rust-cache@v2
  109. # with:
  110. # cache-all-crates: "true"
  111. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  112. with:
  113. cache-all-crates: "true"
  114. incremental: "true"
  115. - uses: browser-actions/setup-firefox@latest
  116. - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile --profile release-unoptimized
  117. fmt:
  118. if: github.event.pull_request.draft == false
  119. name: Rustfmt
  120. runs-on: ubuntu-latest
  121. steps:
  122. - uses: actions/checkout@v4
  123. - uses: dtolnay/rust-toolchain@1.84.0
  124. with:
  125. components: rustfmt
  126. # - uses: Swatinem/rust-cache@v2
  127. # with:
  128. # cache-all-crates: "true"
  129. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  130. with:
  131. cache-all-crates: "true"
  132. incremental: "true"
  133. - run: cargo fmt --all -- --check
  134. docs:
  135. if: github.event.pull_request.draft == false
  136. name: Docs
  137. runs-on: ubuntu-latest
  138. steps:
  139. - uses: actions/checkout@v4
  140. - run: sudo apt-get update
  141. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  142. - name: Install Rust ${{ env.rust_nightly }}
  143. uses: dtolnay/rust-toolchain@nightly
  144. with:
  145. toolchain: ${{ env.rust_nightly }}
  146. # - uses: Swatinem/rust-cache@v2
  147. # with:
  148. # cache-all-crates: "true"
  149. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  150. with:
  151. cache-all-crates: "true"
  152. incremental: "true"
  153. - name: "doc --lib --all-features"
  154. run: |
  155. cargo doc --workspace --no-deps --all-features --document-private-items
  156. # env:
  157. # RUSTFLAGS: --cfg docsrs
  158. # RUSTDOCFLAGS: --cfg docsrs
  159. # todo: re-enable warnings, private items
  160. # RUSTDOCFLAGS: --cfg docsrs -Dwarnings
  161. # --document-private-items
  162. check:
  163. if: github.event.pull_request.draft == false
  164. name: Check
  165. runs-on: ubuntu-latest
  166. steps:
  167. - uses: actions/checkout@v4
  168. - run: sudo apt-get update
  169. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  170. - uses: dtolnay/rust-toolchain@1.84.0
  171. # - uses: Swatinem/rust-cache@v2
  172. # with:
  173. # cache-all-crates: "true"
  174. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  175. with:
  176. cache-all-crates: "true"
  177. incremental: "true"
  178. - run: cargo check --workspace --all-features --all-targets
  179. clippy:
  180. if: github.event.pull_request.draft == false
  181. name: Clippy
  182. runs-on: ubuntu-latest
  183. steps:
  184. - uses: actions/checkout@v4
  185. - run: sudo apt-get update
  186. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  187. - uses: dtolnay/rust-toolchain@1.84.0
  188. with:
  189. components: rustfmt, clippy
  190. # - uses: Swatinem/rust-cache@v2
  191. # with:
  192. # cache-all-crates: "true"
  193. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  194. with:
  195. cache-all-crates: "true"
  196. incremental: "true"
  197. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  198. nix:
  199. if: github.event.pull_request.draft == false
  200. runs-on: ${{ matrix.os }}
  201. strategy:
  202. matrix:
  203. os: [ubuntu-latest, macos-latest]
  204. steps:
  205. - uses: actions/checkout@v4
  206. - uses: DeterminateSystems/nix-installer-action@main
  207. - uses: DeterminateSystems/magic-nix-cache-action@main
  208. - name: Install omnix
  209. run: nix --accept-flake-config profile install "github:juspay/omnix"
  210. - name: Build all flake outputs
  211. run: om ci
  212. - name: Ensure devShell has all build deps
  213. run: nix develop -c cargo build -p dioxus-cli --features no-downloads
  214. playwright:
  215. if: github.event.pull_request.draft == false
  216. name: Playwright Tests
  217. runs-on: macos-latest
  218. steps:
  219. # Do our best to cache the toolchain and node install steps
  220. - uses: actions/checkout@v4
  221. - name: Free Disk Space (Ubuntu)
  222. uses: jlumbroso/free-disk-space@v1.3.1
  223. with: # speed things up a bit
  224. large-packages: false
  225. docker-images: false
  226. swap-storage: false
  227. - uses: actions/setup-node@v4
  228. with:
  229. node-version: 16
  230. - name: Install Rust
  231. uses: dtolnay/rust-toolchain@master
  232. with:
  233. toolchain: stable
  234. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  235. # - uses: Swatinem/rust-cache@v2
  236. # with:
  237. # cache-all-crates: "true"
  238. - uses: jkelleyrtp/rust-cache@jk/speedy-cache
  239. with:
  240. cache-all-crates: "true"
  241. incremental: "true"
  242. - name: Prebuild CLI
  243. run: |
  244. CARGO_LOG=debug cargo build --package dioxus-cli --release
  245. - name: Playwright
  246. working-directory: ./packages/playwright-tests
  247. run: |
  248. npm ci
  249. npm install -D @playwright/test
  250. npx playwright install --with-deps
  251. npx playwright test
  252. - uses: actions/upload-artifact@v4
  253. if: always()
  254. with:
  255. name: playwright-report
  256. path: ./packages/playwright-tests/playwright-report/
  257. retention-days: 30
  258. matrix_test:
  259. runs-on: ${{ matrix.platform.os }}
  260. if: github.event.pull_request.draft == false
  261. env:
  262. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  263. strategy:
  264. matrix:
  265. platform:
  266. - {
  267. target: aarch64-apple-darwin,
  268. os: macos-latest,
  269. toolchain: "1.84.0",
  270. cross: false,
  271. command: "test",
  272. args: "--all --tests",
  273. }
  274. - {
  275. target: x86_64-apple-darwin,
  276. os: macos-13,
  277. toolchain: "1.84.0",
  278. cross: false,
  279. command: "test",
  280. args: "--all --tests",
  281. }
  282. - {
  283. target: aarch64-apple-ios,
  284. os: macos-latest,
  285. toolchain: "1.84.0",
  286. cross: false,
  287. command: "build",
  288. args: "--package dioxus-mobile",
  289. }
  290. - {
  291. target: aarch64-linux-android,
  292. os: ubuntu-latest,
  293. toolchain: "1.84.0",
  294. cross: true,
  295. command: "build",
  296. args: "--package dioxus-mobile",
  297. }
  298. steps:
  299. - uses: actions/checkout@v4
  300. - name: Free Disk Space (Ubuntu)
  301. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  302. uses: jlumbroso/free-disk-space@v1.3.1
  303. with: # speed things up a bit
  304. large-packages: false
  305. docker-images: false
  306. swap-storage: false
  307. - name: install stable
  308. uses: dtolnay/rust-toolchain@master
  309. with:
  310. toolchain: ${{ matrix.platform.toolchain }}
  311. targets: ${{ matrix.platform.target }}
  312. components: rustfmt
  313. - name: Install nasm for windows (tls)
  314. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  315. uses: ilammy/setup-nasm@v1
  316. - name: Install cross
  317. if: ${{ matrix.platform.cross == true }}
  318. uses: taiki-e/install-action@cross
  319. - uses: Swatinem/rust-cache@v2
  320. with:
  321. key: "matrix-${{ matrix.platform.target }}"
  322. cache-all-crates: "true"
  323. - name: test
  324. run: |
  325. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}
  326. # borrowed from uv
  327. # https://raw.githubusercontent.com/astral-sh/uv/refs/heads/main/.github/workflows/ci.yml
  328. cargo-test-windows:
  329. if: github.event.pull_request.draft == false
  330. runs-on:
  331. labels: "windows-latest"
  332. name: "cargo test | windows"
  333. steps:
  334. - uses: actions/checkout@v4
  335. - name: Create Dev Drive using ReFS
  336. run: ${{ github.workspace }}/.github/workflows/setup-dev-drive.ps1
  337. # actions/checkout does not let us clone into anywhere outside ${{ github.workspace }}, so we have to copy the clone...
  338. - name: Copy Git Repo to Dev Drive
  339. run: |
  340. Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.UV_WORKSPACE }}" -Recurse
  341. - uses: dtolnay/rust-toolchain@1.84.0
  342. with:
  343. components: rustfmt, clippy
  344. - uses: Swatinem/rust-cache@v2
  345. with:
  346. workspaces: ${{ env.UV_WORKSPACE }}
  347. cache-all-crates: "true"
  348. - name: "Install Rust toolchain"
  349. working-directory: ${{ env.UV_WORKSPACE }}
  350. run: rustup show
  351. - name: "Cargo test"
  352. working-directory: ${{ env.UV_WORKSPACE }}
  353. run: |
  354. cargo test --workspace --tests
  355. # Only run semver checks if the PR is not a draft and does not have the breaking label
  356. # Breaking PRs don't need to follow semver since they are breaking changes
  357. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  358. # likely make future backporting difficult
  359. #
  360. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  361. #
  362. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  363. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  364. #
  365. # semver:
  366. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  367. # name: Semver Check
  368. # runs-on: ubuntu-latest
  369. # steps:
  370. # - uses: actions/checkout@v4
  371. # - uses: dtolnay/rust-toolchain@1.84.0
  372. # - uses: Swatinem/rust-cache@v2
  373. # with:
  374. # cache-all-crates: "true"
  375. # - name: Check semver
  376. # uses: obi1kenobi/cargo-semver-checks-action@v2
  377. # with:
  378. # manifest-path: ./Cargo.toml
  379. # exclude: "dioxus-cli, dioxus-ext"