main.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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"
  36. RUST_BACKTRACE: 1
  37. rust_nightly: nightly-2024-07-01
  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. save-if: ${{ github.ref == 'refs/heads/main' }}
  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. save-if: ${{ github.ref == 'refs/heads/main' }}
  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. - name: Free Disk Space (Ubuntu)
  90. uses: jlumbroso/free-disk-space@v1.3.1
  91. with: # speed things up a bit
  92. large-packages: false
  93. docker-images: false
  94. swap-storage: false
  95. - run: sudo apt-get update
  96. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  97. - uses: dtolnay/rust-toolchain@stable
  98. - uses: Swatinem/rust-cache@v2
  99. with:
  100. cache-all-crates: "true"
  101. save-if: ${{ github.ref == 'refs/heads/main' }}
  102. - uses: davidB/rust-cargo-make@v1
  103. - uses: browser-actions/setup-firefox@latest
  104. - uses: jetli/wasm-pack-action@v0.4.0
  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. save-if: ${{ github.ref == 'refs/heads/main' }}
  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. - name: Install Rust ${{ env.rust_nightly }}
  135. uses: dtolnay/rust-toolchain@stable
  136. with:
  137. toolchain: ${{ env.rust_nightly }}
  138. - uses: Swatinem/rust-cache@v2
  139. with:
  140. cache-all-crates: "true"
  141. save-if: ${{ github.ref == 'refs/heads/main' }}
  142. - name: "doc --lib --all-features"
  143. run: |
  144. cargo doc --workspace --no-deps --all-features --document-private-items
  145. env:
  146. RUSTFLAGS: --cfg docsrs
  147. RUSTDOCFLAGS: --cfg docsrs
  148. # todo: re-enable warnings
  149. # RUSTDOCFLAGS: --cfg docsrs -Dwarnings
  150. check:
  151. if: github.event.pull_request.draft == false
  152. name: Check
  153. runs-on: ubuntu-latest
  154. steps:
  155. - uses: actions/checkout@v4
  156. - run: sudo apt-get update
  157. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  158. - uses: dtolnay/rust-toolchain@stable
  159. - uses: Swatinem/rust-cache@v2
  160. with:
  161. cache-all-crates: "true"
  162. save-if: ${{ github.ref == 'refs/heads/main' }}
  163. - run: cargo check --workspace --all-features --all-targets
  164. clippy:
  165. if: github.event.pull_request.draft == false
  166. name: Clippy
  167. runs-on: ubuntu-latest
  168. steps:
  169. - uses: actions/checkout@v4
  170. - run: sudo apt-get update
  171. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  172. - uses: dtolnay/rust-toolchain@stable
  173. with:
  174. components: rustfmt, clippy
  175. - uses: Swatinem/rust-cache@v2
  176. with:
  177. cache-all-crates: "true"
  178. save-if: ${{ github.ref == 'refs/heads/main' }}
  179. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  180. # Only run semver checks if the PR is not a draft and does not have the breaking label
  181. # Breaking PRs don't need to follow semver since they are breaking changes
  182. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  183. # likely make future backporting difficult
  184. #
  185. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  186. #
  187. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  188. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  189. #
  190. # semver:
  191. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  192. # name: Semver Check
  193. # runs-on: ubuntu-latest
  194. # steps:
  195. # - uses: actions/checkout@v4
  196. # - uses: dtolnay/rust-toolchain@stable
  197. # - uses: Swatinem/rust-cache@v2
  198. # with:
  199. # cache-all-crates: "true"
  200. # save-if: ${{ github.ref == 'refs/heads/main' }}
  201. # - name: Check semver
  202. # uses: obi1kenobi/cargo-semver-checks-action@v2
  203. # with:
  204. # manifest-path: ./Cargo.toml
  205. # exclude: "dioxus-cli, dioxus-ext"
  206. playwright:
  207. if: github.event.pull_request.draft == false
  208. name: Playwright Tests
  209. runs-on: ubuntu-latest
  210. steps:
  211. # Do our best to cache the toolchain and node install steps
  212. - uses: actions/checkout@v4
  213. - uses: actions/setup-node@v4
  214. with:
  215. node-version: 16
  216. - name: Free Disk Space (Ubuntu)
  217. uses: jlumbroso/free-disk-space@v1.3.1
  218. with: # speed things up a bit
  219. large-packages: false
  220. docker-images: false
  221. swap-storage: false
  222. - name: Install Rust
  223. uses: dtolnay/rust-toolchain@master
  224. with:
  225. toolchain: stable
  226. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  227. - uses: Swatinem/rust-cache@v2
  228. with:
  229. cache-all-crates: "true"
  230. save-if: ${{ github.ref == 'refs/heads/main' }}
  231. - name: Install dependencies
  232. run: npm ci
  233. working-directory: ./packages/playwright-tests
  234. - name: Install Playwright
  235. run: npm install -D @playwright/test
  236. working-directory: ./packages/playwright-tests
  237. - name: Install Playwright Browsers
  238. run: npx playwright install --with-deps
  239. working-directory: ./packages/playwright-tests
  240. - name: Run Playwright tests
  241. run: npx playwright test
  242. working-directory: ./packages/playwright-tests
  243. - uses: actions/upload-artifact@v4
  244. if: always()
  245. with:
  246. name: playwright-report
  247. path: playwright-report/
  248. retention-days: 30
  249. matrix_test:
  250. runs-on: ${{ matrix.platform.os }}
  251. if: github.event.pull_request.draft == false
  252. env:
  253. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  254. strategy:
  255. matrix:
  256. platform:
  257. - {
  258. target: x86_64-pc-windows-msvc,
  259. os: windows-latest,
  260. toolchain: "1.79.0",
  261. cross: false,
  262. command: "test",
  263. args: "--all --tests",
  264. }
  265. - {
  266. target: aarch64-apple-darwin,
  267. os: macos-latest,
  268. toolchain: "1.79.0",
  269. cross: false,
  270. command: "test",
  271. args: "--all --tests",
  272. }
  273. - {
  274. target: x86_64-apple-darwin,
  275. os: macos-13,
  276. toolchain: "1.79.0",
  277. cross: false,
  278. command: "test",
  279. args: "--all --tests",
  280. }
  281. - {
  282. target: aarch64-apple-ios,
  283. os: macos-latest,
  284. toolchain: "1.79.0",
  285. cross: false,
  286. command: "build",
  287. args: "--package dioxus-mobile",
  288. }
  289. - {
  290. target: aarch64-linux-android,
  291. os: ubuntu-latest,
  292. toolchain: "1.79.0",
  293. cross: true,
  294. command: "build",
  295. args: "--package dioxus-mobile",
  296. }
  297. steps:
  298. - uses: actions/checkout@v4
  299. - name: Free Disk Space (Ubuntu)
  300. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  301. uses: jlumbroso/free-disk-space@v1.3.1
  302. with: # speed things up a bit
  303. large-packages: false
  304. docker-images: false
  305. swap-storage: false
  306. - name: install stable
  307. uses: dtolnay/rust-toolchain@master
  308. with:
  309. toolchain: ${{ matrix.platform.toolchain }}
  310. targets: ${{ matrix.platform.target }}
  311. components: rustfmt
  312. - name: Install nasm for windows (tls)
  313. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  314. uses: ilammy/setup-nasm@v1
  315. - name: Install cross
  316. if: ${{ matrix.platform.cross == true }}
  317. uses: taiki-e/install-action@cross
  318. - uses: Swatinem/rust-cache@v2
  319. with:
  320. key: "${{ matrix.platform.target }}"
  321. cache-all-crates: "true"
  322. save-if: ${{ github.ref == 'refs/heads/main' }}
  323. - name: test
  324. run: |
  325. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}