Merge pull request #160 from hartwork/cargo-update #547
This file contains 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
# This file is part of the rust-for-it project. | |
# | |
# Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> | |
# SPDX-License-Identifier: MIT | |
name: Build and test | |
on: | |
pull_request: | |
push: | |
schedule: | |
- cron: '0 16 * * 5' # Every Friday 4pm | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build_and_test: | |
name: Build and test | |
strategy: | |
fail-fast: false | |
matrix: | |
runs-on: [macos-latest, ubuntu-24.04, windows-latest] | |
runs-on: ${{ matrix.runs-on }} | |
env: | |
RUSTFLAGS: "-Cinstrument-coverage -D warnings" | |
steps: | |
- name: Check out | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Build | |
run: |- | |
set -x | |
rustc --version --verbose | |
cargo build | |
cargo build --tests | |
- name: Check whether Cargo.lock is in sync | |
run: |- | |
git diff --exit-code -- Cargo.lock # non-empty diff fails CI | |
- name: Test | |
run: |- | |
set -x | |
for i in {1..10}; do | |
cargo test -- --test-threads 10 --nocapture --color=always | |
done | |
- name: Smoke test CLI | |
run: |- | |
set -x | |
cargo run -- --version | |
cargo run -- --help | |
! cargo run -- --strict -t1 -s google.com:1234 -- true | |
! cargo run -- --strict -t1 -s somewhere.invalid:80 -- true | |
cargo run -- -t0 -s google.com:80 -- echo 'Google is up' | |
- name: Install coverage tools | |
if: runner.os == 'Linux' | |
run: |- | |
set -x | |
# Install grcov | |
wget https://github.com/mozilla/grcov/releases/download/v0.8.19/grcov-x86_64-unknown-linux-gnu.tar.bz2 | |
tar xf grcov-x86_64-unknown-linux-gnu.tar.bz2 | |
chmod a+x grcov | |
mkdir -p ~/.local/bin/ | |
mv grcov ~/.local/bin/ | |
echo "${USER}/.local/bin/" >> "${GITHUB_PATH}" | |
# Install lcov + llvm for llvm-profdata | |
sudo apt-get update | |
sudo apt-get install --yes --no-install-recommends -V \ | |
lcov \ | |
llvm | |
- name: Render coverage report | |
if: runner.os == 'Linux' | |
run: |- | |
set -x | |
grcov_args=( | |
--binary-path target/debug | |
--source-dir src | |
--ignore '/*' | |
--branch | |
# grcov needs help finding llvm-profdata, apparently | |
--llvm-path "$(dirname "$(which llvm-profdata)")" | |
) | |
grcov "${grcov_args[@]}" -t html -o target/coverage/html . | |
grcov "${grcov_args[@]}" -t lcov -o target/coverage/lcov . | |
lcov --list target/coverage/lcov 2>/dev/null \ | |
| tee target/coverage/summary.txt | |
- name: Store coverage report | |
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | |
if: runner.os == 'Linux' | |
with: | |
name: coverage_${{ matrix.runs-on }}_${{ github.sha }} | |
path: target/coverage/ | |
if-no-files-found: error |