Skip to content

Commit f5d3a2d

Browse files
committed
CI: add CICD job for code coverage
1 parent 73faa50 commit f5d3a2d

File tree

1 file changed

+118
-1
lines changed

1 file changed

+118
-1
lines changed

.github/workflows/CICD.yml

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CICD
22

33
# spell-checker:ignore (abbrev/names) CICD CodeCOV MacOS MinGW MSVC musl taiki
44
# spell-checker:ignore (env/flags) Awarnings Ccodegen Coverflow Cpanic Dwarnings RUSTDOCFLAGS RUSTFLAGS Zpanic CARGOFLAGS
5-
# spell-checker:ignore (jargon) SHAs deps dequote softprops subshell toolchain fuzzers dedupe devel
5+
# spell-checker:ignore (jargon) SHAs deps dequote softprops subshell toolchain fuzzers dedupe devel profdata
66
# spell-checker:ignore (people) Peltoche rivy dtolnay Anson dawidd
77
# spell-checker:ignore (shell/tools) binutils choco clippy dmake dpkg esac fakeroot fdesc fdescfs gmake grcov halium lcov libclang libfuse libssl limactl mkdir nextest nocross pacman popd printf pushd redoxer rsync rustc rustfmt rustup shopt sccache utmpdump xargs
88
# spell-checker:ignore (misc) aarch alnum armhf bindir busytest coreutils defconfig DESTDIR gecos getenforce gnueabihf issuecomment maint manpages msys multisize noconfirm nullglob onexitbegin onexitend pell runtest Swatinem tempfile testsuite toybox uutils
@@ -997,6 +997,123 @@ jobs:
997997
name: toybox-result.json
998998
path: ${{ steps.vars.outputs.TEST_SUMMARY_FILE }}
999999

