main.yml 12 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: "1"
  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@stable
  46. - uses: Swatinem/rust-cache@v2
  47. with:
  48. cache-all-crates: "true"
  49. cache-on-failure: "true"
  50. # https://github.com/foresterre/cargo-msrv/blob/4345edfe3f4fc91cc8ae6c7d6804c0748fae92ae/.github/workflows/msrv.yml
  51. - name: install_cargo_msrv
  52. run: cargo install cargo-msrv --all-features
  53. - name: version_of_cargo_msrv
  54. run: cargo msrv --version
  55. - name: run_cargo_msrv
  56. run: cargo msrv --output-format json verify -- cargo check
  57. - name: run_cargo_msrv_on_verify_failure
  58. if: ${{ failure() }}
  59. run: cargo msrv --output-format json -- cargo check
  60. test:
  61. if: github.event.pull_request.draft == false
  62. name: Test Suite
  63. runs-on: ubuntu-latest
  64. steps:
  65. - uses: actions/checkout@v4
  66. - name: Free Disk Space (Ubuntu)
  67. uses: jlumbroso/free-disk-space@v1.3.1
  68. with: # speed things up a bit
  69. large-packages: false
  70. docker-images: false
  71. swap-storage: false
  72. - run: sudo apt-get update
  73. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  74. - uses: dtolnay/rust-toolchain@stable
  75. - uses: Swatinem/rust-cache@v2
  76. with:
  77. cache-all-crates: "true"
  78. cache-on-failure: "true"
  79. - uses: davidB/rust-cargo-make@v1
  80. - uses: browser-actions/setup-firefox@latest
  81. - uses: jetli/wasm-pack-action@v0.4.0
  82. - run: cargo make tests
  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. - run: sudo apt-get update
  90. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  91. - uses: dtolnay/rust-toolchain@stable
  92. - uses: Swatinem/rust-cache@v2
  93. with:
  94. cache-all-crates: "true"
  95. cache-on-failure: "true"
  96. - uses: davidB/rust-cargo-make@v1
  97. - uses: browser-actions/setup-firefox@latest
  98. - uses: jetli/wasm-pack-action@v0.4.0
  99. - name: Free Disk Space (Ubuntu)
  100. uses: jlumbroso/free-disk-space@v1.3.1
  101. with: # speed things up a bit
  102. large-packages: false
  103. docker-images: false
  104. swap-storage: false
  105. - run: cargo test --profile release-unoptimized --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile
  106. fmt:
  107. if: github.event.pull_request.draft == false
  108. name: Rustfmt
  109. runs-on: ubuntu-latest
  110. steps:
  111. - uses: actions/checkout@v4
  112. - uses: dtolnay/rust-toolchain@stable
  113. with:
  114. components: rustfmt
  115. - uses: Swatinem/rust-cache@v2
  116. with:
  117. cache-all-crates: "true"
  118. cache-on-failure: "true"
  119. - run: cargo fmt --all -- --check
  120. typos:
  121. if: github.event.pull_request.draft == false
  122. name: Check for typos
  123. runs-on: ubuntu-latest
  124. steps:
  125. - uses: actions/checkout@v4
  126. - name: Check for typos
  127. uses: crate-ci/typos@master
  128. docs:
  129. if: github.event.pull_request.draft == false
  130. name: Docs
  131. runs-on: ubuntu-latest
  132. steps:
  133. - uses: actions/checkout@v4
  134. - run: sudo apt-get update
  135. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  136. - name: Install Rust ${{ env.rust_nightly }}
  137. uses: dtolnay/rust-toolchain@nightly
  138. with:
  139. toolchain: ${{ env.rust_nightly }}
  140. - uses: Swatinem/rust-cache@v2
  141. with:
  142. cache-all-crates: "true"
  143. cache-on-failure: "true"
  144. - name: "doc --lib --all-features"
  145. run: |
  146. cargo doc --workspace --no-deps --all-features --document-private-items
  147. # env:
  148. # RUSTFLAGS: --cfg docsrs
  149. # RUSTDOCFLAGS: --cfg docsrs
  150. # todo: re-enable warnings, private items
  151. # RUSTDOCFLAGS: --cfg docsrs -Dwarnings
  152. # --document-private-items
  153. # Check for invalid links in the repository
  154. link-check:
  155. if: github.event.pull_request.draft == false
  156. name: Check For Invalid Links
  157. runs-on: ubuntu-latest
  158. steps:
  159. - uses: actions/checkout@v4
  160. - name: Restore lychee cache
  161. uses: actions/cache@v4
  162. with:
  163. path: .lycheecache
  164. key: cache-lychee-${{ github.sha }}
  165. restore-keys: cache-lychee-
  166. - name: Run lychee
  167. uses: lycheeverse/lychee-action@v2
  168. with:
  169. args: --base . --config ./lychee.toml './**/*.md'
  170. fail: true
  171. check:
  172. if: github.event.pull_request.draft == false
  173. name: Check
  174. runs-on: ubuntu-latest
  175. steps:
  176. - uses: actions/checkout@v4
  177. - run: sudo apt-get update
  178. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  179. - uses: dtolnay/rust-toolchain@stable
  180. - uses: Swatinem/rust-cache@v2
  181. with:
  182. cache-all-crates: "true"
  183. cache-on-failure: "true"
  184. - run: cargo check --workspace --all-features --all-targets
  185. clippy:
  186. if: github.event.pull_request.draft == false
  187. name: Clippy
  188. runs-on: ubuntu-latest
  189. steps:
  190. - uses: actions/checkout@v4
  191. - run: sudo apt-get update
  192. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  193. - uses: dtolnay/rust-toolchain@stable
  194. with:
  195. components: rustfmt, clippy
  196. - uses: Swatinem/rust-cache@v2
  197. with:
  198. cache-all-crates: "true"
  199. cache-on-failure: "true"
  200. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  201. nix:
  202. runs-on: ${{ matrix.os }}
  203. strategy:
  204. matrix:
  205. os: [ubuntu-latest, macos-latest]
  206. steps:
  207. - uses: actions/checkout@v4
  208. - uses: DeterminateSystems/nix-installer-action@main
  209. - uses: DeterminateSystems/magic-nix-cache-action@main
  210. - name: Install omnix
  211. run: nix --accept-flake-config profile install "github:juspay/omnix"
  212. - name: Build all flake outputs
  213. run: om ci
  214. - name: Ensure devShell has all build deps
  215. run: nix develop -c cargo build -p dioxus-cli
  216. playwright:
  217. if: github.event.pull_request.draft == false
  218. name: Playwright Tests
  219. runs-on: macos-latest
  220. steps:
  221. # Do our best to cache the toolchain and node install steps
  222. - uses: actions/checkout@v4
  223. - uses: actions/setup-node@v4
  224. with:
  225. node-version: 16
  226. - name: Free Disk Space (Ubuntu)
  227. uses: jlumbroso/free-disk-space@v1.3.1
  228. with: # speed things up a bit
  229. large-packages: false
  230. docker-images: false
  231. swap-storage: false
  232. - name: Install Rust
  233. uses: dtolnay/rust-toolchain@master
  234. with:
  235. toolchain: stable
  236. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  237. - uses: Swatinem/rust-cache@v2
  238. with:
  239. cache-all-crates: "true"
  240. cache-on-failure: "true"
  241. - name: Playwright
  242. working-directory: ./packages/playwright-tests
  243. run: |
  244. npm ci
  245. npm install -D @playwright/test
  246. npx playwright install --with-deps
  247. npx playwright test
  248. - uses: actions/upload-artifact@v4
  249. if: always()
  250. with:
  251. name: playwright-report
  252. path: playwright-report/
  253. retention-days: 30
  254. matrix_test:
  255. runs-on: ${{ matrix.platform.os }}
  256. if: github.event.pull_request.draft == false
  257. env:
  258. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  259. strategy:
  260. matrix:
  261. platform:
  262. - {
  263. target: x86_64-pc-windows-msvc,
  264. os: windows-latest,
  265. toolchain: "1.79.0",
  266. cross: false,
  267. command: "test",
  268. args: "--all --tests",
  269. }
  270. - {
  271. target: aarch64-apple-darwin,
  272. os: macos-latest,
  273. toolchain: "1.79.0",
  274. cross: false,
  275. command: "test",
  276. args: "--all --tests",
  277. }
  278. - {
  279. target: x86_64-apple-darwin,
  280. os: macos-13,
  281. toolchain: "1.79.0",
  282. cross: false,
  283. command: "test",
  284. args: "--all --tests",
  285. }
  286. - {
  287. target: aarch64-apple-ios,
  288. os: macos-latest,
  289. toolchain: "1.79.0",
  290. cross: false,
  291. command: "build",
  292. args: "--package dioxus-mobile",
  293. }
  294. - {
  295. target: aarch64-linux-android,
  296. os: ubuntu-latest,
  297. toolchain: "1.79.0",
  298. cross: true,
  299. command: "build",
  300. args: "--package dioxus-mobile",
  301. }
  302. steps:
  303. - uses: actions/checkout@v4
  304. - name: Free Disk Space (Ubuntu)
  305. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  306. uses: jlumbroso/free-disk-space@v1.3.1
  307. with: # speed things up a bit
  308. large-packages: false
  309. docker-images: false
  310. swap-storage: false
  311. - name: install stable
  312. uses: dtolnay/rust-toolchain@master
  313. with:
  314. toolchain: ${{ matrix.platform.toolchain }}
  315. targets: ${{ matrix.platform.target }}
  316. components: rustfmt
  317. - name: Install nasm for windows (tls)
  318. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  319. uses: ilammy/setup-nasm@v1
  320. - name: Install cross
  321. if: ${{ matrix.platform.cross == true }}
  322. uses: taiki-e/install-action@cross
  323. - uses: Swatinem/rust-cache@v2
  324. with:
  325. key: "${{ matrix.platform.target }}"
  326. cache-all-crates: "true"
  327. cache-on-failure: "true"
  328. - name: test
  329. run: |
  330. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}
  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@stable
  348. # - uses: Swatinem/rust-cache@v2
  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"