Add Nix-based build environment, update CI pipeline to use it, add contribution guide #114
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test and Analyze | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_TEST_TIME_UNIT: 60,120 | |
| RUST_TEST_TIME_INTEGRATION: 60,120 | |
| RUST_TEST_TIME_DOCTEST: 60,120 | |
| jobs: | |
| test: | |
| name: test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| crate: [ libcoap-sys, libcoap-rs ] | |
| dtls_backend: [ openssl, gnutls, tinydtls, mbedtls ] | |
| rust_version: [ msrv, stable, nightly ] | |
| env: | |
| LLVM_PROFILE_FILE: "${{ github.workspace }}/coverage-data/coverage/libcoap-rs-%p-%m.profraw" | |
| RUSTFLAGS: "${{ matrix.rust_version == 'nightly' && '-Cinstrument-coverage -Cpanic=abort -Zpanic_abort_tests' || ' ' }}" | |
| RUSTDOCFLAGS: "${{ matrix.rust_version == 'nightly' && '-C instrument-coverage -Cpanic=abort -Zpanic_abort_tests -Z unstable-options --persist-doctests target/debug/doctests' || ' ' }}" | |
| LIBCOAP_RS_BUILD_SYSTEM: "vendored" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - uses: nixbuild/nix-quick-install-action@v33 | |
| - name: Restore and save Nix store | |
| uses: nix-community/cache-nix-action@v6 | |
| with: | |
| # restore and save a cache using this key | |
| primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/devenv.lock') }} | |
| # if there's no cache hit, restore a cache by this prefix | |
| restore-prefixes-first-match: nix-${{ runner.os }}- | |
| # collect garbage until the Nix store size (in bytes) is at most this number | |
| # before trying to save a new cache | |
| # 1G = 1073741824 | |
| gc-max-store-size: 3G | |
| # do purge caches | |
| purge: true | |
| # purge all versions of the cache | |
| purge-prefixes: nix-${{ runner.os }}- | |
| # last accessed more than this number of seconds ago | |
| # relative to the start of the `Post Restore and save Nix store` phase | |
| purge-last-accessed: 86400 | |
| # except any version with the key that is the same as the `primary-key` | |
| purge-primary-key: never | |
| - run: nix profile install 'nixpkgs#devenv' | |
| - run: devenv shell --option rust-version:string ${{ matrix.rust_version }} ${{ matrix.crate }}:test_${{ matrix.dtls_backend }} | |
| - if: matrix.rust_version == 'nightly' | |
| run: | | |
| mkdir -p coverage-data/test-binaries | |
| mkdir -p target/debug/doctests | |
| devenv shell --option rust-version:string ${{ matrix.rust_version }} 'cp $(${{ matrix.crate }}:test_${{ matrix.dtls_backend }} --no-run --message-format=json --no-fail-fast \ | |
| | jq -r "select(.profile.test == true) | .filenames[]" \ | |
| | grep -v dSYM -) coverage-data/test-binaries/' | |
| cp -r target/debug/doctests coverage-data/test-binaries/ | |
| - if: matrix.rust_version == 'nightly' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| retention-days: 1 | |
| name: test-coverage-data-${{ matrix.crate }}-${{ matrix.dtls_backend }} | |
| path: | | |
| coverage-data/ | |
| - run: devenv gc | |
| lint: | |
| name: lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - uses: nixbuild/nix-quick-install-action@v33 | |
| - name: Restore and save Nix store | |
| uses: nix-community/cache-nix-action@v6 | |
| with: | |
| # restore and save a cache using this key | |
| primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/devenv.lock') }} | |
| # if there's no cache hit, restore a cache by this prefix | |
| restore-prefixes-first-match: nix-${{ runner.os }}- | |
| # collect garbage until the Nix store size (in bytes) is at most this number | |
| # before trying to save a new cache | |
| # 1G = 1073741824 | |
| gc-max-store-size: 3G | |
| # do purge caches | |
| purge: true | |
| # purge all versions of the cache | |
| purge-prefixes: nix-${{ runner.os }}- | |
| # last accessed more than this number of seconds ago | |
| # relative to the start of the `Post Restore and save Nix store` phase | |
| purge-last-accessed: 86400 | |
| # except any version with the key that is the same as the `primary-key` | |
| purge-primary-key: never | |
| - run: nix profile install 'nixpkgs#devenv' | |
| - uses: reviewdog/action-setup@v1 | |
| with: | |
| reviewdog_version: latest | |
| # Nightly required for rustfmt's --emit=checkstyle argument | |
| - uses: dtolnay/rust-toolchain@nightly | |
| with: | |
| components: clippy, rustfmt | |
| - uses: baptiste0928/cargo-install@v3 | |
| with: | |
| crate: clippy-reviewdog-filter | |
| - name: Run Linter | |
| env: | |
| REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| devenv shell --option rust-version:string nightly reviewdog -reporter=github-pr-check -fail-level=any | |
| docs: | |
| runs-on: ubuntu-latest | |
| env: | |
| CMAKE_POLICY_VERSION_MINIMUM: 3.5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| ref: ${{ env.HEAD_REF }} | |
| - uses: nixbuild/nix-quick-install-action@v33 | |
| - name: Restore and save Nix store | |
| uses: nix-community/cache-nix-action@v6 | |
| with: | |
| # restore and save a cache using this key | |
| primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/devenv.lock') }} | |
| # if there's no cache hit, restore a cache by this prefix | |
| restore-prefixes-first-match: nix-${{ runner.os }}- | |
| # collect garbage until the Nix store size (in bytes) is at most this number | |
| # before trying to save a new cache | |
| # 1G = 1073741824 | |
| gc-max-store-size: 3G | |
| # do purge caches | |
| purge: true | |
| # purge all versions of the cache | |
| purge-prefixes: nix-${{ runner.os }}- | |
| # last accessed more than this number of seconds ago | |
| # relative to the start of the `Post Restore and save Nix store` phase | |
| purge-last-accessed: 86400 | |
| # except any version with the key that is the same as the `primary-key` | |
| purge-primary-key: never | |
| - run: nix profile install 'nixpkgs#devenv' | |
| - name: Build documentation | |
| run: devenv shell cargo doc --all-features --no-deps --workspace | |
| - uses: actions/upload-artifact@v4 | |
| id: upload-docs | |
| with: | |
| name: docs | |
| path: | | |
| ./target/doc |