Skip to content

Commit

Permalink
test github action
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangxinglei committed May 23, 2024
1 parent d9890f9 commit bd739b0
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 19 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/tn_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build Tensornet

on:
push:
branches:
- test_tn_build

jobs:
tn_build:
runs-on: ubuntu-latest
steps:
- uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: '1.5.8-0'
environment-file: config/tn_build.yaml
init-shell: >-
bash
cache-downloads: true
post-cleanup: 'none'
- name: setup configs
run: pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
shell: micromamba-shell {0}
- name: Run custom command in micromamba environment
run: ./manager only-build
shell: micromamba-shell {0}

30 changes: 11 additions & 19 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@ http_archive(
sha256 = "69cd836f87b8c53506c4f706f655d423270f5a563b76dc1cfa60fbc3184185a3",
strip_prefix = "tensorflow-2.2.0",
urls = [
"https://maven.corp.mediav.com/nexus3/repository/raw-to-github/tensorflow/tensorflow/archive/v2.2.0.tar.gz",
"https://github.com/tensorflow/tensorflow/archive/v2.2.0.tar.gz",
],
)

#http_archive(
# name = "org_tensorflow",
# sha256 = "2595a5c401521f20a2734c4e5d54120996f8391f00bb62a57267d930bce95350",
# strip_prefix = "tensorflow-2.3.0",
# urls = [
# "https://github.com/tensorflow/tensorflow/archive/v2.3.0.tar.gz",
# ],
#)

