main.yml 12 KB

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