main.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. RUST_BACKTRACE: 1
  37. rust_nightly: nightly-2024-07-01
  38. jobs:
  39. check-msrv:
  40. if: github.event.pull_request.draft == false
  41. name: Check MSRV
  42. runs-on: ubuntu-latest
  43. steps:
  44. - uses: actions/checkout@v4
  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. # https://github.com/foresterre/cargo-msrv/blob/4345edfe3f4fc91cc8ae6c7d6804c0748fae92ae/.github/workflows/msrv.yml
  51. - name: install_cargo_msrv
  52. run: cargo install cargo-msrv --all-features
  53. - name: version_of_cargo_msrv
  54. run: cargo msrv --version
  55. - name: run_cargo_msrv
  56. run: cargo msrv --output-format json verify -- cargo check
  57. - name: run_cargo_msrv_on_verify_failure
  58. if: ${{ failure() }}
  59. run: cargo msrv --output-format json -- cargo check
  60. test:
  61. if: github.event.pull_request.draft == false
  62. name: Test Suite
  63. runs-on: ubuntu-latest
  64. steps:
  65. - uses: actions/checkout@v4
  66. - name: Free Disk Space (Ubuntu)
  67. uses: jlumbroso/free-disk-space@v1.3.1
  68. with: # speed things up a bit
  69. large-packages: false
  70. docker-images: false
  71. swap-storage: false
  72. - run: sudo apt-get update
  73. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  74. - uses: dtolnay/rust-toolchain@stable
  75. - uses: Swatinem/rust-cache@v2
  76. with:
  77. cache-all-crates: "true"
  78. save-if: ${{ github.ref == 'refs/heads/main' }}
  79. - uses: davidB/rust-cargo-make@v1
  80. - uses: browser-actions/setup-firefox@latest
  81. - uses: jetli/wasm-pack-action@v0.4.0
  82. - run: cargo make tests
  83. release-test:
  84. if: github.event.pull_request.draft == false
  85. name: Test Suite with Optimizations
  86. runs-on: ubuntu-latest
  87. steps:
  88. - uses: actions/checkout@v4
  89. - name: Free Disk Space (Ubuntu)
  90. uses: jlumbroso/free-disk-space@v1.3.1
  91. with: # speed things up a bit
  92. large-packages: false
  93. docker-images: false
  94. swap-storage: false
  95. - run: sudo apt-get update
  96. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  97. - uses: dtolnay/rust-toolchain@stable
  98. - uses: Swatinem/rust-cache@v2
  99. with:
  100. cache-all-crates: "true"
  101. save-if: ${{ github.ref == 'refs/heads/main' }}
  102. - uses: davidB/rust-cargo-make@v1
  103. - uses: browser-actions/setup-firefox@latest
  104. - uses: jetli/wasm-pack-action@v0.4.0
  105. - run: cargo test --profile release-unoptimized --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile
  106. fmt:
  107. if: github.event.pull_request.draft == false
  108. name: Rustfmt
  109. runs-on: ubuntu-latest
  110. steps:
  111. - uses: actions/checkout@v4
  112. - uses: dtolnay/rust-toolchain@stable
  113. with:
  114. components: rustfmt
  115. - uses: Swatinem/rust-cache@v2
  116. with:
  117. cache-all-crates: "true"
  118. save-if: ${{ github.ref == 'refs/heads/main' }}
  119. - run: cargo fmt --all -- --check
  120. typos:
  121. if: github.event.pull_request.draft == false
  122. name: Check for typos
  123. runs-on: ubuntu-latest
  124. steps:
  125. - uses: actions/checkout@v4
  126. - name: Check for typos
  127. uses: crate-ci/typos@master
  128. docs:
  129. if: github.event.pull_request.draft == false
  130. name: Docs
  131. runs-on: ubuntu-latest
  132. steps:
  133. - uses: actions/checkout@v4
  134. - name: Install Rust ${{ env.rust_nightly }}
  135. uses: dtolnay/rust-toolchain@stable
  136. with:
  137. toolchain: ${{ env.rust_nightly }}
  138. - uses: Swatinem/rust-cache@v2
  139. with:
  140. cache-all-crates: "true"
  141. save-if: ${{ github.ref == 'refs/heads/main' }}
  142. - name: "doc --lib --all-features"
  143. run: |
  144. cargo doc --workspace --no-deps --all-features --document-private-items
  145. env:
  146. RUSTFLAGS: --cfg docsrs
  147. RUSTDOCFLAGS: --cfg docsrs
  148. # todo: re-enable warnings
  149. # RUSTDOCFLAGS: --cfg docsrs -Dwarnings
  150. # Check for invalid links in the repository
  151. link-check:
  152. if: github.event.pull_request.draft == false
  153. name: Check For Invalid Links
  154. runs-on: ubuntu-latest
  155. steps:
  156. - uses: actions/checkout@v4
  157. - name: Restore lychee cache
  158. uses: actions/cache@v3
  159. with:
  160. path: .lycheecache
  161. key: cache-lychee-${{ github.sha }}
  162. restore-keys: cache-lychee-
  163. - name: Run lychee
  164. uses: lycheeverse/lychee-action@v1
  165. with:
  166. args: --base . --config ./lychee.toml './**/*.md'
  167. fail: true
  168. check:
  169. if: github.event.pull_request.draft == false
  170. name: Check
  171. runs-on: ubuntu-latest
  172. steps:
  173. - uses: actions/checkout@v4
  174. - run: sudo apt-get update
  175. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  176. - uses: dtolnay/rust-toolchain@stable
  177. - uses: Swatinem/rust-cache@v2
  178. with:
  179. cache-all-crates: "true"
  180. save-if: ${{ github.ref == 'refs/heads/main' }}
  181. - run: cargo check --workspace --all-features --all-targets
  182. clippy:
  183. if: github.event.pull_request.draft == false
  184. name: Clippy
  185. runs-on: ubuntu-latest
  186. steps:
  187. - uses: actions/checkout@v4
  188. - run: sudo apt-get update
  189. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  190. - uses: dtolnay/rust-toolchain@stable
  191. with:
  192. components: rustfmt, clippy
  193. - uses: Swatinem/rust-cache@v2
  194. with:
  195. cache-all-crates: "true"
  196. save-if: ${{ github.ref == 'refs/heads/main' }}
  197. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  198. # Only run semver checks if the PR is not a draft and does not have the breaking label
  199. # Breaking PRs don't need to follow semver since they are breaking changes
  200. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  201. # likely make future backporting difficult
  202. #
  203. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  204. #
  205. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  206. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  207. #
  208. # semver:
  209. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  210. # name: Semver Check
  211. # runs-on: ubuntu-latest
  212. # steps:
  213. # - uses: actions/checkout@v4
  214. # - uses: dtolnay/rust-toolchain@stable
  215. # - uses: Swatinem/rust-cache@v2
  216. # with:
  217. # cache-all-crates: "true"
  218. # save-if: ${{ github.ref == 'refs/heads/main' }}
  219. # - name: Check semver
  220. # uses: obi1kenobi/cargo-semver-checks-action@v2
  221. # with:
  222. # manifest-path: ./Cargo.toml
  223. # exclude: "dioxus-cli, dioxus-ext"
  224. playwright:
  225. if: github.event.pull_request.draft == false
  226. name: Playwright Tests
  227. runs-on: ubuntu-latest
  228. steps:
  229. # Do our best to cache the toolchain and node install steps
  230. - uses: actions/checkout@v4
  231. - uses: actions/setup-node@v4
  232. with:
  233. node-version: 16
  234. - name: Free Disk Space (Ubuntu)
  235. uses: jlumbroso/free-disk-space@v1.3.1
  236. with: # speed things up a bit
  237. large-packages: false
  238. docker-images: false
  239. swap-storage: false
  240. - name: Install Rust
  241. uses: dtolnay/rust-toolchain@master
  242. with:
  243. toolchain: stable
  244. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  245. - uses: Swatinem/rust-cache@v2
  246. with:
  247. cache-all-crates: "true"
  248. save-if: ${{ github.ref == 'refs/heads/main' }}
  249. - name: Install dependencies
  250. run: npm ci
  251. working-directory: ./packages/playwright-tests
  252. - name: Install Playwright
  253. run: npm install -D @playwright/test
  254. working-directory: ./packages/playwright-tests
  255. - name: Install Playwright Browsers
  256. run: npx playwright install --with-deps
  257. working-directory: ./packages/playwright-tests
  258. - name: Run Playwright tests
  259. run: npx playwright test
  260. working-directory: ./packages/playwright-tests
  261. - uses: actions/upload-artifact@v4
  262. if: always()
  263. with:
  264. name: playwright-report
  265. path: playwright-report/
  266. retention-days: 30
  267. matrix_test:
  268. runs-on: ${{ matrix.platform.os }}
  269. if: github.event.pull_request.draft == false
  270. env:
  271. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  272. strategy:
  273. matrix:
  274. platform:
  275. - {
  276. target: x86_64-pc-windows-msvc,
  277. os: windows-latest,
  278. toolchain: "1.79.0",
  279. cross: false,
  280. command: "test",
  281. args: "--all --tests",
  282. }
  283. - {
  284. target: aarch64-apple-darwin,
  285. os: macos-latest,
  286. toolchain: "1.79.0",
  287. cross: false,
  288. command: "test",
  289. args: "--all --tests",
  290. }
  291. - {
  292. target: x86_64-apple-darwin,
  293. os: macos-13,
  294. toolchain: "1.79.0",
  295. cross: false,
  296. command: "test",
  297. args: "--all --tests",
  298. }
  299. - {
  300. target: aarch64-apple-ios,
  301. os: macos-latest,
  302. toolchain: "1.79.0",
  303. cross: false,
  304. command: "build",
  305. args: "--package dioxus-mobile",
  306. }
  307. - {
  308. target: aarch64-linux-android,
  309. os: ubuntu-latest,
  310. toolchain: "1.79.0",
  311. cross: true,
  312. command: "build",
  313. args: "--package dioxus-mobile",
  314. }
  315. steps:
  316. - uses: actions/checkout@v4
  317. - name: Free Disk Space (Ubuntu)
  318. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  319. uses: jlumbroso/free-disk-space@v1.3.1
  320. with: # speed things up a bit
  321. large-packages: false
  322. docker-images: false
  323. swap-storage: false
  324. - name: install stable
  325. uses: dtolnay/rust-toolchain@master
  326. with:
  327. toolchain: ${{ matrix.platform.toolchain }}
  328. targets: ${{ matrix.platform.target }}
  329. components: rustfmt
  330. - name: Install nasm for windows (tls)
  331. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  332. uses: ilammy/setup-nasm@v1
  333. - name: Install cross
  334. if: ${{ matrix.platform.cross == true }}
  335. uses: taiki-e/install-action@cross
  336. - uses: Swatinem/rust-cache@v2
  337. with:
  338. key: "${{ matrix.platform.target }}"
  339. cache-all-crates: "true"
  340. save-if: ${{ github.ref == 'refs/heads/main' }}
  341. - name: test
  342. run: |
  343. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}