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