unit-tests.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 curl git
  96. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.74 -y
  97. . ~/.cargo/env
  98. cargo install cargo-hack
  99. git config --global --add safe.directory /home/runner/work/eza/eza
  100. run: |
  101. set -e
  102. . ~/.cargo/env
  103. export CARGO_TERM_COLOR="always"
  104. export RUSTFLAGS="--deny warnings"
  105. cargo fmt --check
  106. cargo clippy -- -D warnings
  107. cargo hack test
  108. unit-tests-netbsd:
  109. needs: conventional
  110. runs-on: ubuntu-22.04
  111. timeout-minutes: 20
  112. steps:
  113. - uses: actions/checkout@v4
  114. with:
  115. submodules: recursive
  116. - name: Compile
  117. uses: vmactions/netbsd-vm@v1
  118. with:
  119. release: '10.1'
  120. usesh: true
  121. prepare: |
  122. PATH="/root/.cargo/bin:/usr/pkg/sbin:/usr/pkg/bin:$PATH"
  123. PKG_PATH="https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/10.1/All/"
  124. export PATH PKG_PATH
  125. /usr/sbin/pkg_add pkgin
  126. pkgin -y install rust git
  127. cargo install cargo-hack
  128. git config --global --add safe.directory /home/runner/work/eza/eza
  129. run: |
  130. set -e
  131. export CARGO_TERM_COLOR="always"
  132. export RUSTFLAGS="--deny warnings"
  133. cargo fmt --check
  134. cargo clippy -- -D warnings
  135. cargo hack test
  136. unit-tests-openbsd:
  137. needs: conventional
  138. runs-on: ubuntu-22.04
  139. timeout-minutes: 20
  140. steps:
  141. - uses: actions/checkout@v4
  142. with:
  143. submodules: recursive
  144. - name: Compile
  145. uses: vmactions/openbsd-vm@v1
  146. with:
  147. release: '7.6'
  148. usesh: true
  149. prepare: |
  150. pkg_add rust rust-rustfmt rust-clippy git
  151. cargo install cargo-hack
  152. git config --global --add safe.directory /home/runner/work/eza/eza
  153. run: |
  154. set -e
  155. export CARGO_TERM_COLOR="always"
  156. export RUSTFLAGS="--deny warnings"
  157. cargo fmt --check
  158. cargo clippy -- -D warnings
  159. cargo hack test
  160. flake-check:
  161. needs: conventional
  162. name: Check Nix Flake
  163. runs-on: ubuntu-latest
  164. strategy:
  165. matrix:
  166. checks: [build, formatting, lint, pre-commit-check, test, trycmd]
  167. target: [x86_64-linux]
  168. steps:
  169. - uses: actions/checkout@v4
  170. - name: Install Nix
  171. uses: DeterminateSystems/nix-installer-action@v16
  172. - name: Setup Nix cache
  173. uses: DeterminateSystems/magic-nix-cache-action@main
  174. - name: Nix Flake Check
  175. run: nix build .#checks.${{ matrix.target }}.${{ matrix.checks }} -L
  176. flake-build:
  177. needs: conventional
  178. name: Build Nix package
  179. # if cross compilation is desired add 'aarch64-linux', 'x86_64-darwin' and 'aarch64-darwin' and fix the flake to support cross compilation.
  180. strategy:
  181. matrix:
  182. target: [x86_64-linux]
  183. runs-on: ubuntu-latest
  184. steps:
  185. - uses: actions/checkout@v4
  186. - name: Install Nix
  187. uses: DeterminateSystems/nix-installer-action@v16
  188. - name: Setup Nix cache
  189. uses: DeterminateSystems/magic-nix-cache-action@main
  190. - name: Nix Build
  191. run: nix build .#packages.${{ matrix.target }}.default -L