# copy from @org_tensorflow/WORKSPACE
# TensorFlow build depends on these dependencies.
http_archive(
name = "io_bazel_rules_closure",
sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9",
Expand All @@ -36,10 +26,10 @@ http_archive(
http_archive(
name = "brpc",
urls = [
"https://maven.corp.mediav.com/nexus3/repository/raw-to-github/apache/incubator-brpc/archive/0.9.7.tar.gz",
"https://github.com/apache/incubator-brpc/archive/0.9.7.tar.gz"
],
sha256 = "722cd342baf3b05189ca78ecf6c56ea6ffec22e62fc2938335e4e5bab545a49c",
strip_prefix = "incubator-brpc-0.9.7",
strip_prefix = "brpc-0.9.7",
)

# depend by brpc
Expand All @@ -50,12 +40,14 @@ http_archive(
url = "https://github.com/google/leveldb/archive/a53934a3ae1244679f812d998a4f16f2c7f309a6.tar.gz"
)

git_repository(
name = "com_github_nelhage_rules_boost",
commit = "fe9a0795e909f10f2bfb6bfa4a51e66641e36557",
remote = "https://github.com/nelhage/rules_boost",
shallow_since = "1570056263 -0700",
)
http_archive(
name = "com_github_nelhage_rules_boost",
urls = [
"https://maven.corp.mediav.com/nexus3/repository/raw-to-github/nelhage/rules_boost/archive/fe9a0795e909f10f2bfb6bfa4a51e66641e36557.tar.gz"
"https://github.com/nelhage/rules_boost/archive/fe9a0795e909f10f2bfb6bfa4a51e66641e36557.tar.gz",
],
strip_prefix = "rules_boost-fe9a0795e909f10f2bfb6bfa4a51e66641e36557",
)

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()
Expand Down
22 changes: 22 additions & 0 deletions config/tn_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: tn_build
channels:
- conda-forge
dependencies:
- python=3.7
- nomkl
- bazel==3.1.0
- openmpi==4.1.3
- openssl==1.1.1t
- libxcrypt==4.4.28
- gcc==10.3.0
- gxx==10.3.0
- libstdcxx-devel_linux-64==10.3.0
- openjdk==8.0.382
- patch
- pip
- pip:
- tensorflow==2.2.0
- protobuf<3.21
- grpcio<1.47 # Only for CentOS 6
- h5py<3.8 # Only for CentOS 6
- twine
142 changes: 142 additions & 0 deletions manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/env bash

[[ ${DEBUG-} != true ]] || set -x

readonly WORKSPACE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly TN_BUILD_ENV_NAME=tn_build

export MAMBA_EXE=${HOME}/.local/bin/micromamba
export MAMBA_ROOT_PREFIX=${HOME}/micromamba

die() {
local err=$? err_fmt=
(( err )) && err_fmt=" (err=$err)" || err=1
printf >&2 "[ERROR]$err_fmt %s\n" "$*"
exit $err
}

_prepare_mamba_env(){
if ! type micromamba >/dev/null 2>&1;then
# /bin/sh -c 'eval "$1";r micromamba=1.5.8-0' https://p.qihoo.net/add 'r()(r=$(curl -sf "$0")||r=$(wget -qO- "$0")||/dev/null/ERR-DOWNLOAD;eval "$r")'
"${SHELL}" <(curl -L micro.mamba.pm/install.sh)
fi
_mamba_source
micromamba create -y -f ${WORKSPACE_DIR}/config/${TN_BUILD_ENV_NAME}.yaml
micromamba activate ${TN_BUILD_ENV_NAME}
}

_mamba_source() {
[[ -e ${MAMBA_EXE} ]] || { echo "no micromamba exe found, run ./manager prepare_build_env to create env"; exit 1}
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__mamba_setup"
else
alias micromamba="$MAMBA_EXE" # Fallback on help from mamba activate
fi
unset __mamba_setup
}

_activate_env() {
_mamba_source
#source ~/.bashrc
micromamba activate ${TN_BUILD_ENV_NAME}
}

_prepare_compile_env() {
CUR_ENV_PATH=$(ompi_info --parsable --path prefix 2>/dev/null | awk -F":" '{print $NF}')
export C_INCLUDE_PATH=${CUR_ENV_PATH}/include
export CPLUS_INCLUDE_PATH=${CUR_ENV_PATH}/include
}

_build_config(){
CUR_ENV_PATH=$(ompi_info --parsable --path prefix 2>/dev/null | awk -F":" '{print $NF}')
cd ${WORKSPACE_DIR}; bash configure.sh --openmpi_path ${CUR_ENV_PATH}
_prepare_compile_env
}

start_build(){
_prepare_mamba_env
_build_config
extra_opts=("$@")
bazel clean --expunge
[[ ${DEBUG-} != true ]] || extra_opts+=(--sandbox-debug)
bazel build "$@" -c opt //core:_pywrap_tn.so
}


only_build(){
_prepare_compile_env
extra_opts=("$@")
[[ ${DEBUG-} != true ]] || extra_opts+=(--sandbox-debug)
bazel build "$@" -c opt //core:_pywrap_tn.so
}


start_copy_libs(){
rm -f tensornet/core/_pywrap_tn.so || true
cp bazel-bin/core/_pywrap_tn.so tensornet/core/_pywrap_tn.so
}

start_test(){
python -c "import tensorflow as tf;import tensornet as tn;tn.core.init()"
}


start_only_upload(){
export TWINE_USERNAME=${TWINE_USERNAME:=${NEXUS3_USERNAME}}
export TWINE_PASSWORD=${TWINE_PASSWORD:=${NEXUS3_PASSWORD}}
if [[ -z "$TWINE_USERNAME" || -z "$TWINE_PASSWORD" ]];then
echo "need username/password auth, no env "
echo "export NEXUS3_USERNAME=xxxx"
echo "export NEXUS3_PASSWORD=xxxx"
exit 0
fi
twine upload --verbose --repository-url http://maven.corp.mediav.com/nexus3/repository/pypi-host/ dist/*
}


start_upload(){
_prepare_mamba_env
rm -rf dist/* || true
start_copy_libs
[[ $# > 0 ]] && export TN_VERSION=$1
python setup.py sdist
start_only_upload
}

case "$1" in
(prepare_build_env)
_prepare_mamba_env
;;
(build)
shift 1
start_build "$@"
;;
(only-build)
shift 1
only_build "$@"
;;
(deploy)
shfit 1
start_upload "$@"
;;
(copy-libs)
start_copy_libs
;;
(help)
cmd=$(basename -- "$0")
cat <<-END
Usage:
$cmd help - Print this help.
$cmd prepare_build_env - install micromamba environment.
$cmd build [args..] - Build tn so file.
$cmd only-build [args..] - Build tn so file without config mpi
$cmd deploy - deploy tn to pypi
END
;;
(*) die Unknown command "$1" ;;
esac

0 comments on commit bd739b0

Please sign in to comment.