Skip to content

Commit fe422c4

Browse files
authored
refactor: Improve code formatting (#283)
1 parent fe61ad5 commit fe422c4

File tree

25 files changed

+237
-75
lines changed

25 files changed

+237
-75
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
HELM_VERSION: v3.15.2
11+
PGO_VERSION: 5.7.4
12+
13+
jobs:
14+
validate:
15+
name: Lint checks
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Install uv
25+
run: |
26+
curl -LsSf https://astral.sh/uv/install.sh | sh
27+
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
28+
29+
- name: Install Helm
30+
uses: azure/setup-helm@v3
31+
with:
32+
version: ${{ env.HELM_VERSION }}
33+
34+
- name: Run linters
35+
run: |
36+
export PATH="$HOME/.cargo/bin:$PATH"
37+
make lint

.github/workflows/helm-tests.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches: [ "main" ]
66
pull_request:
77
branches: [ "main" ]
8-
types: [ opened, reopened, synchronize, labeled ]
98

109
env:
1110
HELM_VERSION: v3.15.2
@@ -46,10 +45,7 @@ jobs:
4645
docker-enabled: true
4746

4847
- name: Set release name
49-
run: |
50-
SHORT_SHA="${{ github.sha }}"
51-
SHORT_SHA="${SHORT_SHA::8}"
52-
echo "RELEASE_NAME=eoapi-$SHORT_SHA" >> "$GITHUB_ENV"
48+
run: echo "RELEASE_NAME=eoapi-$(echo "${{ github.sha }}" | cut -c1-8)" >> "$GITHUB_ENV"
5349

5450
- name: Deploy eoAPI
5551
id: deploy
@@ -112,6 +108,10 @@ jobs:
112108
echo "===== Relevant ConfigMaps ====="
113109
kubectl get configmaps | grep -E "initdb|pgstac" || echo "No relevant configmaps found"
114110
111+
# Check for any related events
112+
echo "===== Related Kubernetes Events ====="
113+
kubectl get events | grep -E "pgstac|initdb" || echo "No relevant events found"
114+
115115
exit 1
116116
117117
- name: Run integration tests
@@ -126,14 +126,10 @@ jobs:
126126
run: |
127127
echo "=== Final Deployment Status ==="
128128
kubectl get pods -o wide
129-
kubectl get services
129+
kubectl get jobs -o wide
130+
kubectl get services -o wide
130131
kubectl get ingress
131132
132-
- name: Debug on failure
133-
if: failure()
134-
run: |
135-
echo "=== Additional failure debugging (integration script provides comprehensive debugging) ==="
136-
kubectl get events --sort-by='.lastTimestamp' | tail -20 || true
137133
138134
- name: Cleanup
139135
if: always()

.github/workflows/pr.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: PR Checks
32
on:
43
pull_request:

.github/workflows/stac-browser.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ jobs:
3232

3333
- name: Set environment variables
3434
run: |
35-
echo VERSION=${TAG_NAME#v} >> $GITHUB_ENV
36-
echo IMAGE_NAME=$REGISTRY/$(echo ${GITHUB_REPOSITORY,,})/stac-browser >> $GITHUB_ENV
37-
echo COMMITED_AT=$(git show -s --format=%cI `git rev-parse HEAD`) >> $GITHUB_ENV
38-
echo REVISION=$(git rev-parse --short HEAD) >> $GITHUB_ENV
35+
{
36+
echo "VERSION=${TAG_NAME#v}"
37+
echo "IMAGE_NAME=$REGISTRY/${GITHUB_REPOSITORY,,}/stac-browser"
38+
echo "COMMITED_AT=$(git show -s --format=%cI "$(git rev-parse HEAD)")"
39+
echo "REVISION=$(git rev-parse --short HEAD)"
40+
} >> "$GITHUB_ENV"
3941
4042
- name: Collect Docker image metadata
4143
id: meta

.github/workflows/tests/test_stac.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def test_stac_custom_path(stac_endpoint):
7474
"""test stac with custom ingress path."""
7575
# If we're using a custom path (e.g., /api instead of /stac)
7676
base_path = stac_endpoint.split("://")[1]
77-
77+
7878
# Landing page
7979
resp = client.get(stac_endpoint)
8080
assert resp.status_code == 200
8181
landing = resp.json()
82-
82+
8383
# All links should use the custom path
8484
for link in landing["links"]:
8585
if link["href"].startswith("/"):
@@ -90,7 +90,7 @@ def test_stac_custom_path(stac_endpoint):
9090
resp = client.get(f"{stac_endpoint}/collections")
9191
assert resp.status_code == 200
9292
collections = resp.json()["collections"]
93-
93+
9494
for collection in collections:
9595
for link in collection["links"]:
9696
if link["href"].startswith("/"):
@@ -101,7 +101,7 @@ def test_stac_custom_path(stac_endpoint):
101101
resp = client.get(f"{stac_endpoint}/collections/noaa-emergency-response/items")
102102
assert resp.status_code == 200
103103
items = resp.json()
104-
104+
105105
# Item links should also use the custom path
106106
for feature in items["features"]:
107107
for link in feature["links"]:

.pre-commit-config.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Pre-commit configuration for eoAPI Kubernetes charts
2+
# Fast, essential checks only - heavy validation moved to CI
3+
4+
repos:
5+
# Basic file formatting and validation
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v6.0.0
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-yaml
12+
args: ['--allow-multiple-documents']
13+
exclude: ^charts/.+/templates/
14+
- id: check-added-large-files
15+
16+
# YAML linting
17+
- repo: https://github.com/adrienverge/yamllint
18+
rev: v1.37.1
19+
hooks:
20+
- id: yamllint
21+
files: \.(yaml|yml)$
22+
exclude: ^charts/.+/templates/
23+
24+
# Shell script validation
25+
- repo: https://github.com/shellcheck-py/shellcheck-py
26+
rev: v0.11.0.1
27+
hooks:
28+
- id: shellcheck
29+
args: ['-e', 'SC1091']
30+
31+
# GitHub Actions linting
32+
- repo: https://github.com/rhysd/actionlint
33+
rev: v1.7.7
34+
hooks:
35+
- id: actionlint
36+
37+
# Fast Helm syntax check only
38+
- repo: local
39+
hooks:
40+
- id: helm-lint-syntax
41+
name: Helm Syntax Check
42+
entry: >
43+
bash -c 'for chart in charts/*/; do
44+
if [ -f "$chart/Chart.yaml" ]; then
45+
if grep -q "dependencies:" "$chart/Chart.yaml" 2>/dev/null; then
46+
if [ -d "$chart/charts" ] && [ -n "$(find "$chart/charts" -name "*.tgz" 2>/dev/null)" ]; then
47+
echo "Linting $chart (dependencies available)...";
48+
helm lint "$chart" --strict || exit 1;
49+
else echo "Skipping $chart (dependencies not built - run make deploy or scripts/helm-setup.sh first)";
50+
fi; else echo "Linting $chart (no dependencies)...";
51+
helm lint "$chart" --strict || exit 1; fi; fi; done'
52+
language: system
53+
files: ^charts/.+\.(yaml|yml)$
54+
pass_filenames: false
55+
56+
# Exclude directories
57+
exclude: |
58+
(?x)^(
59+
\.git/.*|
60+
charts/.+/charts/.*|
61+
charts/.+/tmpcharts.*/.*
62+
)$

.yamllint.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# yamllint configuration for Kubernetes/Helm YAML files
2+
# See https://yamllint.readthedocs.io/en/stable/configuration.html
3+
4+
extends: default
5+
6+
rules:
7+
# Allow longer lines for Kubernetes manifests (image names, URLs, etc.)
8+
line-length:
9+
max: 180
10+
level: warning
11+
12+
# Allow multiple documents in single files (common in K8s)
13+
document-start: disable
14+
15+
# Relax indentation rules - K8s manifests can have complex nesting
16+
indentation:
17+
spaces: consistent
18+
indent-sequences: consistent
19+
check-multi-line-strings: false
20+
21+
# Allow empty values (common in Helm templates)
22+
empty-values:
23+
forbid-in-block-mappings: false
24+
forbid-in-flow-mappings: false
25+
26+
# Allow truthy values like "yes", "no", "on", "off" (common in K8s)
27+
truthy:
28+
allowed-values: ['true', 'false', 'yes', 'no', 'on', 'off']
29+
check-keys: false
30+
31+
# Be more lenient with comments
32+
comments:
33+
min-spaces-from-content: 1
34+
require-starting-space: true
35+
36+
# Allow quoted strings (often necessary for Helm templating)
37+
quoted-strings:
38+
quote-type: any
39+
required: false
40+
41+
# Allow brackets for flow sequences/mappings
42+
brackets:
43+
min-spaces-inside: 0
44+
max-spaces-inside: 1
45+
46+
# Allow braces for flow mappings
47+
braces:
48+
min-spaces-inside: 0
49+
max-spaces-inside: 1
50+
51+
# Ignore certain files/patterns
52+
ignore: |
53+
charts/*/charts/
54+
charts/*/tmpcharts/
55+
charts/*/templates/
56+
.github/workflows/tests/

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Enforcement of `CHANGELOG.md` entries for PRs and Conventional Commits for PR titles [#288](https://github.com/developmentseed/eoapi-k8s/pull/288)
13+
- Added code formatting and linting with pre-commit hooks [#283](https://github.com/developmentseed/eoapi-k8s/pull/283)
1314

1415
## [0.7.8] - 2025-09-10
1516

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ HELM_REPO_URL=https://devseed.com/eoapi-k8s/
55
HELM_CHART_NAME=eoapi/eoapi
66
PGO_CHART_VERSION=5.7.4
77

8-
.PHONY: all deploy minikube ingest test-integration tests help
8+
.PHONY: all deploy minikube ingest tests integration lint help
99

1010
# Default target
1111
all: deploy
@@ -41,11 +41,21 @@ integration:
4141
@command -v bash >/dev/null 2>&1 || { echo "bash is required but not installed"; exit 1; }
4242
@./scripts/test.sh integration
4343

44+
lint:
45+
@echo "Running linting and code quality checks..."
46+
@if [ ! -f .git/hooks/pre-commit ]; then \
47+
echo "Installing pre-commit..."; \
48+
uv pip install pre-commit yamllint shellcheck-py || pip3 install --user pre-commit yamllint shellcheck-py; \
49+
pre-commit install; \
50+
fi
51+
@pre-commit run --all-files
52+
4453
help:
4554
@echo "Makefile commands:"
4655
@echo " make deploy - Deploy eoAPI to the configured Kubernetes cluster."
4756
@echo " make minikube - Install eoAPI on minikube."
4857
@echo " make ingest - Ingest STAC collections and items into the database."
4958
@echo " make integration - Run integration tests on connected Kubernetes cluster."
5059
@echo " make tests - Run lint + unit tests."
60+
@echo " make lint - Run linting and code quality checks."
5161
@echo " make help - Show this help message."

charts/eoapi-support/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
observability, monitoring and some custom metrics for autoscaling
44

5-
(please see documentation about `helm install` and configuration at ../../docs/autoscaling.md)
5+
(please see documentation about `helm install` and configuration at ../../docs/autoscaling.md)

0 commit comments

Comments
 (0)