Skip to content

Commit

Permalink
Partition out Golang and Python linting and style tasks (#412)
Browse files Browse the repository at this point in the history
Signed-off-by: Jose R. Gonzalez <[email protected]>
  • Loading branch information
komish authored Nov 2, 2023
1 parent a3f4bb2 commit 934aef5
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 27 deletions.
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/golang-style.yml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions .github/workflows/python-style.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ Dockerfile.cross
coverage.out

# omit generated reports
report-info.*
report-info.*

# ignore python venvs
ve1/
venv.*/
59 changes: 57 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -101,4 +156,4 @@ define go-install-tool
@[ -f $(1) ] || { \
GOBIN=$(PROJECT_DIR)/out go install $(2) ;\
}
endef
endef
3 changes: 3 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore = [
"E203" # https://github.com/PyCQA/pycodestyle/issues/373
]

0 comments on commit 934aef5

Please sign in to comment.