Skip to content

Commit dc469f7

Browse files
sylvestreRenjiSann
authored andcommitted
Revert "ci: remove code coverage jobs"
This reverts commit ca92bff.
1 parent 38bbfce commit dc469f7

2 files changed

Lines changed: 200 additions & 0 deletions

File tree

.github/workflows/CICD.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,132 @@ jobs:
989989
name: toybox-result.json
990990
path: ${{ steps.vars.outputs.TEST_SUMMARY_FILE }}
991991

992+
coverage:
993+
name: Code Coverage
994+
runs-on: ${{ matrix.job.os }}
995+
timeout-minutes: 90
996+
env:
997+
SCCACHE_GHA_ENABLED: "true"
998+
RUSTC_WRAPPER: "sccache"
999+
strategy:
1000+
fail-fast: false
1001+
matrix:
1002+
job:
1003+
- { os: ubuntu-latest , features: unix, toolchain: nightly }
1004+
- { os: macos-latest , features: macos, toolchain: nightly }
1005+
# FIXME: Re-enable Code Coverage on windows, which currently fails due to "profiler_builtins". See #6686.
1006+
# - { os: windows-latest , features: windows, toolchain: nightly-x86_64-pc-windows-gnu }
1007+
steps:
1008+
- uses: actions/checkout@v4
1009+
- uses: dtolnay/rust-toolchain@master
1010+
with:
1011+
toolchain: ${{ matrix.job.toolchain }}
1012+
components: rustfmt
1013+
- uses: taiki-e/install-action@nextest
1014+
- uses: taiki-e/install-action@grcov
1015+
- uses: Swatinem/rust-cache@v2
1016+
- name: Run sccache-cache
1017+
uses: mozilla-actions/sccache-action@v0.0.6
1018+
# - name: Reattach HEAD ## may be needed for accurate code coverage info
1019+
# run: git checkout ${{ github.head_ref }}
1020+
- name: Initialize workflow variables
1021+
id: vars
1022+
shell: bash
1023+
run: |
1024+
## VARs setup
1025+
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
1026+
# toolchain
1027+
TOOLCHAIN="nightly" ## default to "nightly" toolchain (required for certain required unstable compiler flags) ## !maint: refactor when stable channel has needed support
1028+
# * specify gnu-type TOOLCHAIN for windows; `grcov` requires gnu-style code coverage data files
1029+
case ${{ matrix.job.os }} in windows-*) TOOLCHAIN="$TOOLCHAIN-x86_64-pc-windows-gnu" ;; esac;
1030+
# * use requested TOOLCHAIN if specified
1031+
if [ -n "${{ matrix.job.toolchain }}" ]; then TOOLCHAIN="${{ matrix.job.toolchain }}" ; fi
1032+
outputs TOOLCHAIN
1033+
# target-specific options
1034+
# * CARGO_FEATURES_OPTION
1035+
CARGO_FEATURES_OPTION='--all-features' ; ## default to '--all-features' for code coverage
1036+
if [ -n "${{ matrix.job.features }}" ]; then CARGO_FEATURES_OPTION='--features=${{ matrix.job.features }}' ; fi
1037+
outputs CARGO_FEATURES_OPTION
1038+
# * CODECOV_FLAGS
1039+
CODECOV_FLAGS=$( echo "${{ matrix.job.os }}" | sed 's/[^[:alnum:]]/_/g' )
1040+
outputs CODECOV_FLAGS
1041+
- name: Install/setup prerequisites
1042+
shell: bash
1043+
run: |
1044+
## Install/setup prerequisites
1045+
case '${{ matrix.job.os }}' in
1046+
macos-latest) brew install coreutils ;; # needed for testing
1047+
esac
1048+
case '${{ matrix.job.os }}' in
1049+
ubuntu-latest)
1050+
# pinky is a tool to show logged-in users from utmp, and gecos fields from /etc/passwd.
1051+
# In GitHub Action *nix VMs, no accounts log in, even the "runner" account that runs the commands. The account also has empty gecos fields.
1052+
# To work around this for pinky tests, we create a fake login entry for the GH runner account...
1053+
FAKE_UTMP='[7] [999999] [tty2] [runner] [tty2] [] [0.0.0.0] [2022-02-22T22:22:22,222222+00:00]'
1054+
# ... by dumping the login records, adding our fake line, then reverse dumping ...
1055+
(utmpdump /var/run/utmp ; echo $FAKE_UTMP) | sudo utmpdump -r -o /var/run/utmp
1056+
# ... and add a full name to each account with a gecos field but no full name.
1057+
sudo sed -i 's/:,/:runner name,/' /etc/passwd
1058+
# We also create a couple optional files pinky looks for
1059+
touch /home/runner/.project
1060+
echo "foo" > /home/runner/.plan
1061+
;;
1062+
esac
1063+
case '${{ matrix.job.os }}' in
1064+
# Update binutils if MinGW due to https://github.com/rust-lang/rust/issues/112368
1065+
windows-latest) C:/msys64/usr/bin/pacman.exe -Sy --needed mingw-w64-x86_64-gcc --noconfirm ; echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH ;;
1066+
esac
1067+
- name: Initialize toolchain-dependent workflow variables
1068+
id: dep_vars
1069+
shell: bash
1070+
run: |
1071+
## Dependent VARs setup
1072+
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
1073+
# * determine sub-crate utility list
1074+
UTILITY_LIST="$(./util/show-utils.sh ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }})"
1075+
CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo -n "-puu_${u} "; done;)"
1076+
outputs CARGO_UTILITY_LIST_OPTIONS
1077+
- name: Test
1078+
run: cargo nextest run --profile ci --hide-progress-bar ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} -p uucore -p coreutils
1079+
env:
1080+
RUSTC_WRAPPER: ""
1081+
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
1082+
RUSTDOCFLAGS: "-Cpanic=abort"
1083+
RUST_BACKTRACE: "1"
1084+
# RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }}
1085+
- name: Test individual utilities
1086+
run: cargo nextest run --profile ci --hide-progress-bar ${{ steps.dep_vars.outputs.CARGO_UTILITY_LIST_OPTIONS }}
1087+
env:
1088+
RUSTC_WRAPPER: ""
1089+
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
1090+
RUSTDOCFLAGS: "-Cpanic=abort"
1091+
RUST_BACKTRACE: "1"
1092+
# RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }}
1093+
- name: Generate coverage data (via `grcov`)
1094+
id: coverage
1095+
shell: bash
1096+
run: |
1097+
## Generate coverage data
1098+
COVERAGE_REPORT_DIR="target/debug"
1099+
COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info"
1100+
# GRCOV_IGNORE_OPTION='--ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*"' ## `grcov` ignores these params when passed as an environment variable (why?)
1101+
# GRCOV_EXCLUDE_OPTION='--excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()"' ## `grcov` ignores these params when passed as an environment variable (why?)
1102+
mkdir -p "${COVERAGE_REPORT_DIR}"
1103+
# display coverage files
1104+
grcov . --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique
1105+
# generate coverage report
1106+
grcov . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()"
1107+
echo "report=${COVERAGE_REPORT_FILE}" >> $GITHUB_OUTPUT
1108+
- name: Upload coverage results (to Codecov.io)
1109+
uses: codecov/codecov-action@v4
1110+
with:
1111+
token: ${{ secrets.CODECOV_TOKEN }}
1112+
file: ${{ steps.coverage.outputs.report }}
1113+
## flags: IntegrationTests, UnitTests, ${{ steps.vars.outputs.CODECOV_FLAGS }}
1114+
flags: ${{ steps.vars.outputs.CODECOV_FLAGS }}
1115+
name: codecov-umbrella
1116+
fail_ci_if_error: false
1117+
9921118
test_separately:
9931119
name: Separate Builds
9941120
runs-on: ${{ matrix.os }}

