unit-tests.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. flake-check:
  75. needs: conventional
  76. name: Check Nix Flake
  77. runs-on: ubuntu-latest
  78. strategy:
  79. matrix:
  80. checks: [build, formatting, lint, pre-commit-check, test, trycmd]
  81. target: [x86_64-linux]
  82. steps:
  83. - uses: actions/checkout@v4
  84. - name: Install Nix
  85. uses: DeterminateSystems/nix-installer-action@v16
  86. - name: Setup Nix cache
  87. uses: DeterminateSystems/magic-nix-cache-action@main
  88. - name: Nix Flake Check
  89. run: nix build .#checks.${{ matrix.target }}.${{ matrix.checks }} -L
  90. flake-build:
  91. needs: conventional
  92. name: Build Nix package
  93. # if cross compilation is desired add 'aarch64-linux', 'x86_64-darwin' and 'aarch64-darwin' and fix the flake to support cross compilation.
  94. strategy:
  95. matrix:
  96. target: [x86_64-linux]
  97. runs-on: ubuntu-latest
  98. steps:
  99. - uses: actions/checkout@v4
  100. - name: Install Nix
  101. uses: DeterminateSystems/nix-installer-action@v16
  102. - name: Setup Nix cache
  103. uses: DeterminateSystems/magic-nix-cache-action@main
  104. - name: Nix Build
  105. run: nix build .#packages.${{ matrix.target }}.default -L