From aa56693445cc749b20e4d9342a3a1deb3aea63b7 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 14:43:49 +0300 Subject: [PATCH 01/33] test bazel --- .github/workflows/ci.yml | 12 +++---- WORKSPACE.bazel | 18 +++++++++++ app/BUILD.bazel | 15 +++++++++ app/codecov_wrapper.sh | 13 ++++++++ app/test_calculator.py | 70 ++++++++++++++++++++++------------------ 5 files changed, 91 insertions(+), 37 deletions(-) create mode 100644 WORKSPACE.bazel create mode 100644 app/BUILD.bazel create mode 100644 app/codecov_wrapper.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06b266f5..7e33e4cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,15 +4,15 @@ jobs: run: runs-on: ubuntu-latest steps: + - uses: bazelbuild/setup-bazelisk@v2 - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python 3.10 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.10' - name: Install dependencies run: pip install -r requirements.txt - - name: Run tests and collect coverage - run: pytest --cov app - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + - name: run tests by bazel and generate coverage + run: bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator + diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 00000000..e41b88a6 --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1,18 @@ +#https://github.com/bazelbuild/rules_python - for using py rules +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "rules_python", + sha256 = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841", + strip_prefix = "rules_python-0.23.1", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.23.1/rules_python-0.23.1.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") + +py_repositories() + +python_register_toolchains( + name = "python39", + python_version = "3.9", + register_coverage_tool = True, +) \ No newline at end of file diff --git a/app/BUILD.bazel b/app/BUILD.bazel new file mode 100644 index 00000000..c8b025ab --- /dev/null +++ b/app/BUILD.bazel @@ -0,0 +1,15 @@ +py_library( + name="calculator", + srcs=["calculator.py"], + +) + +py_test( + name="test_calculator", + srcs=["test_calculator.py"], + deps = [ + "//app:calculator", + ] +) + +exports_files(["codecov_wrapper.sh"]) diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh new file mode 100644 index 00000000..1ceec13d --- /dev/null +++ b/app/codecov_wrapper.sh @@ -0,0 +1,13 @@ +#/bin/bash + +# `bazel coverage --run_under foo :bar` basically translates to: +# foo pytest --cov bar/src/a.py bar/src/b.py +# We want to run that `pytest` command unmodified, as below: +"$@" +pyenv virtualenv codecov-env +pyenv activate codecov-env +pip install codecov-cli +# Now we want to run `codecovcli` +# CODECOV_TOKEN= codecovcli create-commit +# CODECOV_TOKEN= codecovcli create-report +# CODECOV_TOKEN= codecovcli do-upload diff --git a/app/test_calculator.py b/app/test_calculator.py index 8b61b6b3..a040f2b8 100644 --- a/app/test_calculator.py +++ b/app/test_calculator.py @@ -1,32 +1,40 @@ -from .calculator import Calculator - - -def test_add(): - assert 1 == 1 - -# def test_subtract(): -# assert Calculator.subtract(1, 2) == -1.0 -# assert Calculator.subtract(2, 1) == 1.0 -# assert Calculator.subtract(1.0, 2.0) == -1.0 -# assert Calculator.subtract(0, 2.0) == -2.0 -# assert Calculator.subtract(2.0, 0.0) == 2.0 -# assert Calculator.subtract(-4, 2.0) == -6.0 - -# def test_multiply(): -# assert Calculator.multiply(1, 2) == 2.0 -# assert Calculator.multiply(1.0, 2.0) == 2.0 -# assert Calculator.multiply(0, 2.0) == 0.0 -# assert Calculator.multiply(2.0, 0.0) == 0.0 -# assert Calculator.multiply(-4, 2.0) == -8.0 - -def test_trivial(): - assert True - -# def test_divide(): -# # assert Calculator.divide(1, 2) == 0.5 -# assert Calculator.divide(1.0, 2.0) == 0.5 -# assert Calculator.divide(0, 2.0) == 0 -# assert Calculator.divide(-4, 2.0) == -2.0 -# # assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0' - +from app.calculator import Calculator + +import unittest + + + +class TestMethods(unittest.TestCase): + def test_add(self): + self.assertEqual(True, True) + + def test_add(self): + self.assertEqual(Calculator.add(1, 2), 3.0) + self.assertEqual(Calculator.add(1.0, 2.0), 3.0) + self.assertEqual(Calculator.add(0, 2.0), 2.0) + self.assertEqual(Calculator.add(2.0, 0), 2.0) + self.assertEqual(Calculator.add(-4, 2.0), -2.0) + + def test_subtract(self): + self.assertEqual(Calculator.subtract(1, 2) , -1.0) + self.assertEqual(Calculator.subtract(2, 1) , 1.0) + self.assertEqual(Calculator.subtract(1.0, 2.0) , -1.0) + self.assertEqual(Calculator.subtract(0, 2.0) , -2.0) + self.assertEqual(Calculator.subtract(2.0, 0.0) , 2.0) + self.assertEqual(Calculator.subtract(-4, 2.0) , -6.0) + + def test_multiply(self): + self.assertEqual(Calculator.multiply(1, 2) , 2.0) + self.assertEqual(Calculator.multiply(1.0, 2.0) , 2.0) + self.assertEqual(Calculator.multiply(0, 2.0) , 0.0) + self.assertEqual(Calculator.multiply(2.0, 0.0) , 0.0) + self.assertEqual(Calculator.multiply(-4, 2.0) , -8.0) + + def test_divide(self): + self.assertEqual(Calculator.divide(1.0, 2.0) , 0.5) + self.assertEqual(Calculator.divide(0, 2.0) , 0) + self.assertEqual(Calculator.divide(-4, 2.0) , -2.0) + +if __name__ == "__main__": + unittest.main() From e2b46c3438734d6c76f175e535932dc1e42873ac Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 14:47:15 +0300 Subject: [PATCH 02/33] logging output --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e33e4cd..af60dddc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,5 +14,5 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - name: run tests by bazel and generate coverage - run: bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator + run: bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From e1c428957e3b716fe78454d6865e585e96a07e66 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 14:49:58 +0300 Subject: [PATCH 03/33] fix --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af60dddc..6220b672 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: python-version: '3.10' - name: Install dependencies run: pip install -r requirements.txt + - name: give wrapper permission + run: chmod +x codecov_wrapper.sh - name: run tests by bazel and generate coverage run: bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From 7685963a74fed5a5ba5a8a8af7ce4d615357e9e2 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 14:51:51 +0300 Subject: [PATCH 04/33] fix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6220b672..18fc7990 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - name: give wrapper permission - run: chmod +x codecov_wrapper.sh + run: chmod +x app/codecov_wrapper.sh - name: run tests by bazel and generate coverage run: bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From 53ce3a362560ff1502e420fa71e5e97601b11df2 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:00:36 +0300 Subject: [PATCH 05/33] fix --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18fc7990..9eb0c612 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,5 +16,8 @@ jobs: - name: give wrapper permission run: chmod +x app/codecov_wrapper.sh - name: run tests by bazel and generate coverage - run: bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all + run: + virtualenv venv | + . venv/bin/activate && python -m pip install --upgrade pip | + bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From 0ab88cbcaa234f05cf19038f17b3b2475c0ff393 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:02:23 +0300 Subject: [PATCH 06/33] fix --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9eb0c612..52df3b9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,8 @@ jobs: - name: give wrapper permission run: chmod +x app/codecov_wrapper.sh - name: run tests by bazel and generate coverage - run: - virtualenv venv | - . venv/bin/activate && python -m pip install --upgrade pip | + run: | + virtualenv venv + . venv/bin/activate && python -m pip install --upgrade pip bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From f66064421bef9286692a88012f252f67b6e3094d Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:03:30 +0300 Subject: [PATCH 07/33] fix --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52df3b9f..7bc6c31d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: run: chmod +x app/codecov_wrapper.sh - name: run tests by bazel and generate coverage run: | - virtualenv venv - . venv/bin/activate && python -m pip install --upgrade pip - bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all + virtualenv venv + . venv/bin/activate && python -m pip install --upgrade pip + bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From b118cdc86c64615d8d3f8179531d255adf53e725 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:09:21 +0300 Subject: [PATCH 08/33] fix --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bc6c31d..d9e6e18a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: run: chmod +x app/codecov_wrapper.sh - name: run tests by bazel and generate coverage run: | - virtualenv venv - . venv/bin/activate && python -m pip install --upgrade pip + virtualenv venv + . venv/bin/activate && python -m pip install --upgrade pip bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From 639e78327a5399733b343e07907c667694a187e5 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:11:17 +0300 Subject: [PATCH 09/33] fix --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9e6e18a..b4b9fcff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,6 @@ jobs: run: chmod +x app/codecov_wrapper.sh - name: run tests by bazel and generate coverage run: | - virtualenv venv - . venv/bin/activate && python -m pip install --upgrade pip + python -m pip install --upgrade pip bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From 441870751d0acf170d0ba6bbb51d5f9446bf9503 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:21:58 +0300 Subject: [PATCH 10/33] fix --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4b9fcff..a31da192 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,8 @@ jobs: - name: run tests by bazel and generate coverage run: | python -m pip install --upgrade pip + pip install virtualenv + virtualenv venv + source venv/bin/activate bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all From f012b6259e7fc71c737a5520e099ab5bf2d51d32 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:35:01 +0300 Subject: [PATCH 11/33] fix --- app/codecov_wrapper.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh index 1ceec13d..3da80357 100644 --- a/app/codecov_wrapper.sh +++ b/app/codecov_wrapper.sh @@ -4,8 +4,6 @@ # foo pytest --cov bar/src/a.py bar/src/b.py # We want to run that `pytest` command unmodified, as below: "$@" -pyenv virtualenv codecov-env -pyenv activate codecov-env pip install codecov-cli # Now we want to run `codecovcli` # CODECOV_TOKEN= codecovcli create-commit From f3fee7678b3588602a52e7051e503c271f8e022c Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:37:34 +0300 Subject: [PATCH 12/33] fix --- app/codecov_wrapper.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh index 3da80357..567b8579 100644 --- a/app/codecov_wrapper.sh +++ b/app/codecov_wrapper.sh @@ -4,6 +4,7 @@ # foo pytest --cov bar/src/a.py bar/src/b.py # We want to run that `pytest` command unmodified, as below: "$@" +source venv/bin/activate pip install codecov-cli # Now we want to run `codecovcli` # CODECOV_TOKEN= codecovcli create-commit From f153a699e98a410ff46bb1ef021624a163fb5148 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 20 Jul 2023 15:40:30 +0300 Subject: [PATCH 13/33] fix --- .github/workflows/ci.yml | 1 + app/codecov_wrapper.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a31da192..fbe70e08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,5 +21,6 @@ jobs: pip install virtualenv virtualenv venv source venv/bin/activate + pip install codecov-cli bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh index 567b8579..a2862a85 100644 --- a/app/codecov_wrapper.sh +++ b/app/codecov_wrapper.sh @@ -4,8 +4,8 @@ # foo pytest --cov bar/src/a.py bar/src/b.py # We want to run that `pytest` command unmodified, as below: "$@" -source venv/bin/activate -pip install codecov-cli +codecovcli create-commit + # Now we want to run `codecovcli` # CODECOV_TOKEN= codecovcli create-commit # CODECOV_TOKEN= codecovcli create-report From b60befb641d8a45be7e4bb951313eef5a4ef6e8b Mon Sep 17 00:00:00 2001 From: Dana Date: Sun, 23 Jul 2023 17:24:18 +0300 Subject: [PATCH 14/33] test out new fixes --- .github/workflows/ci.yml | 2 +- app/codecov_wrapper.sh | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) mode change 100644 => 100755 app/codecov_wrapper.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbe70e08..5c3a7e72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,5 +22,5 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - bazel coverage --run_under //app:codecov_wrapper.sh //app:test_calculator --test_output=all + bazel coverage --run_under //app:codecov_wrapper.sh --test_output=all --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) --combined_report=lcov //app:test_calculator diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh old mode 100644 new mode 100755 index a2862a85..01b5b2ad --- a/app/codecov_wrapper.sh +++ b/app/codecov_wrapper.sh @@ -4,9 +4,17 @@ # foo pytest --cov bar/src/a.py bar/src/b.py # We want to run that `pytest` command unmodified, as below: "$@" -codecovcli create-commit +#COVERAGE_DIR="$CURR_DIR/bazel-out/_coverage" +# Now you can use $COVERAGE_DIR to access the coverage report files +# For example, if you want to print the coverage report path: +echo "Coverage report path: $COVERAGE_DIR" +# Assuming you are in the root of your workspace +mv $COVERAGE_DIR/pylcov.dat $COVERAGE_DIR/lcov.dat + +# Get the root of the Git repository +GIT_DIR="$GIT_DIR" +codecovcli -v --url http://localhost:8000 create-commit -t dc93f68d-1a9e-4c37-a184-8ec34cd335a2 +codecovcli -v --url http://localhost:8000 create-report -t dc93f68d-1a9e-4c37-a184-8ec34cd335a2 +codecovcli -v --url http://localhost:8000 do-upload -t dc93f68d-1a9e-4c37-a184-8ec34cd335a2 --plugin gcov --plugin pycoverage -s $COVERAGE_DIR + -# Now we want to run `codecovcli` -# CODECOV_TOKEN= codecovcli create-commit -# CODECOV_TOKEN= codecovcli create-report -# CODECOV_TOKEN= codecovcli do-upload From 04aeb41e71b3b60a08ad7a8651863bb30ba2cb8e Mon Sep 17 00:00:00 2001 From: Dana Date: Sun, 23 Jul 2023 17:30:24 +0300 Subject: [PATCH 15/33] test out new fixes --- app/codecov_wrapper.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh index 01b5b2ad..658b298a 100755 --- a/app/codecov_wrapper.sh +++ b/app/codecov_wrapper.sh @@ -13,8 +13,8 @@ mv $COVERAGE_DIR/pylcov.dat $COVERAGE_DIR/lcov.dat # Get the root of the Git repository GIT_DIR="$GIT_DIR" -codecovcli -v --url http://localhost:8000 create-commit -t dc93f68d-1a9e-4c37-a184-8ec34cd335a2 -codecovcli -v --url http://localhost:8000 create-report -t dc93f68d-1a9e-4c37-a184-8ec34cd335a2 -codecovcli -v --url http://localhost:8000 do-upload -t dc93f68d-1a9e-4c37-a184-8ec34cd335a2 --plugin gcov --plugin pycoverage -s $COVERAGE_DIR +codecovcli -v create-commit -t 02d15256-c911-4a8e-a642-1685b111da77 +codecovcli -v create-report -t 02d15256-c911-4a8e-a642-1685b111da77 +codecovcli -v do-upload -t 02d15256-c911-4a8e-a642-1685b111da77 --plugin gcov --plugin pycoverage -s $COVERAGE_DIR From a5c27188f1c474fcdfdb7c7cdcd198486514f952 Mon Sep 17 00:00:00 2001 From: Dana Date: Mon, 24 Jul 2023 13:38:29 +0300 Subject: [PATCH 16/33] hide token --- .github/workflows/ci.yml | 2 +- app/codecov_wrapper.sh | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c3a7e72..b428eadb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,5 +22,5 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - bazel coverage --run_under //app:codecov_wrapper.sh --test_output=all --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) --combined_report=lcov //app:test_calculator + bazel coverage --run_under //app:codecov_wrapper.sh --test_output=all --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) --action_env=CODECOV_TOKEN=${{ CODECOV_TOKEN }} --combined_report=lcov //app:test_calculator diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh index 658b298a..b6efb7b4 100755 --- a/app/codecov_wrapper.sh +++ b/app/codecov_wrapper.sh @@ -4,17 +4,13 @@ # foo pytest --cov bar/src/a.py bar/src/b.py # We want to run that `pytest` command unmodified, as below: "$@" -#COVERAGE_DIR="$CURR_DIR/bazel-out/_coverage" -# Now you can use $COVERAGE_DIR to access the coverage report files -# For example, if you want to print the coverage report path: -echo "Coverage report path: $COVERAGE_DIR" -# Assuming you are in the root of your workspace + +# codecov doesn't recognise pylcov.dat as a coverage report, renaming it to lcov.dat so codecov can acknowledge it mv $COVERAGE_DIR/pylcov.dat $COVERAGE_DIR/lcov.dat -# Get the root of the Git repository -GIT_DIR="$GIT_DIR" -codecovcli -v create-commit -t 02d15256-c911-4a8e-a642-1685b111da77 -codecovcli -v create-report -t 02d15256-c911-4a8e-a642-1685b111da77 -codecovcli -v do-upload -t 02d15256-c911-4a8e-a642-1685b111da77 --plugin gcov --plugin pycoverage -s $COVERAGE_DIR +# uploading coverage +codecovcli -v --url http://localhost:8000 create-commit -t $CODECOV_TOKEN +codecovcli -v --url http://localhost:8000 create-report -t $CODECOV_TOKEN +codecovcli -v --url http://localhost:8000 do-upload -t $CODECOV_TOKEN -s $COVERAGE_DIR From aeafa67e789136e22653cae17af7ece7ac061607 Mon Sep 17 00:00:00 2001 From: Dana Date: Mon, 24 Jul 2023 13:43:48 +0300 Subject: [PATCH 17/33] hide token --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b428eadb..2f2afc9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,5 +22,5 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - bazel coverage --run_under //app:codecov_wrapper.sh --test_output=all --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) --action_env=CODECOV_TOKEN=${{ CODECOV_TOKEN }} --combined_report=lcov //app:test_calculator + bazel coverage --run_under //app:codecov_wrapper.sh --test_output=all --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} --combined_report=lcov //app:test_calculator From f6d66c6f695fd35aabdaf32f0e32257bc0f91c2f Mon Sep 17 00:00:00 2001 From: Dana Date: Mon, 24 Jul 2023 13:46:30 +0300 Subject: [PATCH 18/33] hide token --- .github/workflows/ci.yml | 6 +++++- app/codecov_wrapper.sh | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f2afc9c..df8f2732 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,5 +22,9 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - bazel coverage --run_under //app:codecov_wrapper.sh --test_output=all --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} --combined_report=lcov //app:test_calculator + bazel coverage --run_under //app:codecov_wrapper.sh \ + --test_output=all \ + --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ + --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ + --combined_report=lcov //app:test_calculator diff --git a/app/codecov_wrapper.sh b/app/codecov_wrapper.sh index b6efb7b4..6129daf0 100755 --- a/app/codecov_wrapper.sh +++ b/app/codecov_wrapper.sh @@ -9,8 +9,8 @@ mv $COVERAGE_DIR/pylcov.dat $COVERAGE_DIR/lcov.dat # uploading coverage -codecovcli -v --url http://localhost:8000 create-commit -t $CODECOV_TOKEN -codecovcli -v --url http://localhost:8000 create-report -t $CODECOV_TOKEN -codecovcli -v --url http://localhost:8000 do-upload -t $CODECOV_TOKEN -s $COVERAGE_DIR +codecovcli -v create-commit -t $CODECOV_TOKEN +codecovcli -v create-report -t $CODECOV_TOKEN +codecovcli -v do-upload -t $CODECOV_TOKEN -s $COVERAGE_DIR From 111adc3ff3012c1c7d6f98dade519482f2391b64 Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 26 Jul 2023 12:43:10 +0300 Subject: [PATCH 19/33] create two projects --- app/{ => projectA}/BUILD.bazel | 2 +- app/{ => projectA}/calculator.py | 0 app/{ => projectA}/codecov_wrapper.sh | 0 app/{ => projectA}/test_calculator.py | 2 +- app/projectB/BUILD.bazel | 15 +++++++++++++++ app/projectB/adder.py | 3 +++ app/projectB/codecov_wrapper.sh | 16 ++++++++++++++++ app/projectB/test_adder.py | 9 +++++++++ 8 files changed, 45 insertions(+), 2 deletions(-) rename app/{ => projectA}/BUILD.bazel (84%) rename app/{ => projectA}/calculator.py (100%) rename app/{ => projectA}/codecov_wrapper.sh (100%) rename app/{ => projectA}/test_calculator.py (96%) create mode 100644 app/projectB/BUILD.bazel create mode 100644 app/projectB/adder.py create mode 100755 app/projectB/codecov_wrapper.sh create mode 100644 app/projectB/test_adder.py diff --git a/app/BUILD.bazel b/app/projectA/BUILD.bazel similarity index 84% rename from app/BUILD.bazel rename to app/projectA/BUILD.bazel index c8b025ab..2bba0201 100644 --- a/app/BUILD.bazel +++ b/app/projectA/BUILD.bazel @@ -8,7 +8,7 @@ py_test( name="test_calculator", srcs=["test_calculator.py"], deps = [ - "//app:calculator", + "//app/projectA:calculator", ] ) diff --git a/app/calculator.py b/app/projectA/calculator.py similarity index 100% rename from app/calculator.py rename to app/projectA/calculator.py diff --git a/app/codecov_wrapper.sh b/app/projectA/codecov_wrapper.sh similarity index 100% rename from app/codecov_wrapper.sh rename to app/projectA/codecov_wrapper.sh diff --git a/app/test_calculator.py b/app/projectA/test_calculator.py similarity index 96% rename from app/test_calculator.py rename to app/projectA/test_calculator.py index a040f2b8..be2c1611 100644 --- a/app/test_calculator.py +++ b/app/projectA/test_calculator.py @@ -1,5 +1,5 @@ -from app.calculator import Calculator +from app.projectA.calculator import Calculator import unittest diff --git a/app/projectB/BUILD.bazel b/app/projectB/BUILD.bazel new file mode 100644 index 00000000..3c65aa33 --- /dev/null +++ b/app/projectB/BUILD.bazel @@ -0,0 +1,15 @@ +py_library( + name="adder", + srcs=["adder.py"], + +) + +py_test( + name="test_adder", + srcs=["test_adder.py"], + deps = [ + "//app/projectB:adder", + ] +) + +exports_files(["codecov_wrapper.sh"]) diff --git a/app/projectB/adder.py b/app/projectB/adder.py new file mode 100644 index 00000000..57f0dc95 --- /dev/null +++ b/app/projectB/adder.py @@ -0,0 +1,3 @@ +class Adder: + def add(self, x, y): + return x + y \ No newline at end of file diff --git a/app/projectB/codecov_wrapper.sh b/app/projectB/codecov_wrapper.sh new file mode 100755 index 00000000..6129daf0 --- /dev/null +++ b/app/projectB/codecov_wrapper.sh @@ -0,0 +1,16 @@ +#/bin/bash + +# `bazel coverage --run_under foo :bar` basically translates to: +# foo pytest --cov bar/src/a.py bar/src/b.py +# We want to run that `pytest` command unmodified, as below: +"$@" + +# codecov doesn't recognise pylcov.dat as a coverage report, renaming it to lcov.dat so codecov can acknowledge it +mv $COVERAGE_DIR/pylcov.dat $COVERAGE_DIR/lcov.dat + +# uploading coverage +codecovcli -v create-commit -t $CODECOV_TOKEN +codecovcli -v create-report -t $CODECOV_TOKEN +codecovcli -v do-upload -t $CODECOV_TOKEN -s $COVERAGE_DIR + + diff --git a/app/projectB/test_adder.py b/app/projectB/test_adder.py new file mode 100644 index 00000000..bb327e22 --- /dev/null +++ b/app/projectB/test_adder.py @@ -0,0 +1,9 @@ +import unittest + +from app.projectB.adder import Adder + + + +class TestAdder(unittest.TestCase): + def test_adder(self, x, y): + assert x + y == Adder.add(x, y) \ No newline at end of file From cce184340ee7deb404e17af70d9f0dd916f3c2f7 Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 26 Jul 2023 12:45:57 +0300 Subject: [PATCH 20/33] fixing paths --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df8f2732..9400c259 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - name: give wrapper permission - run: chmod +x app/codecov_wrapper.sh + run: chmod +x app/projectA/codecov_wrapper.sh - name: run tests by bazel and generate coverage run: | python -m pip install --upgrade pip @@ -22,9 +22,9 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - bazel coverage --run_under //app:codecov_wrapper.sh \ + bazel coverage --run_under //app/projectA:codecov_wrapper.sh \ --test_output=all \ --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ - --combined_report=lcov //app:test_calculator + --combined_report=lcov //app/... From e6c160713289a6fad3b77f048a9d958e73b6b005 Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 26 Jul 2023 12:52:06 +0300 Subject: [PATCH 21/33] run adder tests --- app/projectB/test_adder.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/projectB/test_adder.py b/app/projectB/test_adder.py index bb327e22..8254f139 100644 --- a/app/projectB/test_adder.py +++ b/app/projectB/test_adder.py @@ -3,7 +3,9 @@ from app.projectB.adder import Adder - class TestAdder(unittest.TestCase): def test_adder(self, x, y): - assert x + y == Adder.add(x, y) \ No newline at end of file + assert x + y == Adder.add(x, y) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From a94d303684be4b49d83abd8d52cc04bcbf0446d4 Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 26 Jul 2023 12:59:54 +0300 Subject: [PATCH 22/33] fix adder tests --- app/projectB/test_adder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/projectB/test_adder.py b/app/projectB/test_adder.py index 8254f139..ebbc7273 100644 --- a/app/projectB/test_adder.py +++ b/app/projectB/test_adder.py @@ -4,8 +4,8 @@ class TestAdder(unittest.TestCase): - def test_adder(self, x, y): - assert x + y == Adder.add(x, y) + def test_adder(self): + assert 2 + 3 == Adder().add(2, 3) if __name__ == "__main__": unittest.main() \ No newline at end of file From 3fb7ed01dce9cc7ea14c7f13576849227b633950 Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 26 Jul 2023 13:58:08 +0300 Subject: [PATCH 23/33] using remote cache --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9400c259..766bd970 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,8 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - bazel coverage --run_under //app/projectA:codecov_wrapper.sh \ + bazel coverage --remote_cache=${{ secrets.NGROK_LINK }} \ + --run_under //app/projectA:codecov_wrapper.sh \ --test_output=all \ --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ From f7041fd5adfecde9efc67f72c42d36d85fafb91e Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 26 Jul 2023 14:52:23 +0300 Subject: [PATCH 24/33] do not upload to codecov from the cli --- .github/workflows/ci.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 766bd970..819b8b49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,10 +22,5 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - bazel coverage --remote_cache=${{ secrets.NGROK_LINK }} \ - --run_under //app/projectA:codecov_wrapper.sh \ - --test_output=all \ - --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ - --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ - --combined_report=lcov //app/... + From 8fc3f7a65b1c3dcde310dc2ec7d1cc16938da17d Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 26 Jul 2023 14:58:20 +0300 Subject: [PATCH 25/33] run projectB tests only --- app/projectB/test_adder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/projectB/test_adder.py b/app/projectB/test_adder.py index ebbc7273..6aea25c9 100644 --- a/app/projectB/test_adder.py +++ b/app/projectB/test_adder.py @@ -5,7 +5,7 @@ class TestAdder(unittest.TestCase): def test_adder(self): - assert 2 + 3 == Adder().add(2, 3) + assert 2 + 3.0 == Adder().add(2, 3) if __name__ == "__main__": unittest.main() \ No newline at end of file From c19d09c18db14cf4fdb6a4e8c6845c67bd570701 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 27 Jul 2023 18:27:25 +0300 Subject: [PATCH 26/33] gcp --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 819b8b49..4c348733 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,5 +22,11 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - + bazel coverage --remote_cache=https://storage.googleapis.com/bazel-test-dana \ + --google_credentials={{secrets.GCP_CREDENTIALS}} + --run_under //app/projectA:codecov_wrapper.sh \ + --test_output=all \ + --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ + --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ + --combined_report=lcov //app/... From f57933a47c1ecfb63c27d73a8560cca6fe9c4a5e Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 27 Jul 2023 18:29:32 +0300 Subject: [PATCH 27/33] missing $ --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c348733..ae3d96b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: source venv/bin/activate pip install codecov-cli bazel coverage --remote_cache=https://storage.googleapis.com/bazel-test-dana \ - --google_credentials={{secrets.GCP_CREDENTIALS}} + --google_credentials=${{secrets.GCP_CREDENTIALS}} --run_under //app/projectA:codecov_wrapper.sh \ --test_output=all \ --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ From 375f3c9909871918ce0c901f805f622db4511cc7 Mon Sep 17 00:00:00 2001 From: Dana Date: Fri, 28 Jul 2023 10:19:05 +0300 Subject: [PATCH 28/33] config gcs --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae3d96b5..9f7cedde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,8 +22,9 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli + echo ${{secrets.GCP_CREDENTIALS}} > service.json bazel coverage --remote_cache=https://storage.googleapis.com/bazel-test-dana \ - --google_credentials=${{secrets.GCP_CREDENTIALS}} + --google_credentials=service.json --run_under //app/projectA:codecov_wrapper.sh \ --test_output=all \ --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ From 85b77c241d7af6d05abd13d08bcc068859d00319 Mon Sep 17 00:00:00 2001 From: Dana Date: Fri, 28 Jul 2023 10:25:49 +0300 Subject: [PATCH 29/33] config gcs --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f7cedde..37756620 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: virtualenv venv source venv/bin/activate pip install codecov-cli - echo ${{secrets.GCP_CREDENTIALS}} > service.json + echo "$GCP_CREDENTIALS" > service.json bazel coverage --remote_cache=https://storage.googleapis.com/bazel-test-dana \ --google_credentials=service.json --run_under //app/projectA:codecov_wrapper.sh \ @@ -30,4 +30,5 @@ jobs: --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ --combined_report=lcov //app/... - + env: + GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} From 81270f89634c23e4bb01e38f90c157219e0e4a19 Mon Sep 17 00:00:00 2001 From: Dana Date: Fri, 28 Jul 2023 10:33:44 +0300 Subject: [PATCH 30/33] config gcs --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37756620..ad14e3e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,8 @@ jobs: source venv/bin/activate pip install codecov-cli echo "$GCP_CREDENTIALS" > service.json + echo "-----" + bazel build //app/... bazel coverage --remote_cache=https://storage.googleapis.com/bazel-test-dana \ --google_credentials=service.json --run_under //app/projectA:codecov_wrapper.sh \ From 69c01cafb06ba398473c1c87a67d8cd1e4f7662e Mon Sep 17 00:00:00 2001 From: Dana Date: Fri, 28 Jul 2023 10:39:55 +0300 Subject: [PATCH 31/33] config gcs --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad14e3e9..e83cbe61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,7 @@ jobs: echo "$GCP_CREDENTIALS" > service.json echo "-----" bazel build //app/... - bazel coverage --remote_cache=https://storage.googleapis.com/bazel-test-dana \ - --google_credentials=service.json + bazel coverage --run_under //app/projectA:codecov_wrapper.sh \ --test_output=all \ --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ From 8b3cc7c7f56bce6c64eeb43801b626a7c047c6b5 Mon Sep 17 00:00:00 2001 From: Dana Date: Fri, 28 Jul 2023 10:44:44 +0300 Subject: [PATCH 32/33] change cov command --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e83cbe61..d1d42a5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,7 @@ jobs: echo "$GCP_CREDENTIALS" > service.json echo "-----" bazel build //app/... - bazel coverage - --run_under //app/projectA:codecov_wrapper.sh \ + bazel coverage --run_under //app/projectA:codecov_wrapper.sh \ --test_output=all \ --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ From 14c0ed8d0be906b34fff95bc6084929b356d65ad Mon Sep 17 00:00:00 2001 From: Dana Date: Fri, 28 Jul 2023 10:47:02 +0300 Subject: [PATCH 33/33] add gcp creds --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1d42a5c..9e20a923 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,8 @@ jobs: --test_output=all \ --action_env=GIT_DIR=${PWD}/$(git rev-parse --git-dir) \ --action_env=CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \ + --remote_cache=https://storage.googleapis.com/bazel-test-dana \ + --google_credentials=service.json \ --combined_report=lcov //app/... env: GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}