main.yml 13 KB

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