Skip to content

Commit

Permalink
Test R package with Alpine Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Nov 27, 2024
1 parent 0783f38 commit 23a21ef
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 46 deletions.
110 changes: 67 additions & 43 deletions .github/workflows/r_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,140 @@ name: XGBoost-R-Tests

on: [push, pull_request]

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

permissions:
contents: read # to fetch code (actions/checkout)

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
BRANCH_NAME: >-
${{ github.event.pull_request.number && 'PR-' }}${{ github.event.pull_request.number || github.ref_name }}
USE_DOCKER_CACHE: 1
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

jobs:
test-Rpkg:
runs-on: ${{ matrix.os }}
name: Test R on OS ${{ matrix.os }}, R ${{ matrix.r }}, Compiler ${{ matrix.compiler }}, Build ${{ matrix.build }}
build-containers:
name: Build CI containers (${{ matrix.container_id }})
runs-on:
- runs-on
- runner=linux-amd64-cpu
- run-id=${{ github.run_id }}
- tag=r-tests-build-containers-${{ matrix.container_id }}
strategy:
fail-fast: false
matrix:
container_id:
- xgb-ci.gpu_build_r_rockylinux8
- xgb-ci.alpine
steps:
# Restart Docker daemon so that it recognizes the ephemeral disks
- run: sudo systemctl restart docker
- uses: actions/checkout@v4
with:
submodules: "true"
- name: Build ${{ matrix.container_id }}
run: bash ops/docker_build.sh ${{ matrix.container_id }}
test-rpkg:
name: Test R on ${{ matrix.name }}
needs: build-containers
runs-on:
- runs-on=${{ github.run_id }}
- runner=linux-amd64-cpu
- tag=r-tests-test-rpkg-${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
r: release
compiler: mingw
build: autotools
- os: ubuntu-latest
r: release
compiler: none
build: cmake
- name: rockylinux-cmake
container_id: xgb-ci.gpu_build_r_rockylinux8
build_tool: cmake
- name: rockylinux-autotools
container_id: xgb-ci.gpu_build_r_rockylinux8
build_tool: autotools
- name: alpine-autotools
container_id: xgb-ci.alpine
build_tool: autotools
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true

steps:
- name: Install system dependencies
run: |
sudo apt update
sudo apt install libcurl4-openssl-dev libssl-dev libssh2-1-dev libgit2-dev libglpk-dev libxml2-dev libharfbuzz-dev libfribidi-dev
if: matrix.os == 'ubuntu-latest'
# Restart Docker daemon so that it recognizes the ephemeral disks
- run: sudo systemctl restart docker
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Fetch container from cache
run: bash ops/docker_build.sh ${{ matrix.container_id }}
- name: Test R
run: |
bash ops/pipeline/test-rpkg.sh ${{ matrix.container_id }} ${{ matrix.build_tool }}
test-rpkg-windows:
runs-on: windows-latest
name: Test R on Windows
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r }}

r-version: release
- name: Cache R packages
uses: actions/cache@v4
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.r }}-7-${{ hashFiles('R-package/DESCRIPTION') }}
restore-keys: ${{ runner.os }}-r-${{ matrix.r }}-7-${{ hashFiles('R-package/DESCRIPTION') }}

key: ${{ runner.os }}-r-release-7-${{ hashFiles('R-package/DESCRIPTION') }}
restore-keys: ${{ runner.os }}-r-release-7-${{ hashFiles('R-package/DESCRIPTION') }}
- uses: actions/setup-python@v5
with:
python-version: "3.10"
architecture: 'x64'

- uses: r-lib/actions/setup-tinytex@v2

- name: Install dependencies
shell: Rscript {0}
run: |
source("./R-package/tests/helper_scripts/install_deps.R")
- name: Test R
shell: powershell
run: |
python ops/script/test_r_package.py --compiler='${{ matrix.compiler }}' --build-tool="${{ matrix.build }}" --task=check
if: matrix.compiler != 'none'

