From f06704453f7ccd4aedc727cc48c9664d18887154 Mon Sep 17 00:00:00 2001 From: grapebaba <281165273@qq.com> Date: Sun, 6 Aug 2023 10:51:48 +0800 Subject: [PATCH] feat:add dev check Signed-off-by: grapebaba <281165273@qq.com> --- .github/workflows/build.yml | 27 +++++++++++++++++++ .gitignore | 2 ++ Makefile | 7 +++++ README.md | 12 ++++++++- makefile | 0 roll.py | 8 +++--- ruff.toml | 1 + scripts/install.sh | 53 +++++++++++++++++++++++++++++++++++++ 8 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 Makefile delete mode 100644 makefile create mode 100644 ruff.toml create mode 100755 scripts/install.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..672f037 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,27 @@ +name: Build the project + +on: + push: + branches: [ "master" ] + pull_request: + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + source scripts/install.sh + - name: Check with ruff + run: | + make check diff --git a/.gitignore b/.gitignore index b6c549e..da8623f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /optimism /__pycache__ /.idea +/venv +/.ruff_cache \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ed7bde1 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ + +linter: ## Run linter + @ruff check . +.PHONY: linter + +check: linter ## Run check +.PHONY: check \ No newline at end of file diff --git a/README.md b/README.md index 5bec46d..b3756c0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ you can automatically subsidize gas for transactions that match certain criteria ## Prerequisites -- Python 3 (to run the `roll.py` script) +- Python >= 3.10 (to run the `roll.py` script) The following dependencies will be checked by `roll.py`: @@ -34,6 +34,16 @@ always for your permission before installing anything outside the current direct - Node.js 16.x - Yarn (`npm install -g yarn` — the old one, not yarn v3 aka yarn berry) +## Contributing + +```bash +# Install dependencies +source scripts/install.sh + +# Run checks +make check +``` + ## Plans - See [here](https://app.charmverse.io/op-grants/proposals?id=a6e6bfb8-75bd-41bd-acb1-618c3c62e667) diff --git a/makefile b/makefile deleted file mode 100644 index e69de29..0000000 diff --git a/roll.py b/roll.py index 796407b..f650b83 100755 --- a/roll.py +++ b/roll.py @@ -127,7 +127,7 @@ def nvm_install_node(): # We have NVM, try using required version or installing it. try: lib.run(f"use node {NODE_VNAME}", f"source ~/.nvm/nvm.sh; nvm use {NODE_VERSION}") - except Exception as err: + except Exception: if lib.ask_yes_no(f"Node {NODE_VNAME} ({NODE_VERSION}) is required. NVM is installed. " f"Install with NVM?"): nvm_install_node() @@ -172,9 +172,11 @@ def setup_optimism_repo(): print("Starting to build the optimism repository. This may take a while...\n") # TODO screen position moves, so this only clears one screen worth of output - if args.use_ansi_esc: lib.term_save_cursor() + if args.use_ansi_esc: + lib.term_save_cursor() run_with_node("build optimism", "make build", cwd="optimism", forward_output=True) - if args.use_ansi_esc: lib.term_clear_from_saved() + if args.use_ansi_esc: + lib.term_clear_from_saved() # TODO tee the outputs to a log file print("Successfully built the optimism repository.") diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..309e4ce --- /dev/null +++ b/ruff.toml @@ -0,0 +1 @@ +line-length = 110 \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..2fc5a37 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# Description: This script is used to setup the development environment for the project. + + +check_python_version() { + # Check python version if greater or equal than 3.10, otherwise exit + python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') + if python3 -c "import sys; sys.exit(not (sys.version_info >= (3, 10)))"; then + echo "Python version is $python_version" + else + echo "Python version is $python_version, but 3.10 or greater is required" + exit 1 + fi +} + +activate_venv() { + # Check if venv directory exists, otherwise create it. Then activate venv + if [ -d "venv" ]; then + echo "venv directory exists" + else + echo "venv directory does not exist, creating it now" + python3 -m venv venv + fi + echo "activating venv" + source ./venv/bin/activate +} + +install_dev_dependencies() { + # Install development dependencies + echo "installing development dependencies" + # Check if pip3 version is greater or equal than 21.2.4, otherwise upgrade it + pip3_version=$(pip3 --version | awk '{print $2}') + if python3 -c "import sys; sys.exit(not (sys.version_info >= (21, 2, 4)))"; then + echo "pip3 version is $pip3_version" + else + echo "pip3 version is $pip3_version, but 21.2.4 or greater is required" + pip3 install --upgrade pip + fi + # Check if ruff is installed, otherwise install it + if ! command -v ruff &> /dev/null + then + echo "ruff could not be found, installing it now" + pip3 install ruff + else + echo "ruff is installed" + fi +} + +check_python_version +activate_venv +install_dev_dependencies +