main.yml 9.5 KB

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