unit-tests.yml 5.8 KB

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