main.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. jobs:
  37. check:
  38. if: github.event.pull_request.draft == false
  39. name: Check
  40. runs-on: ubuntu-latest
  41. steps:
  42. - uses: actions/checkout@v4
  43. - run: sudo apt-get update
  44. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  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. - run: cargo check --all --examples --tests --all-features --all-targets
  51. check-msrv:
  52. if: github.event.pull_request.draft == false
  53. name: Check MSRV
  54. runs-on: ubuntu-latest
  55. steps:
  56. - uses: actions/checkout@v4
  57. - uses: dtolnay/rust-toolchain@stable
  58. - uses: Swatinem/rust-cache@v2
  59. with:
  60. cache-all-crates: "true"
  61. save-if: ${{ github.ref == 'refs/heads/main' }}
  62. # https://github.com/foresterre/cargo-msrv/blob/4345edfe3f4fc91cc8ae6c7d6804c0748fae92ae/.github/workflows/msrv.yml
  63. - name: install_cargo_msrv
  64. run: cargo install cargo-msrv --all-features
  65. - name: version_of_cargo_msrv
  66. run: cargo msrv --version
  67. - name: run_cargo_msrv
  68. run: cargo msrv --output-format json verify -- cargo check
  69. - name: run_cargo_msrv_on_verify_failure
  70. if: ${{ failure() }}
  71. run: cargo msrv --output-format json -- cargo check
  72. test:
  73. if: github.event.pull_request.draft == false
  74. name: Test Suite
  75. runs-on: ubuntu-latest
  76. steps:
  77. - uses: actions/checkout@v4
  78. - name: Free Disk Space (Ubuntu)
  79. uses: jlumbroso/free-disk-space@v1.3.1
  80. with: # speed things up a bit
  81. large-packages: false
  82. docker-images: false
  83. swap-storage: false
  84. - run: sudo apt-get update
  85. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  86. - uses: dtolnay/rust-toolchain@stable
  87. - uses: Swatinem/rust-cache@v2
  88. with:
  89. cache-all-crates: "true"
  90. save-if: ${{ github.ref == 'refs/heads/main' }}
  91. - uses: davidB/rust-cargo-make@v1
  92. - uses: browser-actions/setup-firefox@latest
  93. - uses: jetli/wasm-pack-action@v0.4.0
  94. - run: cargo make tests
  95. release-test:
  96. if: github.event.pull_request.draft == false
  97. name: Test Suite with Optimizations
  98. runs-on: ubuntu-latest
  99. steps:
  100. - uses: actions/checkout@v4
  101. - name: Free Disk Space (Ubuntu)
  102. uses: jlumbroso/free-disk-space@v1.3.1
  103. with: # speed things up a bit
  104. large-packages: false
  105. docker-images: false
  106. swap-storage: false
  107. - run: sudo apt-get update
  108. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  109. - uses: dtolnay/rust-toolchain@stable
  110. - uses: Swatinem/rust-cache@v2
  111. with:
  112. cache-all-crates: "true"
  113. save-if: ${{ github.ref == 'refs/heads/main' }}
  114. - uses: davidB/rust-cargo-make@v1
  115. - uses: browser-actions/setup-firefox@latest
  116. - uses: jetli/wasm-pack-action@v0.4.0
  117. - run: cargo test --profile release-unoptimized --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile
  118. fmt:
  119. if: github.event.pull_request.draft == false
  120. name: Rustfmt
  121. runs-on: ubuntu-latest
  122. steps:
  123. - uses: actions/checkout@v4
  124. - uses: dtolnay/rust-toolchain@stable
  125. with:
  126. components: rustfmt
  127. - uses: Swatinem/rust-cache@v2
  128. with:
  129. cache-all-crates: "true"
  130. save-if: ${{ github.ref == 'refs/heads/main' }}
  131. - run: cargo fmt --all -- --check
  132. typos:
  133. if: github.event.pull_request.draft == false
  134. name: Check for typos
  135. runs-on: ubuntu-latest
  136. steps:
  137. - uses: actions/checkout@v4
  138. - name: Check for typos
  139. uses: crate-ci/typos@master
  140. clippy:
  141. if: github.event.pull_request.draft == false
  142. name: Clippy
  143. runs-on: ubuntu-latest
  144. steps:
  145. - uses: actions/checkout@v4
  146. - run: sudo apt-get update
  147. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  148. - uses: dtolnay/rust-toolchain@stable
  149. with:
  150. components: rustfmt, clippy
  151. - uses: Swatinem/rust-cache@v2
  152. with:
  153. cache-all-crates: "true"
  154. save-if: ${{ github.ref == 'refs/heads/main' }}
  155. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  156. # Only run semver checks if the PR is not a draft and does not have the breaking label
  157. # Breaking PRs don't need to follow semver since they are breaking changes
  158. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  159. # likely make future backporting difficult
  160. #
  161. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  162. #
  163. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  164. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  165. #
  166. # semver:
  167. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  168. # name: Semver Check
  169. # runs-on: ubuntu-latest
  170. # steps:
  171. # - uses: actions/checkout@v4
  172. # - uses: dtolnay/rust-toolchain@stable
  173. # - uses: Swatinem/rust-cache@v2
  174. # with:
  175. # cache-all-crates: "true"
  176. # save-if: ${{ github.ref == 'refs/heads/main' }}
  177. # - name: Check semver
  178. # uses: obi1kenobi/cargo-semver-checks-action@v2
  179. # with:
  180. # manifest-path: ./Cargo.toml
  181. # exclude: "dioxus-cli, dioxus-ext"
  182. playwright:
  183. if: github.event.pull_request.draft == false
  184. name: Playwright Tests
  185. runs-on: ubuntu-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: Free Disk Space (Ubuntu)
  193. uses: jlumbroso/free-disk-space@v1.3.1
  194. with: # speed things up a bit
  195. large-packages: false
  196. docker-images: false
  197. swap-storage: false
  198. - name: Install Rust
  199. uses: dtolnay/rust-toolchain@master
  200. with:
  201. toolchain: stable
  202. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  203. - uses: Swatinem/rust-cache@v2
  204. with:
  205. cache-all-crates: "true"
  206. save-if: ${{ github.ref == 'refs/heads/main' }}
  207. - name: Install dependencies
  208. run: npm ci
  209. working-directory: ./packages/playwright-tests
  210. - name: Install Playwright
  211. run: npm install -D @playwright/test
  212. working-directory: ./packages/playwright-tests
  213. - name: Install Playwright Browsers
  214. run: npx playwright install --with-deps
  215. working-directory: ./packages/playwright-tests
  216. - name: Run Playwright tests
  217. run: npx playwright test
  218. working-directory: ./packages/playwright-tests
  219. - uses: actions/upload-artifact@v4
  220. if: always()
  221. with:
  222. name: playwright-report
  223. path: playwright-report/
  224. retention-days: 30
  225. matrix_test:
  226. runs-on: ${{ matrix.platform.os }}
  227. if: github.event.pull_request.draft == false
  228. env:
  229. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  230. strategy:
  231. matrix:
  232. platform:
  233. - {
  234. target: x86_64-pc-windows-msvc,
  235. os: windows-latest,
  236. toolchain: "1.79.0",
  237. cross: false,
  238. command: "test",
  239. args: "--all --tests",
  240. }
  241. - {
  242. target: aarch64-apple-darwin,
  243. os: macos-latest,
  244. toolchain: "1.79.0",
  245. cross: false,
  246. command: "test",
  247. args: "--all --tests",
  248. }
  249. - {
  250. target: x86_64-apple-darwin,
  251. os: macos-13,
  252. toolchain: "1.79.0",
  253. cross: false,
  254. command: "test",
  255. args: "--all --tests",
  256. }
  257. - {
  258. target: aarch64-apple-ios,
  259. os: macos-latest,
  260. toolchain: "1.79.0",
  261. cross: false,
  262. command: "build",
  263. args: "--package dioxus-mobile",
  264. }
  265. - {
  266. target: aarch64-linux-android,
  267. os: ubuntu-latest,
  268. toolchain: "1.79.0",
  269. cross: true,
  270. command: "build",
  271. args: "--package dioxus-mobile",
  272. }
  273. steps:
  274. - uses: actions/checkout@v4
  275. - name: Free Disk Space (Ubuntu)
  276. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  277. uses: jlumbroso/free-disk-space@v1.3.1
  278. with: # speed things up a bit
  279. large-packages: false
  280. docker-images: false
  281. swap-storage: false
  282. - name: install stable
  283. uses: dtolnay/rust-toolchain@master
  284. with:
  285. toolchain: ${{ matrix.platform.toolchain }}
  286. targets: ${{ matrix.platform.target }}
  287. components: rustfmt
  288. - name: Install nasm for windows (tls)
  289. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  290. uses: ilammy/setup-nasm@v1
  291. - name: Install cross
  292. if: ${{ matrix.platform.cross == true }}
  293. uses: taiki-e/install-action@cross
  294. - uses: Swatinem/rust-cache@v2
  295. with:
  296. key: "${{ matrix.platform.target }}"
  297. cache-all-crates: "true"
  298. save-if: ${{ github.ref == 'refs/heads/main' }}
  299. - name: test
  300. run: |
  301. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}