Skip to content

Various CI pipeline improvements #228

Various CI pipeline improvements

Various CI pipeline improvements #228

Workflow file for this run

name: CI Status
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-rs]
#dtls_backend: [ gnutls ]
#rust_version: [nightly]
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' || ' ' }}"
LIBRARY_FEATURES: |
${{ (matrix.crate == 'libcoap-rs' && 'tcp,vendored,rand')
|| (matrix.crate == 'libcoap-sys' && 'default')
|| 'vendored'
}}
DTLS_LIBRARY_FEATURES: |
${{ (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'tinydtls' && 'tcp,dtls-psk,dtls-rpk,dtls_tinydtls_vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'mbedtls' && 'tcp,dtls-psk,dtls-pki,dtls_mbedtls_vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'openssl' && 'tcp,dtls-psk,dtls-pki,dtls_openssl_vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'gnutls' && 'tcp,dtls-psk,dtls-pki,dtls-rpk,dtls_gnutls')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'tinydtls' && 'dtls,dtls_backend_tinydtls,dtls_backend_tinydtls_vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'mbedtls' && 'dtls,dtls_backend_mbedtls,dtls_backend_mbedtls_vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'openssl' && 'dtls,dtls_backend_openssl,dtls_backend_openssl_vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'gnutls' && 'dtls,dtls_backend_gnutls')
|| 'vendored'
}}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: dtolnay/rust-toolchain@stable
with:
components: rust-src, rustc, rust-std, cargo, llvm-tools, llvm-tools-preview
toolchain: ${{ matrix.rust_version == 'msrv' && '1.81' || matrix.rust_version }}
- if: matrix.dtls_backend == 'gnutls'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libgnutls28-dev libgnutls30
version: 1.0
- run: cargo test -p ${{ matrix.crate }} --no-default-features --features "$LIBRARY_FEATURES" --features "$DTLS_LIBRARY_FEATURES" --no-fail-fast
- if: matrix.rust_version == 'nightly'
run: |
mkdir -p coverage-data/test-binaries
mkdir -p target/debug/doctests
cp $(cargo test -p ${{ matrix.crate }} --no-run --message-format=json --no-default-features --features "$LIBRARY_FEATURES" --features "$DTLS_LIBRARY_FEATURES" --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/
lint:
name: lint
runs-on: ubuntu-latest
strategy:
matrix:
crate: [ libcoap-sys, libcoap-rs ]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: giraffate/clippy-action@main
with:
reporter: 'github-check'
clippy_flags: -p ${{ matrix.crate }} --no-deps --all-features
level: warning
fail_on_error: true
tool_name: clippy (${{ matrix.crate }})
fmt:
name: rustfmt
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
crate: [ libcoap-sys, libcoap-rs ]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt -p ${{ matrix.crate }}
- name: Generate PR suggestions from rustfmt changes
uses: reviewdog/action-suggester@v1
with:
tool_name: rustfmt
# https://github.com/reviewdog/action-suggester/issues/53 also prevents PR comments from being generated on failure (i think), so we'll have to disable it.
# As merging requires resolving all open threads, this should be fine.
fail_on_error: false
coverage:
name: coverage
runs-on: ubuntu-latest
needs: [ test ]
if: always()
env:
LLVM_PROFILE_FILE: './coverage-data/coverage/libcoap-rs-%p-%m.profraw'
outputs:
report: ${{ steps.cov-report.outputs.summary }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/download-artifact@v4
with:
pattern: test-coverage-data-*
merge-multiple: true
path: coverage-data
- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools, llvm-tools-preview
- uses: baptiste0928/cargo-install@v3
with:
crate: grcov
- run: mkdir -p ./coverage
- run: grcov coverage-data/coverage/ -s . --binary-path ./coverage-data/test-binaries --commit-sha ${GITHUB_SHA} --ignore-not-existing --ignore "/*" -t markdown,html --branch --log-level TRACE -o ./coverage/
- id: cov-report
name: "Set coverage report as job output"
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
{
echo "summary<<$EOF"
cat ./coverage/markdown.md
echo "$EOF"
} >> "$GITHUB_OUTPUT"
- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./coverage/html
publish_branch: _gh_pages
destination_dir: coverage/${{ github.ref_name }}
pr-comment:
name: pr-comment
runs-on: ubuntu-latest
if: ${{ always() && github.event_name == 'pull_request' }}
needs: [ lint, coverage, fmt ]
env:
LINT_OUTPUT: ${{ needs.lint.result }}
FMT_OUTPUT: ${{ needs.fmt.result }}
COV_OUTPUT: ${{ needs.coverage.outputs.report }}
steps:
- name: "Generate Markdown Report"
run: |
# Snippet taken from https://github.com/marocchino/sticky-pull-request-comment#append-after-comment-every-time-it-runs
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
{
echo "report<<$EOF"
echo "# Workflow Status Report"
echo "Generated for commit ${{ github.sha }} on `date -u`."
echo ""
echo "[![CI Status](https://github.com/namib-project/libcoap-rs/actions/workflows/ci.yml/badge.svg?branch=${GITHUB_HEAD_REF}&hash=${{ github.sha }})](https://github.com/namib-project/libcoap-rs/actions/workflows/ci.yml?query=branch%3A${GITHUB_HEAD_REF})"
echo ""
echo "## Linting Report"
echo ""
echo "Clippy check result: $LINT_OUTPUT"
echo ""
echo "<!-- Disabled due to https://github.com/reviewdog/action-suggester/issues/53 (which prevents us from using fail_on_error as this prevents PR comments from being generated) Rustfmt check result: $FMT_OUTPUT -->"
echo ""
echo "In case of failure, required changes are automatically added as review comments."
echo ""
echo "## Code Coverage Report"
echo "[![Coverage](https://namib-project.github.io/libcoap-rs/coverage/${{ github.ref_name }}/badges/flat.svg?hash=${{ github.sha }})](https://namib-project.github.io/libcoap-rs/coverage/${{ github.ref_name }})"
echo ""
echo "<emph>Coverage target is 80%.</emph>"
echo ""
echo "Click on the coverage badge to access the full coverage report including a source code view."
echo ""
echo "<details>"
echo "<summary>Expand to view coverage statistics</summary>"
echo ""
echo "$COV_OUTPUT"
echo "</details>"
echo "$EOF"
} >> "$GITHUB_ENV"
- if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
message: ${{ env.report }}