Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI tests in upstream repository #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
76 changes: 57 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ env:
# RUSTFLAGS: "-D warnings" # it needs some works to enable this flag

jobs:
tests:
pre-compile-check:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
# TODO(someone): re-enable the following platforms
# - macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -28,30 +29,67 @@ jobs:
toolchain: stable
override: true
components: rustfmt
- name: Execute version check
run: ./test-all version-check
shell: bash
- name: Execute clippy check
run: ./test-all clippy-cmd
shell: bash
- name: Execute fmt check
run: ./test-all fmt-cmd
shell: bash
- name: Setup Python # Set Python version
uses: actions/setup-python@v4
with:
python-version: "3.10"
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
# TODO(someone): re-enable the following platforms
# - macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: Execute test check
run: ./test-all test-cmd
shell: bash
- name: Execute doc check
run: ./test-all doc-cmd
shell: bash
- name: Execute attributes check
run: ./test-all attributes-check
shell: bash
examples:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
# TODO(someone): re-enable the following platforms
# - macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
# Install pip and pytest
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r .github/workflows/requirements.txt
- name: Execute test-all
run: ./test-all
- name: Execute example check
run: ./test-all example-cmd
shell: bash
# clippy:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# rust:
# - beta
# steps:
# - uses: actions/checkout@v2
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: ${{ matrix.rust }}
# override: true
# components: clippy
# - run: cargo clippy
179 changes: 108 additions & 71 deletions test-all
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,116 @@ function run {
echo
}

# Make sure the Tensorflow version in the -sys build script matches the one in
# the run-valgrind script.
version_build_script=`grep "const VERSION" tensorflow-sys/build.rs | sed 's|.*"\([^"]*\)";|\1|g'`
version_requirements=`grep "tensorflow\s*=" .github/workflows/requirements.txt | sed "s|.*== \(.*\)|\1|g"`
if [[ "${version_build_script}" != "${version_requirements}" ]]; then
echo "ERROR: TensorFlow version specified in build script does not match the one in the"
echo " GitHub requirements."
echo " tensorflow-sys/build.rs: ${version_build_script}"
echo " .github/workflows/requirements.txt: ${version_requirements}"
exit 1
fi

# Make sure the crate version matches the one in README.md.
version_tensorflow_crate=`grep "^version =" Cargo.toml | sed 's|.*= "\(.*\)"|\1|g'`
version_tensorflow_readme=`sed -En 's|tensorflow *= *"([^"]*)"|\1|p' < README.md`
version_tensorflow_readme2=`sed -En 's|tensorflow *= *\{ *version *= *"([^"]*)".*$|\1|p' < README.md`
if [[ "${version_tensorflow_crate}" != "${version_tensorflow_readme}" || \
"${version_tensorflow_crate}" != "${version_tensorflow_readme2}" ]]; then
echo "ERROR: tensorflow crate version does not match the ones in README.md."
echo " Cargo.toml: ${version_tensorflow_crate}"
echo " README.md: ${version_tensorflow_readme}"
echo " README.md: ${version_tensorflow_readme2}"
exit 1
fi

# Make sure the crate version matches the one in README.md for tensorflow-sys.
version_tensorflow_sys_crate=`grep "^version =" tensorflow-sys/Cargo.toml | sed 's|.*= "\(.*\)"|\1|g'`
version_tensorflow_sys_readme=`sed -En 's|tensorflow-sys *= *\{ *version *= *"([^"]*)".*$|\1|p' < tensorflow-sys/README.md`
if [[ "${version_tensorflow_sys_crate}" != "${version_tensorflow_sys_readme}" ]]; then
echo "ERROR: tensorflow-sys crate version does not match the one in README.md."
echo " Cargo.toml: ${version_tensorflow_sys_crate}"
echo " README.md: ${version_tensorflow_sys_readme}"
exit 1
fi

# Legacy Keras required for now because Keras 3 requires exporting models as
# Keras format, which the C API can't read:
# https://github.com/tensorflow/tensorflow/issues/70514
TF_USE_LEGACY_KERAS=1 run python3 examples/mobilenetv3/create_model.py
# TODO(#391): Re-enable: (cd test_resources/library && ./build-test-op)
run cargo fmt --all -- --check
run cargo test -vv -j 2
run cargo test -vv -j 2 --features eager
run cargo test -vv -j 2 --features tensorflow_unstable
run cargo test -vv -j 2 --features ndarray
run cargo run --example regression
run cargo run --example xor
run cargo run --features tensorflow_unstable --example expressions
run cargo run --features eager --example mobilenetv3
run cargo doc -vv --features experimental,tensorflow_unstable,ndarray,eager
run cargo doc -vv --features experimental,tensorflow_unstable,ndarray,eager,private-docs-rs
# TODO(#66): Re-enable: (cd tensorflow-sys && cargo test -vv -j 1)
(cd tensorflow-sys && run cargo run --example multiplication)
(cd tensorflow-sys && run cargo run --example tf_version)
(cd tensorflow-sys && run cargo doc -vv)

