Skip to content

Commit 69060a1

Browse files
Merge pull request tensorflow#3 from tensorflow/chrisl/code-format-check
Separate code format check into separate CI task
2 parents fe40673 + e0ba5f6 commit 69060a1

File tree

2 files changed

+234
-0
lines changed

2 files changed

+234
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#! /bin/bash
2+
3+
# ==============================================================================
4+
# Copyright 2018 Intel Corporation
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
# ==============================================================================
18+
19+
# Script parameters:
20+
#
21+
# $1 ImageID Required: ID of the ngtf_bridge_ci docker image to use
22+
23+
set -e # Fail on any command with non-zero exit
24+
25+
IMAGE_ID="${1}"
26+
if [ -z "${IMAGE_ID}" ] ; then
27+
echo 'Please provide an image version as the first parameter'
28+
exit 1
29+
fi
30+
31+
# Check if we have a docker ID of image:ID, or just ID
32+
# Use || true to make sure the exit code is always zero, so that the script is
33+
# not killed if ':' is not found
34+
long_ID=`echo ${IMAGE_ID} | grep ':' || true`
35+
36+
# If we have just ID, then IMAGE_CLASS AND IMAGE_ID have
37+
# already been set above
38+
#
39+
# Handle case where we have image:ID
40+
if [ ! -z "${long_ID}" ] ; then
41+
IMAGE_CLASS=` echo ${IMAGE_ID} | sed -e 's/:[^:]*$//' `
42+
IMAGE_ID=` echo ${IMAGE_ID} | sed -e 's/^[^:]*://' `
43+
fi
44+
45+
# Find the top-level bridge directory, so we can mount it into the docker
46+
# container
47+
bridge_dir="$(realpath ../../..)"
48+
49+
bridge_mountpoint='/home/dockuser/ngraph-tf'
50+
tf_mountpoint='/home/dockuser/tensorflow'
51+
52+
# Set up a bunch of volume mounts
53+
volume_mounts="-v ${bridge_dir}:${bridge_mountpoint}"
54+
55+
set -u # No unset variables after this point
56+
57+
RUNASUSER_SCRIPT="${bridge_mountpoint}/test/ci/docker/docker-scripts/run-as-user.sh"
58+
BUILD_SCRIPT="${bridge_mountpoint}/test/ci/docker/docker-scripts/run-check-code-format.sh"
59+
60+
# If proxy settings are detected in the environment, make sure they are
61+
# included on the docker-build command-line. This mirrors a similar system
62+
# in the Makefile.
63+
64+
if [ ! -z "${http_proxy}" ] ; then
65+
DOCKER_HTTP_PROXY="--env http_proxy=${http_proxy}"
66+
else
67+
DOCKER_HTTP_PROXY=' '
68+
fi
69+
70+
if [ ! -z "${https_proxy}" ] ; then
71+
DOCKER_HTTPS_PROXY="--env https_proxy=${https_proxy}"
72+
else
73+
DOCKER_HTTPS_PROXY=' '
74+
fi
75+
76+
drun_cmd="docker run --rm \
77+
--env RUN_UID=$(id -u) \
78+
--env RUN_CMD=${BUILD_SCRIPT} \
79+
${DOCKER_HTTP_PROXY} ${DOCKER_HTTPS_PROXY} \
80+
${volume_mounts} \
81+
${IMAGE_CLASS}:${IMAGE_ID} ${RUNASUSER_SCRIPT}"
82+
83+
echo "Docker build command: ${drun_cmd}"
84+
$drun_cmd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
2+
#! /bin/bash
3+
4+
# ==============================================================================
5+
# Copyright 2018 Intel Corporation
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
# ==============================================================================
19+
20+
# This script is designed to be called from within a docker container.
21+
# It is installed into a docker image. It will not run outside the container.
22+
23+
set -e # Make sure we exit on any command that returns non-zero
24+
set -u # No unset variables
25+
set -o pipefail # Make sure cmds in pipe that are non-zero also fail immediately
26+
27+
# Set up some important known directories
28+
bridge_dir='/home/dockuser/ngraph-tf'
29+
bbuild_dir="${bridge_dir}/build"
30+
tf_dir="${bbuild_dir}/tensorflow"
31+
ci_dir="${bridge_dir}/test/ci/docker"
32+
venv_dir="/tmp/venv_code_check"
33+
ngraph_wheel_dir="${bbuild_dir}"
34+
35+
# HOME is expected to be /home/dockuser. See script run-as-user.sh, which
36+
# sets this up.
37+
38+
echo "In $(basename ${0}):"
39+
echo ''
40+
echo " bridge_dir=${bridge_dir}"
41+
echo " bbuild_dir=${bbuild_dir}"
42+
echo " tf_dir=${tf_dir}"
43+
echo " ci_dir=${ci_dir}"
44+
echo " venv_dir=${venv_dir}"
45+
echo " ngraph_wheel_dir=${ngraph_wheel_dir}"
46+
echo ''
47+
echo " HOME=${HOME}"
48+
49+
# Do some up-front checks, to make sure necessary directories are in-place and
50+
# build directories are not-in-place
51+
52+
if [ -d "${bbuild_dir}" ] ; then
53+
( >&2 echo '***** Error: *****' )
54+
( >&2 echo "Bridge build directory already exists -- please remove it before calling this script: ${bbuild_dir}" )
55+
exit 1
56+
fi
57+
58+
if [ -d "${venv_dir}" ] ; then
59+
( >&2 echo '***** Error: *****' )
60+
( >&2 echo "Virtual-env build directory already exists -- please remove it before calling this script: ${venv_dir}" )
61+
exit 1
62+
fi
63+
64+
# Make sure the Bazel cache is in /tmp, as docker images have too little space
65+
# in the root filesystem, where /home (and $HOME/.cache) is. Even though we
66+
# may not be using the Bazel cache in the builds (in docker), we do this anyway
67+
# in case we decide to turn the Bazel cache back on.
68+
echo "Adjusting bazel cache to be located in /tmp/bazel-cache"
69+
rm -fr "$HOME/.cache"
70+
mkdir /tmp/bazel-cache
71+
ln -s /tmp/bazel-cache "$HOME/.cache"
72+
73+
xtime="$(date)"
74+
echo ' '
75+
echo "===== Checking gcc, python and OS version at ${xtime} ====="
76+
echo ' '
77+
78+
echo 'gcc is being run from:'
79+
which gcc
80+
81+
echo ' '
82+
echo 'gcc verison is:'
83+
gcc --version
84+
85+
echo 'g++ is being run from:'
86+
which g++
87+
88+
echo ' '
89+
echo 'g++ version is:'
90+
g++ --version
91+
92+
echo ' '
93+
echo 'python version is:'
94+
python --version
95+
96+
echo ' '
97+
echo 'python2 version is:'
98+
python2 --version
99+
100+
echo ' '
101+
echo 'python3 version is:'
102+
python3 --version
103+
104+
echo ' '
105+
echo 'virtualenv version is:'
106+
virtualenv --version
107+
108+
echo ' '
109+
echo 'pip version is:'
110+
pip --version
111+
112+
echo ' '
113+
echo 'Ubuntu version is:'
114+
cat /etc/os-release
115+
116+
xtime="$(date)"
117+
echo ' '
118+
echo "===== Setting Up Virtual Environment for Code-Format Check at ${xtime} ====="
119+
echo ' '
120+
121+
# Make sure the bash shell prompt variables are set, as virtualenv crashes
122+
# if PS2 is not set.
123+
PS1='prompt> '
124+
PS2='prompt-more> '
125+
virtualenv --system-site-packages -p /usr/bin/python2 "${venv_dir}"
126+
source "${venv_dir}/bin/activate"
127+
128+
# yapf and futures are needed for code-format checks (ngraph-tf PR#211)
129+
pip install yapf==0.24.0
130+
pip install futures
131+
132+
xtime="$(date)"
133+
echo ' '
134+
echo "===== Starting nGraph TensorFlow Bridge Source Code Format Check at ${xtime} ====="
135+
echo ' '
136+
137+
cd "${bridge_dir}"
138+
maint/check-code-format.sh
139+
140+
xtime="$(date)"
141+
echo ' '
142+
echo "===== Deactivating Virtual Environment at ${xtime} ====="
143+
echo ' '
144+
145+
deactivate
146+
147+
xtime="$(date)"
148+
echo ' '
149+
echo "===== Completed Code Format Check at ${xtime} ====="
150+
echo ' '

0 commit comments

Comments
 (0)