main.yml 9.7 KB

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