run cargo clippy
(cd tensorflow-sys && run cargo clippy)
(cd tensorflow-op-codegen && run cargo clippy)
(cd tensorflow-proto-codegen && run cargo clippy)
(cd tensorflow-internal-macros && run cargo clippy)
function version-check {
echo "Checking versions..."
# Make sure the Tensorflow version in the -sys build script matches the one in
# the run-valgrind script.
version_build_script=`grep "const VERSION" tensorflow-sys/build.rs | sed 's|.*"\([^"]*\)";|\1|g'`
version_requirements=`grep "tensorflow\s*=" .github/workflows/requirements.txt | sed "s|.*== \(.*\)|\1|g"`
if [[ "${version_build_script}" != "${version_requirements}" ]]; then
echo "ERROR: TensorFlow version specified in build script does not match the one in the"
echo " GitHub requirements."
echo " tensorflow-sys/build.rs: ${version_build_script}"
echo " .github/workflows/requirements.txt: ${version_requirements}"
exit 1
fi

for file in $(find . -name target -prune -o -name '*.rs' -print); do
bad_deprecations="$(rustfmt --emit stdout --config max_width=1000 "$file" | grep '#\[deprecated' | grep -E -v '([^"\\]|\\.|"([^"\\]|\\.)*")*since' || true)"
if [[ "${bad_deprecations}" != "" ]]; then
echo "ERROR: #[deprecated] attribute(s) found with no 'since' key in $file:"
echo "${bad_deprecations}"
# Make sure the crate version matches the one in README.md.
version_tensorflow_crate=`grep "^version =" Cargo.toml | sed 's|.*= "\(.*\)"|\1|g'`
version_tensorflow_readme=`sed -En 's|tensorflow *= *"([^"]*)"|\1|p' < README.md`
version_tensorflow_readme2=`sed -En 's|tensorflow *= *\{ *version *= *"([^"]*)".*$|\1|p' < README.md`
if [[ "${version_tensorflow_crate}" != "${version_tensorflow_readme}" || \
"${version_tensorflow_crate}" != "${version_tensorflow_readme2}" ]]; then
echo "ERROR: tensorflow crate version does not match the ones in README.md."
echo " Cargo.toml: ${version_tensorflow_crate}"
echo " README.md: ${version_tensorflow_readme}"
echo " README.md: ${version_tensorflow_readme2}"
exit 1
fi
bad_deprecations="$(rustfmt --emit stdout --config max_width=1000 "$file" | grep '#\[deprecated' | grep -E -v '([^"\\]|\\.|"([^"\\]|\\.)*")*note' || true)"
if [[ "${bad_deprecations}" != "" ]]; then
echo "ERROR: #[deprecated] attribute(s) found with no 'note' key in $file:"
echo "${bad_deprecations}"

# Make sure the crate version matches the one in README.md for tensorflow-sys.
version_tensorflow_sys_crate=`grep "^version =" tensorflow-sys/Cargo.toml | sed 's|.*= "\(.*\)"|\1|g'`
version_tensorflow_sys_readme=`sed -En 's|tensorflow-sys *= *\{ *version *= *"([^"]*)".*$|\1|p' < tensorflow-sys/README.md`
if [[ "${version_tensorflow_sys_crate}" != "${version_tensorflow_sys_readme}" ]]; then
echo "ERROR: tensorflow-sys crate version does not match the one in README.md."
echo " Cargo.toml: ${version_tensorflow_sys_crate}"
echo " README.md: ${version_tensorflow_sys_readme}"
exit 1
fi
done
}

function clippy-cmd {
echo "Running clippy..."
run cargo clippy
(cd tensorflow-sys && run cargo clippy)
(cd tensorflow-op-codegen && run cargo clippy)
(cd tensorflow-proto-codegen && run cargo clippy)
(cd tensorflow-internal-macros && run cargo clippy)
}

function fmt-cmd {
echo "Running cargo fmt..."
run cargo fmt --all -- --check
}

function test-cmd {
echo "Running tests..."
run cargo test -j 2
run cargo test -j 2 --features eager
run cargo test -j 2 --features tensorflow_unstable
run cargo test -j 2 --features ndarray
# TODO(#66): Re-enable: (cd tensorflow-sys && cargo test -j 1)
}

function example-cmd {
echo "Running examples..."
# Legacy Keras required for now because Keras 3 requires exporting models as
# Keras format, which the C API can't read:
# https://github.com/tensorflow/tensorflow/issues/70514
TF_USE_LEGACY_KERAS=1 run python3 examples/mobilenetv3/create_model.py
# TODO(#391): Re-enable: (cd test_resources/library && ./build-test-op)
run cargo run --example regression
run cargo run --example xor
run cargo run --features tensorflow_unstable --example expressions
run cargo run --features eager --example mobilenetv3
(cd tensorflow-sys && run cargo run --example multiplication)
(cd tensorflow-sys && run cargo run --example tf_version)
}

function doc-cmd {
echo "Building docs..."
run cargo doc --features experimental,tensorflow_unstable,ndarray,eager
run cargo doc --features experimental,tensorflow_unstable,ndarray,eager,private-docs-rs
(cd tensorflow-sys && run cargo doc)
}

function attributes-check {
echo "Checking #[deprecated] attributes..."
for file in $(find . -name target -prune -o -name '*.rs' -print); do
bad_deprecations="$(rustfmt --emit stdout --config max_width=1000 "$file" | grep '#\[deprecated' | grep -E -v '([^"\\]|\\.|"([^"\\]|\\.)*")*since' || true)"
if [[ "${bad_deprecations}" != "" ]]; then
echo "ERROR: #[deprecated] attribute(s) found with no 'since' key in $file:"
echo "${bad_deprecations}"
exit 1
fi
bad_deprecations="$(rustfmt --emit stdout --config max_width=1000 "$file" | grep '#\[deprecated' | grep -E -v '([^"\\]|\\.|"([^"\\]|\\.)*")*note' || true)"
if [[ "${bad_deprecations}" != "" ]]; then
echo "ERROR: #[deprecated] attribute(s) found with no 'note' key in $file:"
echo "${bad_deprecations}"
exit 1
fi
done
}

# check command line arguments and run the appropriate commands
if [[ $# -eq 0 ]]; then
version-check
clippy-cmd
fmt-cmd
test-cmd
example-cmd
doc-cmd
attributes-check
else
run "$@"
fi