main.yml 13 KB

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