unit-tests.yml 5.6 KB

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