main.yml 13 KB

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