_build-rust.yml 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Reusable GitHub CI workflow:
  2. # More info: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses
  3. # Common Rust CI setup that checkout the repo, installs the common toolchain
  4. # and set's up the cargo cache. It builds, tests, and lints the code.
  5. on:
  6. workflow_call:
  7. inputs:
  8. rust-version:
  9. type: string
  10. required: false
  11. default: stable
  12. description: Rust version
  13. rust-target:
  14. type: string
  15. required: false
  16. default: x86_64-unknown-linux-gnu
  17. description: Rust target for the build step. Clippy and tests are still executed with the default target.
  18. features:
  19. type: string
  20. required: false
  21. # Make sure we always an empty string to "--features <FEATURES>"
  22. default: '""'
  23. description: Comma-separated String with additional Rust features relevant for a certain job.
  24. do-style-check:
  25. type: boolean
  26. required: false
  27. default: true
  28. description: Perform code and doc style checks.
  29. do-test:
  30. type: boolean
  31. required: false
  32. default: true
  33. description: Execute tests.
  34. jobs:
  35. check_rust:
  36. runs-on: ubuntu-latest
  37. steps:
  38. - name: Check out
  39. uses: actions/checkout@v3
  40. - name: Set up rustup cache
  41. uses: actions/cache@v3
  42. continue-on-error: false
  43. with:
  44. path: |
  45. ~/.rustup/downloads
  46. ~/.rustup/toolchains
  47. # key: ${{ runner.os }}-rustup-${{ inputs.rust-version }}-${{ inputs.rust-target }}-${{ hashFiles('**/rustup-toolchain.toml') }}
  48. key: ${{ runner.os }}-rustup-${{ inputs.rust-version }}-${{ inputs.rust-target }}
  49. # The effect of this is must smaller than the cache for Cargo. However, it
  50. # still saves a few seconds. Note that many CI runs within a week may
  51. # quickly bring you close to the 10GB limit:
  52. # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#managing-caches
  53. - name: Install Rust Toolchain via Rustup
  54. uses: actions-rs/toolchain@v1
  55. with:
  56. profile: minimal
  57. toolchain: ${{ inputs.rust-version }}
  58. override: true
  59. components: clippy, rustfmt
  60. target: ${{ inputs.rust-target }}
  61. - name: Set up Cargo cache
  62. uses: actions/cache@v3
  63. continue-on-error: false
  64. with:
  65. path: |
  66. ~/.cargo/bin/
  67. ~/.cargo/registry/index/
  68. ~/.cargo/registry/cache/
  69. ~/.cargo/git/db/
  70. target/
  71. # We do not have a Cargo.lock here, so I hash Cargo.toml
  72. key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml') }}
  73. - run: cargo version
  74. - name: Build (library)
  75. run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }}
  76. - name: Build (all targets)
  77. run: cargo build --all-targets --features ${{ inputs.features }}
  78. - name: Code Formatting
  79. if: ${{ inputs.do-style-check }}
  80. run: cargo fmt --all -- --check
  81. - name: Code Style and Doc Style
  82. if: ${{ inputs.do-style-check }}
  83. run: |
  84. cargo doc --document-private-items --features ${{ inputs.features }}
  85. cargo clippy --all-targets --features ${{ inputs.features }}
  86. - name: Unit Test
  87. if: ${{ inputs.do-test }}
  88. run: |
  89. curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
  90. chmod u+x cargo-nextest
  91. ./cargo-nextest nextest run --features ${{ inputs.features }}