- name: Test R
run: |
python ops/script/test_r_package.py --build-tool="${{ matrix.build }}" --task=check
if: matrix.compiler == 'none'
python ops/script/test_r_package.py --compiler='mingw' `
--build-tool='autotools' --task=check
test-R-on-Debian:
name: Test R package on Debian
runs-on: ubuntu-latest
container:
image: rhub/debian-gcc-release

steps:
- name: Install system dependencies
run: |
# Must run before checkout to have the latest git installed.
# No need to add pandoc, the container has it figured out.
apt update && apt install libcurl4-openssl-dev libssl-dev libssh2-1-dev libgit2-dev libglpk-dev libxml2-dev libharfbuzz-dev libfribidi-dev git -y
apt update && apt install libcurl4-openssl-dev libssl-dev libssh2-1-dev libgit2-dev \
libglpk-dev libxml2-dev libharfbuzz-dev libfribidi-dev git -y
- name: Trust git cloning project sources
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
- uses: actions/checkout@v4
with:
submodules: 'true'

- name: Install dependencies
shell: bash -l {0}
run: |
Rscript -e "source('./R-package/tests/helper_scripts/install_deps.R')"
- name: Test R
shell: bash -l {0}
run: |
python3 ops/script/test_r_package.py --r=/usr/bin/R --build-tool=autotools --task=check
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
r_package:
- 'R-package/**'
- name: Run document check
if: steps.changes.outputs.r_package == 'true'
run: |
Expand Down
78 changes: 77 additions & 1 deletion R-package/configure
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ ac_includes_default="\
ac_header_cxx_list=
ac_subst_vars='LTLIBOBJS
LIBOBJS
DMLC_DEFS
BACKTRACE_LIB
ENDIAN_FLAG
OPENMP_LIB
Expand Down Expand Up @@ -1504,6 +1505,68 @@ fi
} # ac_fn_cxx_try_link
# ac_fn_cxx_check_func LINENO FUNC VAR
# ------------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
ac_fn_cxx_check_func ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
printf %s "(cached) " >&6
else $as_nop
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
For example, HP-UX 11i <limits.h> declares gettimeofday. */
#define $2 innocuous_$2
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $2 (); below. */
#include <limits.h>
#undef $2
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char $2 ();
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif
int
main (void)
{
return $2 ();
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"
then :
eval "$3=yes"
else $as_nop
eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
fi
eval ac_res=\$$3
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_cxx_check_func

# ac_fn_cxx_try_run LINENO
# ------------------------
# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that
Expand Down Expand Up @@ -2192,6 +2255,8 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu


DMLC_DEFS=""

### Check whether backtrace() is part of libc or the external lib libexecinfo
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking Backtrace lib" >&5
printf %s "checking Backtrace lib... " >&6; }
Expand Down Expand Up @@ -2866,7 +2931,17 @@ if test "x$ac_cv_lib_execinfo_backtrace" = xyes
then :
BACKTRACE_LIB=-lexecinfo
else $as_nop
BACKTRACE_LIB=''
BACKTRACE_LIB=''; DMLC_DEFS="$DMLC_DEFS -DDMLC_LOG_STACK_TRACE=0"
fi


### Check whether fopen64 is available
ac_fn_cxx_check_func "$LINENO" "fopen64" "ac_cv_func_fopen64"
if test "x$ac_cv_func_fopen64" = xyes
then :

else $as_nop
DMLC_DEFS="$DMLC_DEFS -DDMLC_USE_FOPEN64=0"
fi


Expand Down Expand Up @@ -3205,6 +3280,7 @@ fi




ac_config_files="$ac_config_files src/Makevars"

ac_config_headers="$ac_config_headers config.h"
Expand Down
10 changes: 9 additions & 1 deletion R-package/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
AC_LANG(C++)

DMLC_DEFS=""

### Check whether backtrace() is part of libc or the external lib libexecinfo
AC_MSG_CHECKING([Backtrace lib])
AC_MSG_RESULT([])
AC_CHECK_LIB([execinfo], [backtrace], [BACKTRACE_LIB=-lexecinfo], [BACKTRACE_LIB=''])
AC_CHECK_LIB([execinfo], [backtrace],
[BACKTRACE_LIB=-lexecinfo],
[BACKTRACE_LIB=''; DMLC_DEFS="$DMLC_DEFS -DDMLC_LOG_STACK_TRACE=0"])

### Check whether fopen64 is available
AC_CHECK_FUNC(fopen64, [], [DMLC_DEFS="$DMLC_DEFS -DDMLC_USE_FOPEN64=0"])

### Endian detection
AC_ARG_VAR(USE_LITTLE_ENDIAN, "Whether to build with little endian (checks at compile time if unset)")
Expand Down Expand Up @@ -83,6 +90,7 @@ AC_SUBST(OPENMP_CXXFLAGS)
AC_SUBST(OPENMP_LIB)
AC_SUBST(ENDIAN_FLAG)
AC_SUBST(BACKTRACE_LIB)
AC_SUBST(DMLC_DEFS)
AC_CONFIG_FILES([src/Makevars])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT
1 change: 1 addition & 0 deletions R-package/src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PKG_CPPFLAGS = \
-I$(PKGROOT)/include \
-I$(PKGROOT)/dmlc-core/include \
-I$(PKGROOT) \
@DMLC_DEFS@ \
$(XGB_RFLAGS)

PKG_CXXFLAGS = \
Expand Down
3 changes: 3 additions & 0 deletions ops/docker/ci_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ xgb-ci.gpu_build_r_rockylinux8:
CUDA_VERSION_ARG: "12.4.1"
R_VERSION_ARG: "4.3.2"

xgb-ci.alpine:
container_def: alpine

xgb-ci.gpu:
container_def: gpu
build_args:
Expand Down
20 changes: 20 additions & 0 deletions ops/docker/dockerfile/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine:3.20
ENV TZ=UTC
RUN apk add --no-cache bash
SHELL ["/bin/bash", "-c"]
RUN apk add --no-cache R R-dev R-doc g++ shadow

ENV GOSU_VERSION=1.10

# Install lightweight sudo (not bound to TTY)
RUN set -ex; \
wget -nv -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-amd64" && \
chmod +x /usr/local/bin/gosu && \
gosu nobody true

# Default entry-point to use if running locally
# It will preserve attributes of created files
COPY docker/entrypoint.sh /scripts/

WORKDIR /workspace
ENTRYPOINT ["/scripts/entrypoint.sh"]
2 changes: 1 addition & 1 deletion ops/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ then
"${CI_BUILD_USER}" || true
export HOME="/home/${CI_BUILD_USER}"
shopt -s dotglob
cp -r /root/* "$HOME/"
cp -r /root/* "$HOME/" || true
chown -R "${CI_BUILD_UID}:${CI_BUILD_GID}" "$HOME"

# Allows project-specific customization
Expand Down
17 changes: 17 additions & 0 deletions ops/pipeline/test-rpkg-impl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
## Test R package on Linux

set -euo pipefail

if [[ "$#" -lt 1 ]]
then
echo "Usage: $0 {autotools, cmake}"
exit 1
fi

build_tool="$1"

set -x

gosu root Rscript ./R-package/tests/helper_scripts/install_deps.R
python3 ops/script/test_r_package.py --build-tool="${build_tool}"
Loading

0 comments on commit 23a21ef

Please sign in to comment.