From a6c0f31f05e5a68750a6f09d41b18da61a83106f Mon Sep 17 00:00:00 2001 From: Michael Huang Date: Sat, 19 Sep 2020 19:09:40 -0500 Subject: [PATCH] Set up code coverage (#38) * Setup code coverage * Update main.yml * Use codecov.yml, add badges and clean up scripts * Add pytest-cov to dev deps --- .codecov.yml | 26 +++++++++++ .github/workflows/main.yml | 33 +++++++++++++ Pipfile | 1 + Pipfile.lock | 96 ++++++++++++++++++++++++++++---------- README.md | 4 ++ scripts/bootstrap_dex.sh | 4 +- scripts/clean_up.sh | 2 +- scripts/run_coverage.sh | 19 ++++++++ 8 files changed, 158 insertions(+), 27 deletions(-) create mode 100644 .codecov.yml create mode 100755 scripts/run_coverage.sh diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..2abb256 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,26 @@ +codecov: + notify: + require_ci_to_pass: yes + +coverage: + precision: 2 + round: down + range: "70...100" + + status: + project: + default: + target: auto + threshold: 1.5% + patch: no + changes: no + +comment: + layout: "header, diff" + behavior: default + require_changes: no + +ignore: + - tests + - docs/conf.py + - setup.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a98491..b7c17b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,3 +43,36 @@ jobs: - name: Run unit tests run: | pipenv run pytest -v -m "not integration" + + coverage: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + + - name: Install pipenv + uses: dschep/install-pipenv-action@v1 + + - name: Generate coverage report + run: | + pipenv install --dev --skip-lock pytest pytest-cov + scripts/run_coverage.sh + + - name: Upload coverage to Codecov + # You may pin to the exact commit or the version. + # uses: codecov/codecov-action@6004246f47ab62d32be025ce173b241cd84ac58e + uses: codecov/codecov-action@v1.0.13 + with: + token: ${{ secrets.CODECOV_TOKEN }} + # Path to coverage file to upload + file: ./coverage.xml + env_vars: OS,PYTHON + # Specify whether or not CI build should fail if Codecov runs into an error during upload + fail_ci_if_error: true diff --git a/Pipfile b/Pipfile index b265ad9..9da0f6d 100644 --- a/Pipfile +++ b/Pipfile @@ -20,6 +20,7 @@ pydocstyle = "*" flake8 = "*" isort = "*" rope = "*" +pytest-cov = "*" [packages] solana = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 46b2f91..abe92f7 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6d7356bccd37ffd53f0feeb64a0ff0c123b00d5fcf2cac2b3e0aead5abc335ae" + "sha256": "bd38fc4b3f1d2f88a5043a76b2a8083910d4aecb3e13d72887d5b01daa06c85f" }, "pipfile-spec": 6, "requires": { @@ -96,24 +96,24 @@ }, "pynacl": { "hashes": [ - "sha256:7c6092102219f59ff29788860ccb021e80fffd953920c4a8653889c029b2d420", + "sha256:06cbb4d9b2c4bd3c8dc0d267416aaed79906e7b33f114ddbf0911969794b1cc4", "sha256:11335f09060af52c97137d4ac54285bcb7df0cef29014a1a4efe64ac065434c4", - "sha256:cd401ccbc2a249a47a3a1724c2918fcd04be1f7b54eb2a5a71ff915db0ac51c6", - "sha256:c914f78da4953b33d4685e3cdc7ce63401247a21425c16a39760e282075ac4a6", - "sha256:7757ae33dae81c300487591c68790dfb5145c7d03324000433d9a2c141f82af7", + "sha256:2fe0fc5a2480361dcaf4e6e7cea00e078fcda07ba45f811b167e3f99e8cff574", + "sha256:30f9b96db44e09b3304f9ea95079b1b7316b2b4f3744fe3aaecccd95d547063d", + "sha256:4e10569f8cbed81cb7526ae137049759d2a8d57726d52c1a000a3ce366779634", + "sha256:511d269ee845037b95c9781aa702f90ccc36036f95d0f31373a6a79bd8242e25", + "sha256:537a7ccbea22905a0ab36ea58577b39d1fa9b1884869d173b5cf111f006f689f", "sha256:54e9a2c849c742006516ad56a88f5c74bf2ce92c9f67435187c3c5953b346505", "sha256:757250ddb3bff1eecd7e41e65f7f833a8405fede0194319f87899690624f2122", - "sha256:06cbb4d9b2c4bd3c8dc0d267416aaed79906e7b33f114ddbf0911969794b1cc4", - "sha256:537a7ccbea22905a0ab36ea58577b39d1fa9b1884869d173b5cf111f006f689f", + "sha256:7757ae33dae81c300487591c68790dfb5145c7d03324000433d9a2c141f82af7", + "sha256:7c6092102219f59ff29788860ccb021e80fffd953920c4a8653889c029b2d420", + "sha256:8122ba5f2a2169ca5da936b2e5a511740ffb73979381b4229d9188f6dcb22f1f", + "sha256:9c4a7ea4fb81536c1b1f5cc44d54a296f96ae78c1ebd2311bd0b60be45a48d96", + "sha256:c914f78da4953b33d4685e3cdc7ce63401247a21425c16a39760e282075ac4a6", + "sha256:cd401ccbc2a249a47a3a1724c2918fcd04be1f7b54eb2a5a71ff915db0ac51c6", "sha256:d452a6746f0a7e11121e64625109bc4468fc3100452817001dbe018bb8b08514", "sha256:ea6841bc3a76fa4942ce00f3bda7d436fda21e2d91602b9e21b7ca9ecab8f3ff", - "sha256:9c4a7ea4fb81536c1b1f5cc44d54a296f96ae78c1ebd2311bd0b60be45a48d96", - "sha256:f8851ab9041756003119368c1e6cd0b9c631f46d686b3904b18c0139f4419f80", - "sha256:511d269ee845037b95c9781aa702f90ccc36036f95d0f31373a6a79bd8242e25", - "sha256:4e10569f8cbed81cb7526ae137049759d2a8d57726d52c1a000a3ce366779634", - "sha256:30f9b96db44e09b3304f9ea95079b1b7316b2b4f3744fe3aaecccd95d547063d", - "sha256:8122ba5f2a2169ca5da936b2e5a511740ffb73979381b4229d9188f6dcb22f1f", - "sha256:2fe0fc5a2480361dcaf4e6e7cea00e078fcda07ba45f811b167e3f99e8cff574" + "sha256:f8851ab9041756003119368c1e6cd0b9c631f46d686b3904b18c0139f4419f80" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.4.0" @@ -236,11 +236,11 @@ }, "bleach": { "hashes": [ - "sha256:769483204d247465c0b001ead257fb86bba6944bce6fe1b6759c812cceb54e3d", - "sha256:f9e0205cc57b558c21bdfc11034f9d96b14c4052c25be60885d94f4277c792e0" + "sha256:52b5919b81842b1854196eaae5ca29679a2f2e378905c346d3ca8227c2c66080", + "sha256:9f8ccbeb6183c6e6cddea37592dfb0167485c1e3b13b3363bc325aa8bda3adbd" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", - "version": "==3.2.0" + "version": "==3.2.1" }, "certifi": { "hashes": [ @@ -297,6 +297,46 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", "version": "==7.1.2" }, + "coverage": { + "hashes": [ + "sha256:0203acd33d2298e19b57451ebb0bed0ab0c602e5cf5a818591b4918b1f97d516", + "sha256:0f313707cdecd5cd3e217fc68c78a960b616604b559e9ea60cc16795c4304259", + "sha256:1c6703094c81fa55b816f5ae542c6ffc625fec769f22b053adb42ad712d086c9", + "sha256:1d44bb3a652fed01f1f2c10d5477956116e9b391320c94d36c6bf13b088a1097", + "sha256:280baa8ec489c4f542f8940f9c4c2181f0306a8ee1a54eceba071a449fb870a0", + "sha256:29a6272fec10623fcbe158fdf9abc7a5fa032048ac1d8631f14b50fbfc10d17f", + "sha256:2b31f46bf7b31e6aa690d4c7a3d51bb262438c6dcb0d528adde446531d0d3bb7", + "sha256:2d43af2be93ffbad25dd959899b5b809618a496926146ce98ee0b23683f8c51c", + "sha256:381ead10b9b9af5f64646cd27107fb27b614ee7040bb1226f9c07ba96625cbb5", + "sha256:47a11bdbd8ada9b7ee628596f9d97fbd3851bd9999d398e9436bd67376dbece7", + "sha256:4d6a42744139a7fa5b46a264874a781e8694bb32f1d76d8137b68138686f1729", + "sha256:50691e744714856f03a86df3e2bff847c2acede4c191f9a1da38f088df342978", + "sha256:530cc8aaf11cc2ac7430f3614b04645662ef20c348dce4167c22d99bec3480e9", + "sha256:582ddfbe712025448206a5bc45855d16c2e491c2dd102ee9a2841418ac1c629f", + "sha256:63808c30b41f3bbf65e29f7280bf793c79f54fb807057de7e5238ffc7cc4d7b9", + "sha256:71b69bd716698fa62cd97137d6f2fdf49f534decb23a2c6fc80813e8b7be6822", + "sha256:7858847f2d84bf6e64c7f66498e851c54de8ea06a6f96a32a1d192d846734418", + "sha256:78e93cc3571fd928a39c0b26767c986188a4118edc67bc0695bc7a284da22e82", + "sha256:7f43286f13d91a34fadf61ae252a51a130223c52bfefb50310d5b2deb062cf0f", + "sha256:86e9f8cd4b0cdd57b4ae71a9c186717daa4c5a99f3238a8723f416256e0b064d", + "sha256:8f264ba2701b8c9f815b272ad568d555ef98dfe1576802ab3149c3629a9f2221", + "sha256:9342dd70a1e151684727c9c91ea003b2fb33523bf19385d4554f7897ca0141d4", + "sha256:9361de40701666b034c59ad9e317bae95c973b9ff92513dd0eced11c6adf2e21", + "sha256:9669179786254a2e7e57f0ecf224e978471491d660aaca833f845b72a2df3709", + "sha256:aac1ba0a253e17889550ddb1b60a2063f7474155465577caa2a3b131224cfd54", + "sha256:aef72eae10b5e3116bac6957de1df4d75909fc76d1499a53fb6387434b6bcd8d", + "sha256:bd3166bb3b111e76a4f8e2980fa1addf2920a4ca9b2b8ca36a3bc3dedc618270", + "sha256:c1b78fb9700fc961f53386ad2fd86d87091e06ede5d118b8a50dea285a071c24", + "sha256:c3888a051226e676e383de03bf49eb633cd39fc829516e5334e69b8d81aae751", + "sha256:c5f17ad25d2c1286436761b462e22b5020d83316f8e8fcb5deb2b3151f8f1d3a", + "sha256:c851b35fc078389bc16b915a0a7c1d5923e12e2c5aeec58c52f4aa8085ac8237", + "sha256:cb7df71de0af56000115eafd000b867d1261f786b5eebd88a0ca6360cccfaca7", + "sha256:cedb2f9e1f990918ea061f28a0f0077a07702e3819602d3507e2ff98c8d20636", + "sha256:e8caf961e1b1a945db76f1b5fa9c91498d15f545ac0ababbe575cfab185d3bd8" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", + "version": "==5.3" + }, "decorator": { "hashes": [ "sha256:41fa54c2a0cc4ba648be4fd43cff00aedf5b9465c9bf18d64325bc225f08f760", @@ -723,11 +763,11 @@ }, "pygments": { "hashes": [ - "sha256:2594e8fdb06fef91552f86f4fd3a244d148ab24b66042036e64f29a291515048", - "sha256:2df50d16b45b977217e02cba6c8422aaddb859f3d0570a88e09b00eafae89c6e" + "sha256:307543fe65c0947b126e83dd5a61bd8acbd84abec11f43caebaf5534cbc17998", + "sha256:926c3f319eda178d1bd90851e4317e6d8cdb5e292a3386aac9bd75eca29cf9c7" ], "markers": "python_version >= '3.5'", - "version": "==2.7.0" + "version": "==2.7.1" }, "pylint": { "hashes": [ @@ -760,6 +800,14 @@ "index": "pypi", "version": "==6.0.2" }, + "pytest-cov": { + "hashes": [ + "sha256:45ec2d5182f89a81fc3eb29e3d1ed3113b9e9a873bcddb2a71faaab066110191", + "sha256:47bd0ce14056fdd79f93e1713f88fad7bdcc583dcd7783da86ef2f085a0bb88e" + ], + "index": "pypi", + "version": "==2.10.1" + }, "pytest-tornasync": { "hashes": [ "sha256:4b165b6ba76b5b228933598f456b71ba233f127991a52889788db0a950ad04ba", @@ -875,11 +923,11 @@ }, "terminado": { "hashes": [ - "sha256:4804a774f802306a7d9af7322193c5390f1da0abb429e082a10ef1d46e6fb2c2", - "sha256:a43dcb3e353bc680dd0783b1d9c3fc28d529f190bc54ba9a229f72fe6e7a54d7" + "sha256:7ceea4c1644b0e95588d1d2ba09c5bf365b318c26d0a13ef6a5f2751a2f6efa3", + "sha256:e0eaea25d978d9a8d557f63ef23b0ec81a2f9e22b9dabfe5db4a79d8d38dd7c2" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.8.3" + "markers": "python_version >= '3.6'", + "version": "==0.9.0" }, "testpath": { "hashes": [ diff --git a/README.md b/README.md index 059f2e5..005b080 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +[![Actions +Status](https://github.com/serum-community/pyserum/workflows/CI/badge.svg)](https://github.com/serum-community/pyserum/actions?query=workflow%3ACI) +[![Codecov](https://codecov.io/gh/serum-community/pyserum/branch/alpha/graph/badge.svg)](https://codecov.io/gh/serum-community/pyserum/branches/alpha) + # PySerum Python client library for interacting with the [Project Serum](https://projectserum.com/) DEX. diff --git a/scripts/bootstrap_dex.sh b/scripts/bootstrap_dex.sh index 051006c..6ecf13d 100755 --- a/scripts/bootstrap_dex.sh +++ b/scripts/bootstrap_dex.sh @@ -15,10 +15,10 @@ fi docker-compose up -d if ! hash solana 2>/dev/null; then - echo Installing Solana tool suite... + echo Installing Solana tool suite ... curl -sSf https://raw.githubusercontent.com/solana-labs/solana/v1.3.9/install/solana-install-init.sh | sh -s - v1.3.9 export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH" - echo Generating keypair... + echo Generating keypair ... solana-keygen new -o ~/.config/solana/id.json --no-passphrase --silent fi solana config set --url "http://localhost:8899" diff --git a/scripts/clean_up.sh b/scripts/clean_up.sh index a79ab33..4bdfb28 100644 --- a/scripts/clean_up.sh +++ b/scripts/clean_up.sh @@ -1,7 +1,7 @@ #!/bin/bash if [[ $KEEP_ARTIFACTS == "" ]]; then - echo Deleting artifacts... + echo Deleting artifacts ... rm -rf tests/crank.log crank serum_dex.so fi docker-compose down diff --git a/scripts/run_coverage.sh b/scripts/run_coverage.sh new file mode 100755 index 0000000..b7b9d71 --- /dev/null +++ b/scripts/run_coverage.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +bash scripts/bootstrap_dex.sh + +wait_time=20 +echo "Waiting $wait_time seconds to make sure the market has started" +sleep $wait_time + + + +exit_code=1 +if (pipenv run pytest --cov=./ --cov-report=xml); then + echo "The script ran ok" + exit_code=0 +fi + +bash scripts/clean_up.sh + +exit $exit_code