unit-tests.yml 6.6 KB

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