[ci] [R-package] add CI jobs covering more CRAN "additional checks", fix R_NO_REMAP warnings (fixes #6369) (#6523)

* [ci] [R-package] add CI jobs testing newer compilers

* set up vignette-processing dependencies

* remove tinytex

* set up pandoc

* allow NOTEs, one more R_NO_REMAP guard

* restore other CI

* one more R_NO_REMAP guard

* fail builds producing more than 1 NOTE

* update approach for running R CMD check

* fix filepath

* fix paths

* fix variable name

* echo lines

* fix piping

* fix file extension

* clean up

* make R CMD check stricter
This commit is contained in:
James Lamb 2024-07-14 05:41:38 -07:00 коммит произвёл GitHub
Родитель 2bc3ab86b7
Коммит 5cec6903e7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 133 добавлений и 129 удалений

Просмотреть файл

@ -1,74 +0,0 @@
#!/bin/bash
# [description]
#
# Installs a development version of clang and the other LLVM tools.
#
set -e -E -u -o pipefail
CLANG_VERSION=${1}
apt-get autoremove -y --purge \
clang-* \
libclang-* \
libunwind-* \
llvm-*
apt-get update -y
apt-get install --no-install-recommends -y \
gnupg \
lsb-release \
software-properties-common \
wget
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
# ref: https://apt.llvm.org/
add-apt-repository -y "deb http://apt.llvm.org/unstable/ llvm-toolchain main"
add-apt-repository -y "deb-src http://apt.llvm.org/unstable/ llvm-toolchain main"
add-apt-repository -y "deb http://apt.llvm.org/unstable/ llvm-toolchain-${CLANG_VERSION} main" || true
add-apt-repository -y "deb-src http://apt.llvm.org/unstable/ llvm-toolchain-${CLANG_VERSION} main" || true
apt-get update -y
apt-get install -y --no-install-recommends \
clang-${CLANG_VERSION} \
clangd-${CLANG_VERSION} \
clang-format-${CLANG_VERSION} \
clang-tidy-${CLANG_VERSION} \
clang-tools-${CLANG_VERSION} \
lldb-${CLANG_VERSION} \
lld-${CLANG_VERSION} \
llvm-${CLANG_VERSION}-dev \
llvm-${CLANG_VERSION}-tools \
libomp-${CLANG_VERSION}-dev \
libc++-${CLANG_VERSION}-dev \
libc++abi-${CLANG_VERSION}-dev \
libclang-common-${CLANG_VERSION}-dev \
libclang-${CLANG_VERSION}-dev \
libclang-cpp${CLANG_VERSION}-dev \
libunwind-${CLANG_VERSION}-dev
# overwriting the stuff in /usr/bin is simpler and more reliable than
# updating PATH, LD_LIBRARY_PATH, etc.
cp --remove-destination /usr/lib/llvm-${CLANG_VERSION}/bin/* /usr/bin/
# per https://www.stats.ox.ac.uk/pub/bdr/Rconfig/r-devel-linux-x86_64-fedora-clang
#
# clang was built to use libc++: for a version built to default to libstdc++
# (as shipped by Fedora/Debian/Ubuntu), add -stdlib=libc++ to CXX
# and install the libcxx-devel/libc++-dev package.
mkdir -p "${HOME}/.R"
cat << EOF > "${HOME}/.R/Makevars"
CXX += -stdlib=libc++
CXX11 += -stdlib=libc++
CXX14 += -stdlib=libc++
CXX17 += -stdlib=libc++
CXX20 += -stdlib=libc++
EOF
echo ""
echo "done installing clang"
clang --version
echo ""

46
.ci/run-r-cmd-check.sh Executable file
Просмотреть файл

@ -0,0 +1,46 @@
#!/bin/bash
set -e -u -o pipefail
PKG_TARBALL="${1}"
declare -i ALLOWED_CHECK_NOTES=${2}
# 'R CMD check' redirects installation logs to a file, and returns
# a non-0 exit code if ERRORs are raised.
#
# The '||' here gives us an opportunity to echo out the installation
# logs prior to exiting the script.
check_succeeded="yes"
R CMD check "${PKG_TARBALL}" \
--as-cran \
--run-donttest \
|| check_succeeded="no"
CHECK_LOG_FILE=lightgbm.Rcheck/00check.log
BUILD_LOG_FILE=lightgbm.Rcheck/00install.out
echo "R CMD check build logs:"
cat "${BUILD_LOG_FILE}"
if [[ $check_succeeded == "no" ]]; then
echo "R CMD check failed"
exit 1
fi
# WARNINGs or ERRORs should be treated as a failure
if grep -q -E "WARNING|ERROR" "${CHECK_LOG_FILE}"; then
echo "WARNINGs or ERRORs have been found by R CMD check"
exit 1
fi
# Allow a configurable number of NOTEs.
# Sometimes NOTEs are raised in CI that wouldn't show up on an actual CRAN submission.
set +e
NUM_CHECK_NOTES=$(
grep -o -E '[0-9]+ NOTE' "${CHECK_LOG_FILE}" \
| sed 's/[^0-9]*//g'
)
if [[ ${NUM_CHECK_NOTES} -gt ${ALLOWED_CHECK_NOTES} ]]; then
echo "Found ${NUM_CHECK_NOTES} NOTEs from R CMD check. Only ${ALLOWED_CHECK_NOTES} are allowed"
exit 1
fi