.github/workflows/GnuTests.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,77 @@ jobs:
363363
else
364364
echo "::warning ::Skipping test summary comparison; no prior reference summary is available."
365365
fi
366+
367+
gnu_coverage:
368+
name: Run GNU tests with coverage
369+
runs-on: ubuntu-24.04
370+
steps:
371+
- name: Checkout code uutil
372+
uses: actions/checkout@v4
373+
with:
374+
path: 'uutils'
375+
- name: Checkout GNU coreutils
376+
uses: actions/checkout@v4
377+
with:
378+
repository: 'coreutils/coreutils'
379+
path: 'gnu'
380+
ref: 'v9.5'
381+
submodules: recursive
382+
- uses: dtolnay/rust-toolchain@master
383+
with:
384+
toolchain: nightly
385+
components: rustfmt
386+
- uses: taiki-e/install-action@grcov
387+
- uses: Swatinem/rust-cache@v2
388+
with:
389+
workspaces: "./uutils -> target"
390+
- name: Install dependencies
391+
run: |
392+
## Install dependencies
393+
sudo apt-get update
394+
sudo apt-get install -y autoconf autopoint bison texinfo gperf gcc g++ gdb python3-pyinotify jq valgrind libexpect-perl libacl1-dev libattr1-dev libcap-dev libselinux1-dev attr
395+
- name: Add various locales
396+
run: |
397+
## Add various locales
398+
echo "Before:"
399+
locale -a
400+
## Some tests fail with 'cannot change locale (en_US.ISO-8859-1): No such file or directory'
401+
## Some others need a French locale
402+
sudo locale-gen
403+
sudo locale-gen --keep-existing fr_FR
404+
sudo locale-gen --keep-existing fr_FR.UTF-8
405+
sudo update-locale
406+
echo "After:"
407+
locale -a
408+
- name: Build binaries
409+
env:
410+
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
411+
RUSTDOCFLAGS: "-Cpanic=abort"
412+
run: |
413+
## Build binaries
414+
cd uutils
415+
bash util/build-gnu.sh
416+
- name: Run GNU tests
417+
run: bash uutils/util/run-gnu-test.sh
418+
- name: Generate coverage data (via `grcov`)
419+
id: coverage
420+
run: |
421+
## Generate coverage data
422+
cd uutils
423+
COVERAGE_REPORT_DIR="target/debug"
424+
COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info"
425+
mkdir -p "${COVERAGE_REPORT_DIR}"
426+
sudo chown -R "$(whoami)" "${COVERAGE_REPORT_DIR}"
427+
# display coverage files
428+
grcov . --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique
429+
# generate coverage report
430+
grcov . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()"
431+
echo "report=${COVERAGE_REPORT_FILE}" >> $GITHUB_OUTPUT
432+
- name: Upload coverage results (to Codecov.io)
433+
uses: codecov/codecov-action@v4
434+
with:
435+
token: ${{ secrets.CODECOV_TOKEN }}
436+
file: ${{ steps.coverage.outputs.report }}
437+
flags: gnutests
438+
name: gnutests
439+
working-directory: uutils

0 commit comments

Comments
 (0)