1
0

unit-tests.yml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # SPDX-FileCopyrightText: 2024 Christina Sørensen
  2. # SPDX-License-Identifier: EUPL-1.2
  3. name: Unit tests
  4. on:
  5. push:
  6. branches: [main]
  7. pull_request:
  8. branches: [main]
  9. workflow_dispatch:
  10. concurrency:
  11. group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
  12. cancel-in-progress: true
  13. env:
  14. CARGO_TERM_COLOR: always
  15. RUSTFLAGS: --deny warnings
  16. msrv: 1.78
  17. jobs:
  18. cargo-shear:
  19. name: Run cargo shear
  20. runs-on: ubuntu-latest
  21. steps:
  22. - name: Checkout repository
  23. uses: actions/checkout@v4
  24. - name: Install Rust toolchain
  25. uses: dtolnay/rust-toolchain@stable
  26. - name: Install cargo-shear
  27. run: cargo install cargo-shear
  28. - name: Run check for unused dependencies
  29. run: cargo shear
  30. security_audit:
  31. runs-on: ubuntu-latest
  32. steps:
  33. - uses: actions/checkout@v4
  34. - uses: taiki-e/install-action@cargo-deny
  35. - name: Scan for vulnerabilities
  36. run: cargo deny check
  37. check_if_pr:
  38. runs-on: ubuntu-latest
  39. outputs:
  40. is_pr: ${{ steps.check.outputs.is_pr }}
  41. steps:
  42. - name: Check if it's a PR
  43. id: check
  44. run: |
  45. if [ "${{ github.event_name }}" == "pull_request" ]; then
  46. echo "is_pr=true" >> $GITHUB_OUTPUT
  47. else
  48. echo "is_pr=false" >> $GITHUB_OUTPUT
  49. fi
  50. no-merge-commits:
  51. needs: check_if_pr
  52. if: needs.check_if_pr.outputs.is_pr == 'true'
  53. runs-on: ubuntu-latest
  54. steps:
  55. - name: Checkout
  56. uses: actions/checkout@v4
  57. - name: Run test
  58. uses: NexusPHP/no-merge-commits@v2.2.1
  59. with:
  60. token: ${{ secrets.GITHUB_TOKEN }}
  61. conventional:
  62. needs: [check_if_pr, no-merge-commits]
  63. name: Conventional Commits
  64. runs-on: ubuntu-latest
  65. steps:
  66. - uses: actions/checkout@v4
  67. - uses: webiny/action-conventional-commits@v1.3.0
  68. unit-tests:
  69. needs: conventional
  70. runs-on: ${{ matrix.os }}
  71. continue-on-error: ${{ matrix.rust == 'nightly' }}
  72. strategy:
  73. matrix:
  74. os: [ubuntu-latest, macos-latest, windows-latest]
  75. rust: [msrv, stable, beta, nightly]
  76. steps:
  77. - name: Checkout repository
  78. uses: actions/checkout@v4
  79. - run: rustup toolchain install ${{ matrix.rust == 'msrv' && env.msrv || matrix.rust }} --profile minimal
  80. - uses: Swatinem/rust-cache@v2
  81. - name: Install cargo-hack
  82. uses: nick-fields/retry@v3
  83. with:
  84. timeout_minutes: 5
  85. max_attempts: 5
  86. command: cargo install cargo-hack
  87. - name: Run rustfmt checks
  88. run: cargo fmt --check
  89. - name: Run clippy lints
  90. if: ${{ matrix.os != 'windows-latest' }}
  91. run: cargo clippy -- -D warnings
  92. - name: Run unit tests
  93. run: cargo hack test
  94. unit-tests-freebsd:
  95. needs: conventional
  96. runs-on: ubuntu-22.04
  97. timeout-minutes: 20
  98. continue-on-error: ${{ matrix.rust == 'nightly' }}
  99. strategy:
  100. matrix:
  101. rust: [msrv, stable, beta, nightly]
  102. steps:
  103. - uses: actions/checkout@v4
  104. with:
  105. submodules: recursive
  106. - name: Compile
  107. uses: vmactions/freebsd-vm@v1
  108. with:
  109. release: '14.3'
  110. usesh: true
  111. prepare: |
  112. pkg install -y curl git
  113. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain ${{ matrix.rust == 'msrv' && env.msrv || matrix.rust }} --profile minimal -y
  114. . ~/.cargo/env
  115. cargo install cargo-hack
  116. git config --global --add safe.directory /home/runner/work/eza/eza
  117. run: |
  118. set -e
  119. . ~/.cargo/env
  120. export CARGO_TERM_COLOR="always"
  121. export RUSTFLAGS="--deny warnings"
  122. cargo fmt --check
  123. cargo clippy -- -D warnings
  124. cargo hack test
  125. unit-tests-netbsd:
  126. needs: conventional
  127. runs-on: ubuntu-22.04
  128. timeout-minutes: 20
  129. continue-on-error: ${{ matrix.rust == 'nightly' }}
  130. strategy:
  131. matrix:
  132. rust: [msrv, stable, beta, nightly]
  133. steps:
  134. - uses: actions/checkout@v4
  135. with:
  136. submodules: recursive
  137. - name: Compile
  138. uses: vmactions/netbsd-vm@v1
  139. with:
  140. release: '10.1'
  141. usesh: true
  142. prepare: |
  143. PATH="/root/.cargo/bin:/usr/pkg/sbin:/usr/pkg/bin:$PATH"
  144. PKG_PATH="https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/10.1/All/"
  145. export PATH PKG_PATH
  146. /usr/sbin/pkg_add curl git
  147. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain ${{ matrix.rust == 'msrv' && env.msrv || matrix.rust }} --profile minimal -y
  148. . ~/.cargo/env
  149. cargo install cargo-hack
  150. git config --global --add safe.directory /home/runner/work/eza/eza
  151. run: |
  152. set -e
  153. . ~/.cargo/env
  154. export CARGO_TERM_COLOR="always"
  155. export RUSTFLAGS="--deny warnings"
  156. cargo fmt --check
  157. cargo clippy -- -D warnings
  158. cargo hack test
  159. unit-tests-openbsd:
  160. needs: conventional
  161. runs-on: ubuntu-22.04
  162. timeout-minutes: 20
  163. steps:
  164. - uses: actions/checkout@v4
  165. with:
  166. submodules: recursive
  167. - name: Compile
  168. uses: vmactions/openbsd-vm@v1
  169. with:
  170. release: '7.7'
  171. usesh: true
  172. prepare: |
  173. pkg_add rust rust-rustfmt rust-clippy git
  174. cargo install cargo-hack
  175. git config --global --add safe.directory /home/runner/work/eza/eza
  176. run: |
  177. set -e
  178. export CARGO_TERM_COLOR="always"
  179. export RUSTFLAGS="--deny warnings"
  180. cargo fmt --check
  181. cargo clippy -- -D warnings
  182. cargo hack test
  183. flake-check:
  184. needs: conventional
  185. name: Check Nix Flake
  186. runs-on: ubuntu-latest
  187. strategy:
  188. matrix:
  189. checks: [build, formatting, lint, pre-commit-check, test, trycmd]
  190. target: [x86_64-linux]
  191. steps:
  192. - uses: actions/checkout@v4
  193. - name: Install Nix
  194. uses: DeterminateSystems/nix-installer-action@v17
  195. - name: Nix Flake Check
  196. run: nix build .#checks.${{ matrix.target }}.${{ matrix.checks }} -L
  197. flake-build:
  198. needs: conventional
  199. name: Build Nix package
  200. # if cross compilation is desired add 'aarch64-linux', 'x86_64-darwin' and 'aarch64-darwin' and fix the flake to support cross compilation.
  201. strategy:
  202. matrix:
  203. target: [x86_64-linux]
  204. runs-on: ubuntu-latest
  205. steps:
  206. - uses: actions/checkout@v4
  207. - name: Install Nix
  208. uses: DeterminateSystems/nix-installer-action@v17
  209. - name: Nix Build
  210. run: nix build .#packages.${{ matrix.target }}.default -L