Просмотреть файл

@ -149,8 +149,8 @@ fi
Rscript --vanilla -e "options(install.packages.compile.from.source = '${compile_from_source}'); install.packages(${packages}, repos = '${CRAN_MIRROR}', lib = '${R_LIB_PATH}', dependencies = c('Depends', 'Imports', 'LinkingTo'), Ncpus = parallel::detectCores())" || exit 1 Rscript --vanilla -e "options(install.packages.compile.from.source = '${compile_from_source}'); install.packages(${packages}, repos = '${CRAN_MIRROR}', lib = '${R_LIB_PATH}', dependencies = c('Depends', 'Imports', 'LinkingTo'), Ncpus = parallel::detectCores())" || exit 1
cd "${BUILD_DIRECTORY}" cd "${BUILD_DIRECTORY}"
PKG_TARBALL="lightgbm_$(head -1 VERSION.txt).tar.gz"
PKG_TARBALL="lightgbm_*.tar.gz" BUILD_LOG_FILE="lightgbm.Rcheck/00install.out"
LOG_FILE_NAME="lightgbm.Rcheck/00check.log" LOG_FILE_NAME="lightgbm.Rcheck/00check.log"
if [[ $R_BUILD_TYPE == "cmake" ]]; then if [[ $R_BUILD_TYPE == "cmake" ]]; then
Rscript build_r.R -j4 --skip-install || exit 1 Rscript build_r.R -j4 --skip-install || exit 1
@ -209,21 +209,10 @@ elif [[ $R_BUILD_TYPE == "cran" ]]; then
cd ${R_CMD_CHECK_DIR} cd ${R_CMD_CHECK_DIR}
fi fi
# fails tests if either ERRORs or WARNINGs are thrown by declare -i allowed_notes=0
# R CMD CHECK bash "${BUILD_DIRECTORY}/.ci/run-r-cmd-check.sh" \
check_succeeded="yes" "${PKG_TARBALL}" \
R CMD check ${PKG_TARBALL} \ "${allowed_notes}"
--as-cran \
--run-donttest \
|| check_succeeded="no"
echo "R CMD check build logs:"
BUILD_LOG_FILE=lightgbm.Rcheck/00install.out
cat ${BUILD_LOG_FILE}
if [[ $check_succeeded == "no" ]]; then
exit 1
fi
# ensure 'grep --count' doesn't cause failures # ensure 'grep --count' doesn't cause failures
set +e set +e
@ -242,18 +231,12 @@ if [[ $R_BUILD_TYPE == "cmake" ]]; then
cat $BUILD_LOG_FILE \ cat $BUILD_LOG_FILE \
| grep --count "R version passed into FindLibR.cmake: ${R_VERSION}" | grep --count "R version passed into FindLibR.cmake: ${R_VERSION}"
) )
if [[ $used_correct_r_version -ne 1 ]]; then if [[ $passed_correct_r_version_to_cmake -ne 1 ]]; then
echo "Unexpected R version was passed into cmake. Expected '${R_VERSION}'." echo "Unexpected R version was passed into cmake. Expected '${R_VERSION}'."
exit 1 exit 1
fi fi
fi fi
if grep -q -E "NOTE|WARNING|ERROR" "$LOG_FILE_NAME"; then
echo "NOTEs, WARNINGs, or ERRORs have been found by R CMD check"
exit 1
fi
# this check makes sure that CI builds of the package actually use OpenMP # this check makes sure that CI builds of the package actually use OpenMP
if [[ $OS_NAME == "macos" ]] && [[ $R_BUILD_TYPE == "cran" ]]; then if [[ $OS_NAME == "macos" ]] && [[ $R_BUILD_TYPE == "cran" ]]; then
omp_working=$( omp_working=$(

92
.github/workflows/r_package.yml поставляемый
Просмотреть файл

@ -18,7 +18,12 @@ env:
# #
# this could be removed (hopefully) when R 3.6 support is removed # this could be removed (hopefully) when R 3.6 support is removed
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
# in CMake-driven builds, parallelize compilation
CMAKE_BUILD_PARALLEL_LEVEL: 4 CMAKE_BUILD_PARALLEL_LEVEL: 4
# on Debian-based images, avoid interactive prompts
DEBIAN_FRONTEND: noninteractive
# parallelize compilation (extra important for Linux, where CRAN doesn't supply pre-compiled binaries)
MAKEFLAGS: "-j4"
# hack to get around this: # hack to get around this:
# https://stat.ethz.ch/pipermail/r-package-devel/2020q3/005930.html # https://stat.ethz.ch/pipermail/r-package-devel/2020q3/005930.html
_R_CHECK_SYSTEM_CLOCK_: 0 _R_CHECK_SYSTEM_CLOCK_: 0
@ -258,58 +263,83 @@ jobs:
RDscript${{ matrix.r_customization }} testthat.R >> tests.log 2>&1 || exit_code=-1 RDscript${{ matrix.r_customization }} testthat.R >> tests.log 2>&1 || exit_code=-1
cat ./tests.log cat ./tests.log
exit ${exit_code} exit ${exit_code}
test-r-debian-clang: test-r-extra-checks:
name: r-package (debian, R-devel, clang-${{ matrix.clang-version }}) name: r-package (${{ matrix.image }}, R-devel)
timeout-minutes: 60 timeout-minutes: 60
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
# list of versions tested in CRAN "Additional Checks": # references:
# https://cran.r-project.org/web/checks/check_issue_kinds.html # * CRAN "additional checks": https://cran.r-project.org/web/checks/check_issue_kinds.html
clang-version: # * images: https://r-hub.github.io/containers/containers.html
- 16 image:
- 17 - clang16
- clang17
- clang18
- clang19
- gcc14
- intel
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: rhub/debian-clang-devel container: ghcr.io/r-hub/containers/${{ matrix.image }}:latest
env:
DEBIAN_FRONTEND: noninteractive
steps: steps:
- name: Install Git before checkout
shell: bash
run: |
apt-get update --allow-releaseinfo-change
apt-get install --no-install-recommends -y git
- name: Trust git cloning LightGBM
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 5 fetch-depth: 5
submodules: true submodules: true
- name: install clang - name: Install pandoc
uses: r-lib/actions/setup-pandoc@v2
- name: Install LaTeX
shell: bash
run: | run: |
./.ci/install-clang-devel.sh ${{ matrix.clang-version }} if type -f apt 2>&1 > /dev/null; then
apt-get update
apt-get install --no-install-recommends -y \
devscripts \
texinfo \
texlive-latex-extra \
texlive-latex-recommended \
texlive-fonts-recommended \
texlive-fonts-extra \
tidy \
qpdf
else
yum update -y
yum install -y \
devscripts \
qpdf \
texinfo \
texinfo-tex \
texlive-latex \
tidy
fi
- name: Install packages and run tests - name: Install packages and run tests
shell: bash shell: bash
run: | run: |
export PATH=/opt/R-devel/bin/:${PATH}
Rscript -e "install.packages(c('R6', 'data.table', 'jsonlite', 'knitr', 'markdown', 'Matrix', 'RhpcBLASctl', 'testthat'), repos = 'https://cran.rstudio.com', Ncpus = parallel::detectCores())" Rscript -e "install.packages(c('R6', 'data.table', 'jsonlite', 'knitr', 'markdown', 'Matrix', 'RhpcBLASctl', 'testthat'), repos = 'https://cran.rstudio.com', Ncpus = parallel::detectCores())"
sh build-cran-package.sh sh build-cran-package.sh
R CMD check --as-cran --run-donttest lightgbm_*.tar.gz || exit 1 if [[ "${{ matrix.image }}" =~ "clang" ]]; then
echo "" # allowing the following NOTEs (produced by default in the clang images):
echo "install logs:" #
echo "" # * checking compilation flags used ... NOTE
cat lightgbm.Rcheck/00install.out # Compilation used the following non-portable flag(s):
echo "" # -Wp,-D_FORTIFY_SOURCE=3
if grep -q -E "NOTE|WARNING|ERROR" lightgbm.Rcheck/00check.log; then #
echo "NOTEs, WARNINGs, or ERRORs have been found by R CMD check" # even though CRAN itself sets that:
exit 1 # https://www.stats.ox.ac.uk/pub/bdr/Rconfig/r-devel-linux-x86_64-fedora-clang
#
declare -i allowed_notes=1
else
declare -i allowed_notes=0
fi fi
bash .ci/run-r-cmd-check.sh \
"$(echo lightgbm_$(head -1 VERSION.txt).tar.gz)" \
"${allowed_notes}"
all-r-package-jobs-successful: all-r-package-jobs-successful:
if: always() if: always()
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [test, test-r-sanitizers, test-r-debian-clang] needs: [test, test-r-sanitizers, test-r-extra-checks]
steps: steps:
- name: Note that all tests succeeded - name: Note that all tests succeeded
uses: re-actors/alls-green@v1.2.2 uses: re-actors/alls-green@v1.2.2

Просмотреть файл

@ -13,8 +13,14 @@
#include <R_ext/Rdynload.h> #include <R_ext/Rdynload.h>
#include <R_ext/Altrep.h> #include <R_ext/Altrep.h>
#ifndef R_NO_REMAP
#define R_NO_REMAP #define R_NO_REMAP
#endif
#ifndef R_USE_C99_IN_CXX
#define R_USE_C99_IN_CXX #define R_USE_C99_IN_CXX
#endif
#include <R_ext/Error.h> #include <R_ext/Error.h>
#include <string> #include <string>

Просмотреть файл

@ -7,8 +7,14 @@
#include <LightGBM/c_api.h> #include <LightGBM/c_api.h>
#ifndef R_NO_REMAP
#define R_NO_REMAP #define R_NO_REMAP
#endif
#ifndef R_USE_C99_IN_CXX
#define R_USE_C99_IN_CXX #define R_USE_C99_IN_CXX
#endif
#include <Rinternals.h> #include <Rinternals.h>
/*! /*!

Просмотреть файл

@ -16,8 +16,15 @@
#include <string> #include <string>
#ifdef LGB_R_BUILD #ifdef LGB_R_BUILD
#ifndef R_NO_REMAP
#define R_NO_REMAP #define R_NO_REMAP
#endif
#ifndef R_USE_C99_IN_CXX
#define R_USE_C99_IN_CXX #define R_USE_C99_IN_CXX
#endif
#include <R_ext/Print.h> #include <R_ext/Print.h>
extern "C" void R_FlushConsole(void); extern "C" void R_FlushConsole(void);
#endif #endif