main.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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: ilammy/setup-nasm@v1
  119. - uses: dtolnay/rust-toolchain@stable
  120. - uses: Swatinem/rust-cache@v2
  121. with:
  122. cache-all-crates: "true"
  123. save-if: ${{ github.ref == 'refs/heads/main' }}
  124. - name: Check semver
  125. uses: obi1kenobi/cargo-semver-checks-action@v2
  126. - run: cargo semver-checks --workspace --exclude "dioxus-cli, dioxus-ext"
  127. playwright:
  128. if: github.event.pull_request.draft == false
  129. name: Playwright Tests
  130. runs-on: ubuntu-latest
  131. steps:
  132. # Do our best to cache the toolchain and node install steps
  133. - uses: actions/checkout@v4
  134. - uses: ilammy/setup-nasm@v1
  135. - uses: actions/setup-node@v4
  136. with:
  137. node-version: 16
  138. - name: Free Disk Space (Ubuntu)
  139. uses: jlumbroso/free-disk-space@v1.3.1
  140. with: # speed things up a bit
  141. large-packages: false
  142. docker-images: false
  143. swap-storage: false
  144. - name: Install Rust
  145. uses: dtolnay/rust-toolchain@master
  146. with:
  147. toolchain: stable
  148. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  149. - uses: Swatinem/rust-cache@v2
  150. with:
  151. cache-all-crates: "true"
  152. save-if: ${{ github.ref == 'refs/heads/main' }}
  153. - name: Install dependencies
  154. run: npm ci
  155. working-directory: ./packages/playwright-tests
  156. - name: Install Playwright
  157. run: npm install -D @playwright/test
  158. working-directory: ./packages/playwright-tests
  159. - name: Install Playwright Browsers
  160. run: npx playwright install --with-deps
  161. working-directory: ./packages/playwright-tests
  162. - name: Run Playwright tests
  163. run: npx playwright test
  164. working-directory: ./packages/playwright-tests
  165. - uses: actions/upload-artifact@v4
  166. if: always()
  167. with:
  168. name: playwright-report
  169. path: playwright-report/
  170. retention-days: 30
  171. matrix_test:
  172. runs-on: ${{ matrix.platform.os }}
  173. if: github.event.pull_request.draft == false
  174. env:
  175. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  176. strategy:
  177. matrix:
  178. platform:
  179. - {
  180. target: x86_64-pc-windows-msvc,
  181. os: windows-latest,
  182. toolchain: "1.75.0",
  183. cross: false,
  184. command: "test",
  185. args: "--all --tests",
  186. }
  187. - {
  188. target: x86_64-apple-darwin,
  189. os: macos-latest,
  190. toolchain: "1.75.0",
  191. cross: false,
  192. command: "test",
  193. args: "--all --tests",
  194. }
  195. - {
  196. target: aarch64-apple-ios,
  197. os: macos-latest,
  198. toolchain: "1.75.0",
  199. cross: false,
  200. command: "build",
  201. args: "--package dioxus-mobile",
  202. }
  203. - {
  204. target: aarch64-linux-android,
  205. os: ubuntu-latest,
  206. toolchain: "1.75.0",
  207. cross: true,
  208. command: "build",
  209. args: "--package dioxus-mobile",
  210. }
  211. steps:
  212. - uses: actions/checkout@v4
  213. - uses: ilammy/setup-nasm@v1
  214. - name: install stable
  215. uses: dtolnay/rust-toolchain@master
  216. with:
  217. toolchain: ${{ matrix.platform.toolchain }}
  218. targets: ${{ matrix.platform.target }}
  219. components: rustfmt
  220. - name: Install cross
  221. if: ${{ matrix.platform.cross == true }}
  222. uses: taiki-e/install-action@cross
  223. - name: Free Disk Space (Ubuntu)
  224. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  225. uses: jlumbroso/free-disk-space@v1.3.1
  226. with: # speed things up a bit
  227. large-packages: false
  228. docker-images: false
  229. swap-storage: false
  230. - uses: Swatinem/rust-cache@v2
  231. with:
  232. key: "${{ matrix.platform.target }}"
  233. cache-all-crates: "true"
  234. save-if: ${{ github.ref == 'refs/heads/main' }}
  235. - name: test
  236. run: |
  237. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}