main.yml 12 KB

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