main.yml 12 KB

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