Skip to content

Commit f77b908

Browse files
Cp 19161 ensure we have good testing on new validator code (#36)
* CP-19161 add file changed check to makefile * CP-19161 simplify file changed check to makefile * even simpler * CP-19161 add simple workflow to run python checks * test purposely break build to test pipeline * revert change after pipeline validation * change matrix for current versions * reduce test matrix to match dockerfile only python 3.12
1 parent d20a0d5 commit f77b908

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

.github/workflows/test-python.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: test_python
2+
on:
3+
push:
4+
pull_request:
5+
6+
env:
7+
# build docker images to the (host) local registry
8+
REGISTRY_LOCAL_ADDR: localhost:5000
9+
# k8x requires the kind container address alias (comes from the kind-action)
10+
REGISTRY_TEST_ADDR: kind-registry:5000
11+
# If we are on develop or main, use the production repository
12+
REGISTRY_PROD_ADDR: ghcr.io
13+
# image name should be prefixed with the repository name
14+
IMAGE_NAME: ${{ github.repository }}/cloudzero-agent-validator
15+
16+
jobs:
17+
# This job detects if there are any changes to allow condition testing in other jobs
18+
has_changes:
19+
uses: ./.github/workflows/change-detector.yml
20+
21+
test_python:
22+
runs-on: ubuntu-latest
23+
needs: has_changes
24+
permissions:
25+
contents: read
26+
strategy:
27+
matrix:
28+
python-version: ["3.12"]
29+
steps:
30+
- name: SETUP - Checkout
31+
if: needs.has_changes.outputs.any_changed == 'true'
32+
uses: actions/checkout@v4
33+
34+
- name: SETUP - Python ${{ matrix.python-version }}
35+
if: needs.has_changes.outputs.any_changed == 'true'
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: ${{ matrix.python-version }}
39+
40+
- name: SETUP - Display Python version
41+
if: needs.has_changes.outputs.any_changed == 'true'
42+
run: |
43+
python -c "import sys; print(sys.version)"
44+
45+
- name: TEST - Run checks
46+
run: |
47+
cd charts/cloudzero-agent
48+
make check

charts/cloudzero-agent/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ clean: ## Clean up dangling Docker images
8282
fmt: init-dev ## runs code formatter
8383
@$(PYTHON_ARGS) black $(SRC_DIR)/*.py $(TEST_DIR)/*.py
8484

85+
.PHONY: fmt-check
86+
fmt-check: fmt ## Check if the code is properly formatted
87+
$(eval CHANGED := $(shell git status -s | grep "\.py" | wc -c))
88+
@[ $(CHANGED) -eq 0 ] || { echo "changed files"; exit 1; }
89+
8590
.PHONY: lint
8691
lint: init-dev ## runs code linter
8792
@$(PYTHON_ARGS) ruff check $(SRC_DIR) $(TEST_DIR)
8893

8994
.PHONY: check
90-
check: lint test ## Run code linter and unit tests
95+
check: fmt-check lint test ## Run code linter and unit tests
9196

9297
.PHONY: test
9398
test: check-python-version init-dev ## Run unit tests

0 commit comments

Comments
 (0)