1000+
coverage:
1001+
name: Code Coverage
1002+
runs-on: ${{ matrix.job.os }}
1003+
timeout-minutes: 90
1004+
env:
1005+
SCCACHE_GHA_ENABLED: "true"
1006+
RUSTC_WRAPPER: "sccache"
1007+
strategy:
1008+
fail-fast: false
1009+
matrix:
1010+
job:
1011+
- { os: ubuntu-latest , features: unix, toolchain: nightly }
1012+
# FIXME: Re-enable macos code coverage
1013+
# - { os: macos-latest , features: macos, toolchain: nightly }
1014+
# FIXME: Re-enable Code Coverage on windows, which currently fails due to "profiler_builtins". See #6686.
1015+
# - { os: windows-latest , features: windows, toolchain: nightly-x86_64-pc-windows-gnu }
1016+
steps:
1017+
- uses: actions/checkout@v4
1018+
- uses: dtolnay/rust-toolchain@master
1019+
with:
1020+
toolchain: ${{ matrix.job.toolchain }}
1021+
components: rustfmt
1022+
- uses: taiki-e/install-action@v2
1023+
with:
1024+
tool: nextest,[email protected]
1025+
- uses: Swatinem/rust-cache@v2
1026+
1027+
- name: Run sccache-cache
1028+
uses: mozilla-actions/[email protected]
1029+
1030+
# - name: Reattach HEAD ## may be needed for accurate code coverage info
1031+
# run: git checkout ${{ github.head_ref }}
1032+
1033+
- name: Initialize workflow variables
1034+
id: vars
1035+
shell: bash
1036+
run: |
1037+
## VARs setup
1038+
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
1039+
1040+
# toolchain
1041+
TOOLCHAIN="nightly" ## default to "nightly" toolchain (required for certain required unstable compiler flags) ## !maint: refactor when stable channel has needed support
1042+
1043+
# * specify gnu-type TOOLCHAIN for windows; `grcov` requires gnu-style code coverage data files
1044+
case ${{ matrix.job.os }} in windows-*) TOOLCHAIN="$TOOLCHAIN-x86_64-pc-windows-gnu" ;; esac;
1045+
1046+
# * use requested TOOLCHAIN if specified
1047+
if [ -n "${{ matrix.job.toolchain }}" ]; then TOOLCHAIN="${{ matrix.job.toolchain }}" ; fi
1048+
outputs TOOLCHAIN
1049+
1050+
# target-specific options
1051+
1052+
# * CARGO_FEATURES_OPTION
1053+
CARGO_FEATURES_OPTION='--all-features' ; ## default to '--all-features' for code coverage
1054+
if [ -n "${{ matrix.job.features }}" ]; then CARGO_FEATURES_OPTION='--features=${{ matrix.job.features }}' ; fi
1055+
outputs CARGO_FEATURES_OPTION
1056+
1057+
# * CODECOV_FLAGS
1058+
CODECOV_FLAGS=$( echo "${{ matrix.job.os }}" | sed 's/[^[:alnum:]]/_/g' )
1059+
outputs CODECOV_FLAGS
1060+
1061+
- name: Install/setup prerequisites
1062+
shell: bash
1063+
run: |
1064+
## Install/setup prerequisites
1065+
case '${{ matrix.job.os }}' in
1066+
macos-latest) brew install coreutils ;; # needed for testing
1067+
esac
1068+
1069+
case '${{ matrix.job.os }}' in
1070+
ubuntu-latest)
1071+
# pinky is a tool to show logged-in users from utmp, and gecos fields from /etc/passwd.
1072+
# In GitHub Action *nix VMs, no accounts log in, even the "runner" account that runs the commands. The account also has empty gecos fields.
1073+
# To work around this for pinky tests, we create a fake login entry for the GH runner account...
1074+
FAKE_UTMP='[7] [999999] [tty2] [runner] [tty2] [] [0.0.0.0] [2022-02-22T22:22:22,222222+00:00]'
1075+
# ... by dumping the login records, adding our fake line, then reverse dumping ...
1076+
(utmpdump /var/run/utmp ; echo $FAKE_UTMP) | sudo utmpdump -r -o /var/run/utmp
1077+
# ... and add a full name to each account with a gecos field but no full name.
1078+
sudo sed -i 's/:,/:runner name,/' /etc/passwd
1079+
# We also create a couple optional files pinky looks for
1080+
touch /home/runner/.project
1081+
echo "foo" > /home/runner/.plan
1082+
;;
1083+
esac
1084+
1085+
case '${{ matrix.job.os }}' in
1086+
# Update binutils if MinGW due to https://github.com/rust-lang/rust/issues/112368
1087+
windows-latest) C:/msys64/usr/bin/pacman.exe -Sy --needed mingw-w64-x86_64-gcc --noconfirm ; echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH ;;
1088+
esac
1089+
1090+
## Install the llvm-tools component to get access to `llvm-profdata`
1091+
rustup component add llvm-tools
1092+
1093+
- name: Run test and coverage
1094+
id: run_test_cov
1095+
run: |
1096+
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
1097+
1098+
# Run the coverage script
1099+
./util/build-run-test-coverage-linux.sh
1100+
1101+
outputs REPORT_FILE
1102+
env:
1103+
COVERAGE_DIR: ${{ github.workspace }}/coverage
1104+
FEATURES_OPTION: ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }}
1105+
# RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }}
1106+
1107+
- name: Upload coverage results (to Codecov.io)
1108+
uses: codecov/codecov-action@v4
1109+
with:
1110+
token: ${{ secrets.CODECOV_TOKEN }}
1111+
file: ${{ steps.run_test_cov.outputs.report }}
1112+
## flags: IntegrationTests, UnitTests, ${{ steps.vars.outputs.CODECOV_FLAGS }}
1113+
flags: ${{ steps.vars.outputs.CODECOV_FLAGS }}
1114+
name: codecov-umbrella
1115+
fail_ci_if_error: false
1116+
10001117
test_separately:
10011118
name: Separate Builds
10021119
runs-on: ${{ matrix.os }}

0 commit comments

Comments
 (0)