Skip to content

Commit

Permalink
Merge branch 'master' into dask/ranker
Browse files Browse the repository at this point in the history
  • Loading branch information
ffineis committed Jan 16, 2021
2 parents a33a4de + f2695da commit 78358e2
Show file tree
Hide file tree
Showing 75 changed files with 1,959 additions and 967 deletions.
50 changes: 50 additions & 0 deletions .ci/append_comment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#
# [description]
# Update comment appending a given body to the specified original comment.
#
# [usage]
# append_comment.sh <COMMENT_ID> <BODY>
#
# COMMENT_ID: ID of comment that should be modified.
#
# BODY: Text that will be appended to the original comment body.

set -e

if [ -z "$GITHUB_ACTIONS" ]; then
echo "Must be run inside GitHub Actions CI"
exit -1
fi

if [ $# -ne 2 ]; then
echo "Usage: $0 <COMMENT_ID> <BODY>"
exit -1
fi

comment_id=$1
body=$2

old_comment_body=$(
curl -sL \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $SECRETS_WORKFLOW" \
"${GITHUB_API_URL}/repos/microsoft/LightGBM/issues/comments/$comment_id" | \
jq '.body'
)
body=${body/failure/failure ❌}
body=${body/error/failure ❌}
body=${body/cancelled/failure ❌}
body=${body/timed_out/failure ❌}
body=${body/success/success ✔️}
data=$(
jq -n \
--argjson body "${old_comment_body%?}\r\n\r\n$body\"" \
'{"body":$body}'
)
curl -sL \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $SECRETS_WORKFLOW" \
-d "$data" \
"${GITHUB_API_URL}/repos/microsoft/LightGBM/issues/comments/$comment_id"
87 changes: 87 additions & 0 deletions .ci/get_workflow_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# coding: utf-8
"""Get the most recent status of workflow for the current PR.
[usage]
python get_workflow_status.py TRIGGER_PHRASE
TRIGGER_PHRASE: Code phrase that triggers workflow.
"""
import json
from os import environ
from sys import argv, exit
from time import sleep
try:
from urllib import request
except ImportError:
import urllib2 as request


def get_runs(trigger_phrase):
"""Get all triggering workflow comments in the current PR.
Parameters
----------
trigger_phrase : string
Code phrase that triggers workflow.
Returns
-------
pr_runs : list
List of comment objects sorted by the time of creation in decreasing order.
"""
pr_runs = []
if environ.get("GITHUB_EVENT_NAME", "") == "pull_request":
pr_number = int(environ.get("GITHUB_REF").split('/')[-2])
req = request.Request(url="{}/repos/microsoft/LightGBM/issues/{}/comments".format(environ.get("GITHUB_API_URL"),
pr_number),
headers={"Accept": "application/vnd.github.v3+json"})
url = request.urlopen(req)
data = json.loads(url.read().decode('utf-8'))
url.close()
pr_runs = [i for i in data
if i['author_association'].lower() in {'owner', 'member', 'collaborator'}
and i['body'].startswith('/gha run {}'.format(trigger_phrase))]
return pr_runs[::-1]


def get_status(runs):
"""Get the most recent status of workflow for the current PR.
Parameters
----------
runs : list
List of comment objects sorted by the time of creation in decreasing order.
Returns
-------
status : string
The most recent status of workflow.
Can be 'success', 'failure' or 'in-progress'.
"""
status = 'success'
for run in runs:
body = run['body']
if "Status: " in body:
if "Status: skipped" in body:
continue
if "Status: failure" in body:
status = 'failure'
break
if "Status: success" in body:
status = 'success'
break
else:
status = 'in-progress'
break
return status


if __name__ == "__main__":
trigger_phrase = argv[1]
while True:
status = get_status(get_runs(trigger_phrase))
if status != 'in-progress':
break
sleep(60)
if status == 'failure':
exit(1)
31 changes: 12 additions & 19 deletions .ci/install_opencl.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
Write-Output "Installing OpenCL CPU platform"

$cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135"
$installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe"

if ($env:OPENCL_INSTALLER_FOUND -ne 'true') {
# Pipeline cache miss; download OpenCL platform installer executable into workspace cache
Write-Output "Downloading OpenCL platform installer"
Invoke-WebRequest -OutFile "$installer" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer"
Write-Output "Downloading OpenCL platform installer"
$ProgressPreference = "SilentlyContinue" # progress bar bug extremely slows down download speed
Invoke-WebRequest -OutFile "$installer" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer"

Write-Output "Caching OpenCL platform installer"
New-Item $cache -ItemType Directory | Out-Null
Move-Item -Path "$installer" -Destination "$cache\$installer" | Out-Null

if (Test-Path "$cache\$installer") {
Write-Output "Successfully downloaded OpenCL platform installer"
} else {
Write-Output "Unable to download OpenCL platform installer"
Write-Output "Setting EXIT"
$host.SetShouldExit(-1)
Exit -1
}
if (Test-Path "$installer") {
Write-Output "Successfully downloaded OpenCL platform installer"
} else {
Write-Output "Unable to download OpenCL platform installer"
Write-Output "Setting EXIT"
$host.SetShouldExit(-1)
Exit -1
}

# Install OpenCL platform from installer executable expected in workspace cache
# Install OpenCL platform from installer executable
Write-Output "Running OpenCL installer"
Invoke-Command -ScriptBlock {Start-Process "$cache\$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait}
Invoke-Command -ScriptBlock { Start-Process "$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait }

$property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors
if ($property -eq $null) {
Expand Down
47 changes: 47 additions & 0 deletions .ci/rerun_workflow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
#
# [description]
# Rerun specified workflow for given pull request.
#
# [usage]
# rerun_workflow.sh <WORKFLOW_ID> <PR_NUMBER> <PR_BRANCH>
#
# WORKFLOW_ID: Identifier (config name of ID) of a workflow to be rerun.
#
# PR_NUMBER: Number of pull request for which workflow should be rerun.
#
# PR_BRANCH: Name of pull request's branch.

set -e

if [ -z "$GITHUB_ACTIONS" ]; then
echo "Must be run inside GitHub Actions CI"
exit -1
fi

if [ $# -ne 3 ]; then
echo "Usage: $0 <WORKFLOW_ID> <PR_NUMBER> <PR_BRANCH>"
exit -1
fi

workflow_id=$1
pr_number=$2
pr_branch=$3

runs=$(
curl -sL \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $SECRETS_WORKFLOW" \
"${GITHUB_API_URL}/repos/microsoft/LightGBM/actions/workflows/${workflow_id}/runs?event=pull_request&branch=${pr_branch}" | \
jq '.workflow_runs'
)
runs=$(echo $runs | jq --arg pr_number "$pr_number" --arg pr_branch "$pr_branch" 'map(select(.event == "pull_request" and ((.pull_requests | length) != 0 and (.pull_requests[0].number | tostring) == $pr_number or .head_branch == $pr_branch)))')
runs=$(echo $runs | jq 'sort_by(.run_number) | reverse')

if [[ $(echo $runs | jq 'length') -gt 0 ]]; then
curl -sL \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $SECRETS_WORKFLOW" \
"${GITHUB_API_URL}/repos/microsoft/LightGBM/actions/runs/$(echo $runs | jq '.[0].id')/rerun"
fi
53 changes: 53 additions & 0 deletions .ci/set_commit_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
#
# [description]
# Set a status with a given name to the specified commit.
#
# [usage]
# set_commit_status.sh <NAME> <STATUS> <SHA>
#
# NAME: Name of status.
# Status with existing name overwrites a previous one.
#
# STATUS: Status to be set.
# Can be "error", "failure", "pending" or "success".
#
# SHA: SHA of a commit to set a status on.

set -e

if [ -z "$GITHUB_ACTIONS" ]; then
echo "Must be run inside GitHub Actions CI"
exit -1
fi

if [ $# -ne 3 ]; then
echo "Usage: $0 <NAME> <STATUS> <SHA>"
exit -1
fi

name=$1

status=$2
status=${status/error/failure}
status=${status/cancelled/failure}
status=${status/timed_out/failure}
status=${status/in_progress/pending}
status=${status/queued/pending}

sha=$3

data=$(
jq -n \
--arg state $status \
--arg url "${GITHUB_SERVER_URL}/microsoft/LightGBM/actions/runs/${GITHUB_RUN_ID}" \
--arg name "$name" \
'{"state":$state,"target_url":$url,"context":$name}'
)

curl -sL \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $SECRETS_WORKFLOW" \
-d "$data" \
"${GITHUB_API_URL}/repos/microsoft/LightGBM/statuses/$sha"
47 changes: 44 additions & 3 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,47 @@ if [[ $OS_NAME == "macos" ]]; then
fi
wget -q -O conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
else # Linux
if [[ $IN_UBUNTU_LATEST_CONTAINER == "true" ]]; then

# fixes error "unable to initialize frontend: Dialog"
# https://github.com/moby/moby/issues/27988#issuecomment-462809153
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections

sudo apt-get update
sudo apt-get install -y --no-install-recommends \
software-properties-common

sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update

sudo apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
ca-certificates \
curl \
git \
iputils-ping \
jq \
libcurl4 \
libicu66 \
libssl1.1 \
libunwind8 \
locales \
netcat \
unzip \
wget \
zip

export LANG="en_US.UTF-8"
export LC_ALL="${LANG}"
sudo locale-gen ${LANG}
sudo update-locale

sudo apt-get install -y --no-install-recommends \
cmake \
clang \
libomp-dev
fi
if [[ $TASK == "mpi" ]]; then
sudo apt-get update
sudo apt-get install --no-install-recommends -y libopenmpi-dev openmpi-bin
Expand All @@ -43,13 +84,13 @@ else # Linux
chmod +x cmake.sh
./cmake.sh --prefix=/usr/local --exclude-subdir
fi
if [[ $TRAVIS == "true" ]] || [[ $GITHUB_ACTIONS == "true" ]]; then
if [[ $SETUP_CONDA != "false" ]]; then
wget -q -O conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
fi
fi

if [[ "${TASK:0:9}" != "r-package" ]]; then
if [[ $TRAVIS == "true" ]] || [[ $OS_NAME == "macos" ]]; then
if [[ "${TASK}" != "r-package" ]]; then
if [[ $SETUP_CONDA != "false" ]]; then
sh conda.sh -b -p $CONDA
fi
conda config --set always_yes yes --set changeps1 no
Expand Down
Loading

0 comments on commit 78358e2

Please sign in to comment.