123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- # Reusable GitHub CI workflow:
- # More info: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses
- # Common Rust CI setup that checkout the repo, installs the common toolchain
- # and set's up the cargo cache. It builds, tests, and lints the code, but is
- # configurable. This way, the same workflow can be used to build, test, and lint
- # all in different steps, but with the same cache.
- on:
- workflow_call:
- inputs:
- runs-on:
- type: string
- required: false
- default: ubuntu-latest
- description: |
- The value for the "runs-on" property: e.g.
- - ubuntu-latest
- - windows-latest
- rust-version:
- type: string
- required: false
- default: stable
- description: Rust version
- rust-target:
- type: string
- required: false
- default: x86_64-unknown-linux-gnu
- description: Rust target for the build step. Clippy and tests are still executed with the default target.
- features:
- type: string
- required: false
- # Make sure we always an empty string to "--features <FEATURES>"
- default: '""'
- description: >
- Comma-separated string with additional crate features. Empty string by
- default. CAUTION: For Windows CI runners, this must be '""' as is,
- i.e., the string itself must be "". This is a limitation of the
- Windows power shell. This might be configured like this:
- features: >
- '""'
- do-style-check:
- type: boolean
- required: false
- default: true
- description: Perform code and doc style checks.
- do-test:
- type: boolean
- required: false
- default: true
- description: Execute tests.
- do-miri:
- type: boolean
- required: false
- default: false
- description: Execute unit tests with miri.
- jobs:
- rust:
- runs-on: ${{ inputs.runs-on }}
- steps:
- - name: Check out
- uses: actions/checkout@v4
- - name: Install Rust toolchain
- uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: ${{ inputs.rust-version }}
- override: true
- components: clippy, rustfmt
- target: ${{ inputs.rust-target }}
- - name: Set up cargo cache
- uses: actions/cache@v3
- continue-on-error: false
- with:
- path: |
- ~/.cargo/bin/
- ~/.cargo/registry/index/
- ~/.cargo/registry/cache/
- ~/.cargo/git/db/
- target/
- # Hash over Cargo.toml and Cargo.lock, as this might be copied to
- # projects that do not have a Cargo.lock in their repository tree!
- key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
- - run: cargo version
- - name: Build (library)
- run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }} --no-default-features
- - name: Build (all targets)
- run: cargo build --all-targets --features ${{ inputs.features }} --no-default-features
- - name: Code Formatting
- if: inputs.do-style-check
- run: cargo fmt --all -- --check
- - name: Code Style and Doc Style
- if: inputs.do-style-check
- run: |
- cargo doc --document-private-items --features ${{ inputs.features }} --no-default-features
- cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features
- - name: Unit Test (UNIX)
- if: inputs.do-test && runner.os != 'Windows'
- run: |
- curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
- chmod u+x cargo-nextest
- ./cargo-nextest nextest run --features ${{ inputs.features }} --no-default-features
- - name: Unit Test (Windows)
- if: inputs.do-test && runner.os == 'Windows'
- run: |
- Invoke-WebRequest https://get.nexte.st/latest/windows -OutFile cargo-nextest.zip
- Expand-Archive .\cargo-nextest.zip
- cp .\cargo-nextest/cargo-nextest.exe .
- .\cargo-nextest.exe nextest run --features ${{ inputs.features }} --no-default-features
- - name: Unit Test with Miri
- if: inputs.do-miri
- # "--tests" so that the doctests are skipped. Currently, the doctest
- # in miri fails.
- run: |
- rustup component add miri
- cargo miri test --tests
|