Skip to content

Commit

Permalink
Setup github action. (#5917)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis authored Jul 22, 2020
1 parent 627cf41 commit 66cc1e0
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 12 deletions.
49 changes: 37 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,46 @@ on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test-with-jvm:
name: Test JVM on OS ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, windows-2016, ubuntu-latest]

steps:
- uses: actions/checkout@v2
with:
submodules: 'true'

- uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Test JVM packages
run: |
cd jvm-packages
mvn test -pl :xgboost4j_2.12
test-with-R:
runs-on: ${{ matrix.config.os }}

name: Test R on OS ${{ matrix.config.os }}, R (${{ matrix.config.r }})
name: Test R on OS ${{ matrix.config.os }}, R ${{ matrix.config.r }}, Compiler ${{ matrix.config.compiler }}, Build ${{ matrix.config.build }}

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: 'release', compiler: 'msvc', build: 'autotools'}
- {os: windows-2016, r: 'release', compiler: 'msvc', build: 'autotools'}
- {os: windows-latest, r: 'release', compiler: 'msvc', build: 'cmake'}
- {os: windows-2016, r: 'release', compiler: 'msvc', build: 'cmake'}
- {os: windows-latest, r: 'release', compiler: 'mingw', build: 'autotools'}
- {os: windows-2016, r: 'release', compiler: 'mingw', build: 'autotools'}
- {os: windows-latest, r: 'release', compiler: 'mingw', build: 'cmake'}
- {os: windows-2016, r: 'release', compiler: 'mingw', build: 'cmake'}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
Expand All @@ -37,16 +67,11 @@ jobs:
install.packages(c('XML','igraph'))
install.packages(c('data.table','magrittr','stringi','ggplot2','DiagrammeR','Ckmeans.1d.dp','vcd','testthat','lintr','knitr','rmarkdown'))
- name: Config R
run: |
mkdir build && cd build
cmake .. -DCMAKE_CONFIGURATION_TYPES="Release" -DR_LIB=ON
- name: Build R
run: |
cmake --build build --target install --config Release
- uses: actions/setup-python@v2
with:
python-version: '3.6' # Version range or exact version of a Python version to use, using SemVer's version range syntax
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified

- name: Test R
run: |
cd R-package
R.exe -q -e "library(testthat); setwd('tests'); source('testthat.R')"
python tests/ci_build/test_r_package.py --compiler="${{ matrix.config.compiler }}" --build-tool="${{ matrix.config.build }}"
103 changes: 103 additions & 0 deletions tests/ci_build/test_r_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import argparse
import os
import subprocess

ROOT = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.pardir,
os.path.pardir))
r_package = os.path.join(ROOT, 'R-package')


class DirectoryExcursion:
def __init__(self, path: os.PathLike):
self.path = path
self.curdir = os.path.normpath(os.path.abspath(os.path.curdir))

def __enter__(self):
os.chdir(self.path)

def __exit__(self, *args):
os.chdir(self.curdir)


def get_mingw_bin():
return os.path.join('c:/rtools40/mingw64/', 'bin')


def test_with_autotools(args):
with DirectoryExcursion(r_package):
if args.compiler == 'mingw':
mingw_bin = get_mingw_bin()
CXX = os.path.join(mingw_bin, 'g++.exe')
CC = os.path.join(mingw_bin, 'gcc.exe')
cmd = ['R.exe', 'CMD', 'INSTALL', str(os.path.curdir)]
env = os.environ.copy()
env.update({'CC': CC, 'CXX': CXX})
subprocess.check_call(cmd, env=env)
elif args.compiler == 'msvc':
cmd = ['R.exe', 'CMD', 'INSTALL', str(os.path.curdir)]
env = os.environ.copy()
# autotool favor mingw by default.
env.update({'CC': 'cl.exe', 'CXX': 'cl.exe'})
subprocess.check_call(cmd, env=env)
else:
raise ValueError('Wrong compiler')
subprocess.check_call([
'R.exe', '-q', '-e',
"library(testthat); setwd('tests'); source('testthat.R')"
])


def test_with_cmake(args):
os.mkdir('build')
with DirectoryExcursion('build'):
if args.compiler == 'mingw':
mingw_bin = get_mingw_bin()
CXX = os.path.join(mingw_bin, 'g++.exe')
CC = os.path.join(mingw_bin, 'gcc.exe')
env = os.environ.copy()
env.update({'CC': CC, 'CXX': CXX})
subprocess.check_call([
'cmake', os.path.pardir, '-DUSE_OPENMP=ON', '-DR_LIB=ON',
'-DCMAKE_CONFIGURATION_TYPES=Release', '-G', 'Unix Makefiles',
],
env=env)
subprocess.check_call(['make', '-j', 'install'])
elif args.compiler == 'msvc':
subprocess.check_call([
'cmake', os.path.pardir, '-DUSE_OPENMP=ON', '-DR_LIB=ON',
'-DCMAKE_CONFIGURATION_TYPES=Release', '-A', 'x64'
])
subprocess.check_call([
'cmake', '--build', os.path.curdir, '--target', 'install',
'--config', 'Release'
])
else:
raise ValueError('Wrong compiler')
with DirectoryExcursion(r_package):
subprocess.check_call([
'R.exe', '-q', '-e',
"library(testthat); setwd('tests'); source('testthat.R')"
])


def main(args):
if args.build_tool == 'autotools':
test_with_autotools(args)
else:
test_with_cmake(args)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--compiler',
type=str,
choices=['mingw', 'msvc'],
help='Compiler used for compiling CXX code.')
parser.add_argument(
'--build-tool',
type=str,
choices=['cmake', 'autotools'],
help='Build tool for compiling CXX code and install R package.')
args = parser.parse_args()
main(args)
4 changes: 4 additions & 0 deletions tests/python/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import pytest
import testing as tm
import numpy as np
import sys

if sys.platform.startswith("win"):
pytest.skip("Skipping dask tests on Windows", allow_module_level=True)


def test_rabit_tracker():
Expand Down

0 comments on commit 66cc1e0

Please sign in to comment.