diff --git a/.flake8 b/.flake8 deleted file mode 100644 index f338d003..00000000 --- a/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -# Recommend matching the black line length (default 88), -# rather than using the flake8 default of 79: -max-line-length = 88 -extend-ignore = - # See https://github.com/PyCQA/pycodestyle/issues/373 - E203, diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 835d4907..da82334f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -35,14 +35,6 @@ jobs: working-directory: ./chart-verifier run: make tidy - - name: Ensure Formatting - working-directory: ./chart-verifier - run: make fmt - - - name: Run Linters - working-directory: ./chart-verifier - run: make lint - - name: Build Binary working-directory: ./chart-verifier run: make bin @@ -71,15 +63,6 @@ jobs: cd scripts && ../ve1/bin/pip3 install -r requirements.txt && cd .. cd scripts && ../ve1/bin/python3 setup.py install && cd .. - - name: Run flake8 - working-directory: ./chart-verifier - run: | - python3 -m venv ve_flake8 - source ve_flake8/bin/activate - pip3 install flake8 - flake8 scripts/ - flake8 tests/ - - name: Check if only release file in PR working-directory: ./chart-verifier id: check_version_in_PR diff --git a/.github/workflows/golang-style.yml b/.github/workflows/golang-style.yml new file mode 100644 index 00000000..4c794773 --- /dev/null +++ b/.github/workflows/golang-style.yml @@ -0,0 +1,30 @@ +name: Golang Style + +on: + pull_request: + paths: + - '**.go' + +jobs: + enforce: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version-file: go.mod + + - name: Ensure Modules + run: make tidy + + - name: Ensure Formatting + run: make fmt + + - name: Run Linters + run: make lint + + - name: Build Binary + run: make bin \ No newline at end of file diff --git a/.github/workflows/python-style.yml b/.github/workflows/python-style.yml new file mode 100644 index 00000000..313dab5b --- /dev/null +++ b/.github/workflows/python-style.yml @@ -0,0 +1,31 @@ +name: Python Style + +on: + pull_request: + paths: + # Only trigger on changes to Python source. + - 'scripts/**.py' + - 'tests/**.py' + +jobs: + enforce: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python 3.x Part 1 + uses: actions/setup-python@v4 + with: + python-version: "3.9" + + - name: Install style tooling + run: make venv.codestyle + + - name: Run formatter + run: make py.ci.format + + # Temporarily auto-pass linting until we are able to manually review and + # address. + - name: Run linter + run: make py.lint \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3a5afb40..b8abf228 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,8 @@ Dockerfile.cross coverage.out # omit generated reports -report-info.* \ No newline at end of file +report-info.* + +# ignore python venvs +ve1/ +venv.*/ \ No newline at end of file diff --git a/Makefile b/Makefile index e01d4ddd..e48ff489 100644 --- a/Makefile +++ b/Makefile @@ -75,8 +75,63 @@ push-image: gosec: install.gosec $(GOSEC) -no-fail -fmt=sarif -out=gosec.sarif -exclude-dir tests ./... -### Developer Tooling Installation +### Python Specific Targets +PY_BIN ?= python3 + +# The virtualenv containing code style tools. +VENV_CODESTYLE = venv.codestyle +VENV_CODESTYLE_BIN = $(VENV_CODESTYLE)/bin + +# The virtualenv containing our CI scripts +VENV_TOOLS = venv.tools +VENV_TOOLS_BIN = $(VENV_TOOLS)/bin +# This is what we pass to git ls-files. +LS_FILES_INPUT_STR ?= 'scripts/src/*.py' 'tests/*.py' + +# The same as format, but will throw a non-zero exit code +# if the formatter had to make changes. +.PHONY: py.ci.format +py.ci.format: py.format + git diff --exit-code + +venv.codestyle: + $(MAKE) venv.codestyle.always-reinstall + +# This target will always install the codestyle venv. +# Useful for development cases. +.PHONY: venv.codestyle.always-reinstall +venv.codestyle.always-reinstall: + $(PY_BIN) -m venv $(VENV_CODESTYLE) + ./$(VENV_CODESTYLE_BIN)/pip install --upgrade \ + black \ + ruff + +.PHONY: py.format +py.format: venv.codestyle + ./$(VENV_CODESTYLE_BIN)/black \ + --verbose \ + $$(git ls-files $(LS_FILES_INPUT_STR)) + +.PHONY: py.lint +py.lint: venv.codestyle + ./$(VENV_CODESTYLE_BIN)/ruff \ + check \ + $$(git ls-files $(LS_FILES_INPUT_STR)) + +venv.tools: + $(MAKE) venv.tools.always-reinstall + +# This target will always install the tools at the venv. +# Useful for development cases. +.PHONY: venv.tools.always-reinstall +venv.tools.always-reinstall: + $(PY_BIN) -m venv $(VENV_TOOLS) + ./$(VENV_TOOLS_BIN)/pip install -r requirements.txt + ./$(VENV_TOOLS_BIN)/python setup.py install + + +### Developer Tooling Installation # gosec GOSEC = $(shell pwd)/out/gosec GOSEC_VERSION ?= latest @@ -101,4 +156,4 @@ define go-install-tool @[ -f $(1) ] || { \ GOBIN=$(PROJECT_DIR)/out go install $(2) ;\ } -endef +endef \ No newline at end of file diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..bc792923 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,3 @@ +ignore = [ + "E203" # https://github.com/PyCQA/pycodestyle/issues/373 +] \ No newline at end of file