main.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. - uses: ilammy/setup-nasm@v1
  51. - run: cargo check --all --examples --tests --all-features --all-targets
  52. test:
  53. if: github.event.pull_request.draft == false
  54. name: Test Suite
  55. runs-on: ubuntu-latest
  56. steps:
  57. - uses: actions/checkout@v4
  58. - run: sudo apt-get update
  59. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  60. - uses: dtolnay/rust-toolchain@stable
  61. - uses: Swatinem/rust-cache@v2
  62. with:
  63. cache-all-crates: "true"
  64. save-if: ${{ github.ref == 'refs/heads/main' }}
  65. - uses: ilammy/setup-nasm@v1
  66. - uses: davidB/rust-cargo-make@v1
  67. - uses: browser-actions/setup-firefox@latest
  68. - uses: jetli/wasm-pack-action@v0.4.0
  69. - name: Free Disk Space (Ubuntu)
  70. uses: jlumbroso/free-disk-space@v1.3.1
  71. with: # speed things up a bit
  72. large-packages: false
  73. docker-images: false
  74. swap-storage: false
  75. - run: cargo make tests
  76. fmt:
  77. if: github.event.pull_request.draft == false
  78. name: Rustfmt
  79. runs-on: ubuntu-latest
  80. steps:
  81. - uses: actions/checkout@v4
  82. - uses: ilammy/setup-nasm@v1
  83. - uses: dtolnay/rust-toolchain@stable
  84. with:
  85. components: rustfmt
  86. - uses: Swatinem/rust-cache@v2
  87. with:
  88. cache-all-crates: "true"
  89. save-if: ${{ github.ref == 'refs/heads/main' }}
  90. - run: cargo fmt --all -- --check
  91. clippy:
  92. if: github.event.pull_request.draft == false
  93. name: Clippy
  94. runs-on: ubuntu-latest
  95. steps:
  96. - uses: actions/checkout@v4
  97. - run: sudo apt-get update
  98. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  99. - uses: ilammy/setup-nasm@v1
  100. - uses: dtolnay/rust-toolchain@stable
  101. with:
  102. components: rustfmt, clippy
  103. - uses: Swatinem/rust-cache@v2
  104. with:
  105. cache-all-crates: "true"
  106. save-if: ${{ github.ref == 'refs/heads/main' }}
  107. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  108. # Only run semver checks if the PR is not a draft and does not have the breaking label
  109. # Breaking PRs don't need to follow semver since they are breaking changes
  110. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  111. # likely make future backporting difficult
  112. semver:
  113. if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  114. name: Semver Check
  115. runs-on: ubuntu-latest
  116. steps:
  117. - uses: actions/checkout@v4
  118. - uses: dtolnay/rust-toolchain@stable
  119. - uses: Swatinem/rust-cache@v2
  120. with:
  121. cache-all-crates: "true"
  122. save-if: ${{ github.ref == 'refs/heads/main' }}
  123. - name: Check semver
  124. uses: obi1kenobi/cargo-semver-checks-action@v2
  125. with:
  126. manifest-path: ./Cargo.toml
  127. exclude: "dioxus-cli, dioxus-ext"
  128. playwright:
  129. if: github.event.pull_request.draft == false
  130. name: Playwright Tests
  131. runs-on: ubuntu-latest
  132. steps:
  133. # Do our best to cache the toolchain and node install steps
  134. - uses: actions/checkout@v4
  135. - uses: ilammy/setup-nasm@v1
  136. - uses: actions/setup-node@v4
  137. with:
  138. node-version: 16
  139. - name: Free Disk Space (Ubuntu)
  140. uses: jlumbroso/free-disk-space@v1.3.1
  141. with: # speed things up a bit
  142. large-packages: false
  143. docker-images: false
  144. swap-storage: false
  145. - name: Install Rust
  146. uses: dtolnay/rust-toolchain@master
  147. with:
  148. toolchain: stable
  149. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  150. - uses: Swatinem/rust-cache@v2
  151. with:
  152. cache-all-crates: "true"
  153. save-if: ${{ github.ref == 'refs/heads/main' }}
  154. - name: Install dependencies
  155. run: npm ci
  156. working-directory: ./packages/playwright-tests
  157. - name: Install Playwright
  158. run: npm install -D @playwright/test
  159. working-directory: ./packages/playwright-tests
  160. - name: Install Playwright Browsers
  161. run: npx playwright install --with-deps
  162. working-directory: ./packages/playwright-tests
  163. - name: Run Playwright tests
  164. run: npx playwright test
  165. working-directory: ./packages/playwright-tests
  166. - uses: actions/upload-artifact@v4
  167. if: always()
  168. with:
  169. name: playwright-report
  170. path: playwright-report/
  171. retention-days: 30
  172. matrix_test:
  173. runs-on: ${{ matrix.platform.os }}
  174. if: github.event.pull_request.draft == false
  175. env:
  176. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  177. strategy:
  178. matrix:
  179. platform:
  180. - {
  181. target: x86_64-pc-windows-msvc,
  182. os: windows-latest,
  183. toolchain: "1.75.0",
  184. cross: false,
  185. command: "test",
  186. args: "--all --tests",
  187. }
  188. - {
  189. target: x86_64-apple-darwin,
  190. os: macos-latest,
  191. toolchain: "1.75.0",
  192. cross: false,
  193. command: "test",
  194. args: "--all --tests",
  195. }
  196. - {
  197. target: aarch64-apple-ios,
  198. os: macos-latest,
  199. toolchain: "1.75.0",
  200. cross: false,
  201. command: "build",
  202. args: "--package dioxus-mobile",
  203. }
  204. - {
  205. target: aarch64-linux-android,
  206. os: ubuntu-latest,
  207. toolchain: "1.75.0",
  208. cross: true,
  209. command: "build",
  210. args: "--package dioxus-mobile",
  211. }
  212. steps:
  213. - uses: actions/checkout@v4
  214. - uses: ilammy/setup-nasm@v1
  215. - name: install stable
  216. uses: dtolnay/rust-toolchain@master
  217. with:
  218. toolchain: ${{ matrix.platform.toolchain }}
  219. targets: ${{ matrix.platform.target }}
  220. components: rustfmt
  221. - name: Install cross
  222. if: ${{ matrix.platform.cross == true }}
  223. uses: taiki-e/install-action@cross
  224. - name: Free Disk Space (Ubuntu)
  225. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  226. uses: jlumbroso/free-disk-space@v1.3.1
  227. with: # speed things up a bit
  228. large-packages: false
  229. docker-images: false
  230. swap-storage: false
  231. - uses: Swatinem/rust-cache@v2
  232. with:
  233. key: "${{ matrix.platform.target }}"
  234. cache-all-crates: "true"
  235. save-if: ${{ github.ref == 'refs/heads/main' }}
  236. - name: test
  237. run: |
  238. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}