Spaces:
Running
Running
Melika Kheirieh
commited on
Commit
·
7f99e2c
1
Parent(s):
3dcdaae
chore(ci): refactor Makefile and CI to unify quality checks via make check
Browse files- .github/workflows/ci.yml +51 -32
- Makefile +27 -11
.github/workflows/ci.yml
CHANGED
|
@@ -15,44 +15,59 @@ jobs:
|
|
| 15 |
permissions:
|
| 16 |
contents: read
|
| 17 |
env:
|
|
|
|
| 18 |
PROXY_API_KEY: ${{ secrets.PROXY_API_KEY }}
|
| 19 |
PROXY_BASE_URL: ${{ secrets.PROXY_BASE_URL }}
|
|
|
|
|
|
|
| 20 |
|
| 21 |
steps:
|
| 22 |
-
- name: Checkout
|
| 23 |
uses: actions/checkout@v4
|
| 24 |
|
| 25 |
- name: Set up Python
|
| 26 |
uses: actions/setup-python@v5
|
| 27 |
with:
|
| 28 |
python-version: "3.12"
|
| 29 |
-
cache:
|
| 30 |
cache-dependency-path: |
|
| 31 |
requirements.txt
|
| 32 |
|
| 33 |
-
- name: Upgrade pip tooling
|
| 34 |
-
run: python -m pip install --upgrade pip setuptools wheel
|
| 35 |
-
|
| 36 |
- name: Install dependencies
|
| 37 |
run: |
|
| 38 |
-
|
| 39 |
-
pip install -r requirements-dev.txt
|
| 40 |
-
else
|
| 41 |
pip install -r requirements.txt
|
| 42 |
-
|
| 43 |
-
fi
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
- name:
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
- name:
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
- name:
|
| 55 |
-
run:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
docker-build:
|
| 58 |
needs: build-test
|
|
@@ -67,30 +82,34 @@ jobs:
|
|
| 67 |
IMAGE_NAME: nl2sql-copilot
|
| 68 |
|
| 69 |
steps:
|
| 70 |
-
-
|
| 71 |
-
uses: actions/checkout@v4
|
| 72 |
|
| 73 |
-
- name:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
uses: docker/login-action@v3
|
| 75 |
with:
|
| 76 |
registry: ${{ env.REGISTRY }}
|
| 77 |
username: ${{ github.actor }}
|
| 78 |
password: ${{ secrets.GITHUB_TOKEN }}
|
| 79 |
|
| 80 |
-
- name: Compute image refs
|
| 81 |
run: |
|
| 82 |
OWNER_LC=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
|
| 83 |
echo "OWNER_LC=$OWNER_LC" >> $GITHUB_ENV
|
| 84 |
echo "IMAGE=${{ env.REGISTRY }}/${OWNER_LC}/${{ env.IMAGE_NAME }}:${{ github.sha }}" >> $GITHUB_ENV
|
| 85 |
echo "LATEST=${{ env.REGISTRY }}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_ENV
|
| 86 |
|
| 87 |
-
- name: Build
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
docker push "$LATEST"
|
|
|
|
| 15 |
permissions:
|
| 16 |
contents: read
|
| 17 |
env:
|
| 18 |
+
# App env (if your tests need them)
|
| 19 |
PROXY_API_KEY: ${{ secrets.PROXY_API_KEY }}
|
| 20 |
PROXY_BASE_URL: ${{ secrets.PROXY_BASE_URL }}
|
| 21 |
+
# Ensure imports work when running `pytest` via Makefile
|
| 22 |
+
PYTHONPATH: ${{ github.workspace }}
|
| 23 |
|
| 24 |
steps:
|
| 25 |
+
- name: Checkout
|
| 26 |
uses: actions/checkout@v4
|
| 27 |
|
| 28 |
- name: Set up Python
|
| 29 |
uses: actions/setup-python@v5
|
| 30 |
with:
|
| 31 |
python-version: "3.12"
|
| 32 |
+
cache: pip
|
| 33 |
cache-dependency-path: |
|
| 34 |
requirements.txt
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
- name: Install dependencies
|
| 37 |
run: |
|
| 38 |
+
python -m pip install -U pip wheel
|
|
|
|
|
|
|
| 39 |
pip install -r requirements.txt
|
| 40 |
+
pip install ruff mypy pytest pytest-cov
|
|
|
|
| 41 |
|
| 42 |
+
# Optional caches for tool state (speed up CI on subsequent runs)
|
| 43 |
+
- name: Cache Ruff
|
| 44 |
+
uses: actions/cache@v4
|
| 45 |
+
with:
|
| 46 |
+
path: .ruff_cache
|
| 47 |
+
key: ruff-${{ runner.os }}-${{ hashFiles('**/*.py', 'pyproject.toml', 'ruff.toml', '.pre-commit-config.yaml') }}
|
| 48 |
|
| 49 |
+
- name: Cache Mypy
|
| 50 |
+
uses: actions/cache@v4
|
| 51 |
+
with:
|
| 52 |
+
path: .mypy_cache
|
| 53 |
+
key: mypy-${{ runner.os }}-${{ hashFiles('**/*.py', 'mypy.ini', 'pyproject.toml') }}
|
| 54 |
|
| 55 |
+
- name: Cache Pytest
|
| 56 |
+
uses: actions/cache@v4
|
| 57 |
+
with:
|
| 58 |
+
path: .pytest_cache
|
| 59 |
+
key: pytest-${{ runner.os }}-${{ hashFiles('**/*.py', 'pyproject.toml') }}
|
| 60 |
|
| 61 |
+
- name: Quality gate (format check, lint, typecheck, tests)
|
| 62 |
+
run: make check
|
| 63 |
+
|
| 64 |
+
- name: Upload coverage (optional)
|
| 65 |
+
if: always()
|
| 66 |
+
uses: actions/upload-artifact@v4
|
| 67 |
+
with:
|
| 68 |
+
name: coverage-report
|
| 69 |
+
path: ./.coverage
|
| 70 |
+
if-no-files-found: ignore
|
| 71 |
|
| 72 |
docker-build:
|
| 73 |
needs: build-test
|
|
|
|
| 82 |
IMAGE_NAME: nl2sql-copilot
|
| 83 |
|
| 84 |
steps:
|
| 85 |
+
- uses: actions/checkout@v4
|
|
|
|
| 86 |
|
| 87 |
+
- name: Set up QEMU
|
| 88 |
+
uses: docker/setup-qemu-action@v3
|
| 89 |
+
|
| 90 |
+
- name: Set up Docker Buildx
|
| 91 |
+
uses: docker/setup-buildx-action@v3
|
| 92 |
+
|
| 93 |
+
- name: Login to GHCR
|
| 94 |
uses: docker/login-action@v3
|
| 95 |
with:
|
| 96 |
registry: ${{ env.REGISTRY }}
|
| 97 |
username: ${{ github.actor }}
|
| 98 |
password: ${{ secrets.GITHUB_TOKEN }}
|
| 99 |
|
| 100 |
+
- name: Compute image refs
|
| 101 |
run: |
|
| 102 |
OWNER_LC=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
|
| 103 |
echo "OWNER_LC=$OWNER_LC" >> $GITHUB_ENV
|
| 104 |
echo "IMAGE=${{ env.REGISTRY }}/${OWNER_LC}/${{ env.IMAGE_NAME }}:${{ github.sha }}" >> $GITHUB_ENV
|
| 105 |
echo "LATEST=${{ env.REGISTRY }}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_ENV
|
| 106 |
|
| 107 |
+
- name: Build and push (with cache)
|
| 108 |
+
uses: docker/build-push-action@v6
|
| 109 |
+
with:
|
| 110 |
+
push: true
|
| 111 |
+
tags: |
|
| 112 |
+
${{ env.IMAGE }}
|
| 113 |
+
${{ env.LATEST }}
|
| 114 |
+
cache-from: type=gha
|
| 115 |
+
cache-to: type=gha,mode=max
|
|
|
Makefile
CHANGED
|
@@ -31,35 +31,51 @@ install: ## Install runtime dependencies inside venv
|
|
| 31 |
.PHONY: dev-install
|
| 32 |
dev-install: ## Install dev tools (ruff, mypy, pytest, coverage, uvicorn, etc.)
|
| 33 |
$(PIP) install -U pip wheel
|
| 34 |
-
$(PIP) install ruff mypy pytest pytest-cov uvicorn
|
| 35 |
|
| 36 |
.PHONY: bootstrap
|
| 37 |
bootstrap: venv dev-install ## Create venv and install dev tools
|
| 38 |
|
| 39 |
-
# ---------- Quality ----------
|
| 40 |
-
.PHONY:
|
| 41 |
-
|
| 42 |
-
$(RUFF) format .
|
| 43 |
-
$(RUFF) check . --fix
|
| 44 |
|
| 45 |
.PHONY: lint
|
| 46 |
-
lint: ## Run linting
|
| 47 |
$(RUFF) check .
|
| 48 |
-
$(MYPY) .
|
| 49 |
|
| 50 |
.PHONY: typecheck
|
| 51 |
typecheck: ## Run type checking only
|
| 52 |
-
$(MYPY) .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# ---------- Tests ----------
|
| 55 |
.PHONY: test
|
| 56 |
-
test: ## Run
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
PYTHONPATH=$$PWD $(PYTEST) -q
|
| 58 |
|
| 59 |
.PHONY: cov
|
| 60 |
cov: ## Run tests with coverage
|
| 61 |
PYTHONPATH=$$PWD $(PYTEST) --cov=nl2sql --cov-report=term-missing
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# ---------- Pre-commit ----------
|
| 64 |
.PHONY: precommit
|
| 65 |
precommit: ## Run all pre-commit hooks on all files
|
|
@@ -87,7 +103,7 @@ docker-run: ## Run Docker container on port $(PORT)
|
|
| 87 |
# ---------- Clean ----------
|
| 88 |
.PHONY: clean
|
| 89 |
clean: ## Remove Python caches
|
| 90 |
-
rm -rf __pycache__ .pytest_cache .mypy_cache
|
| 91 |
|
| 92 |
.PHONY: clean-all
|
| 93 |
clean-all: clean ## Remove build artifacts and coverage
|
|
|
|
| 31 |
.PHONY: dev-install
|
| 32 |
dev-install: ## Install dev tools (ruff, mypy, pytest, coverage, uvicorn, etc.)
|
| 33 |
$(PIP) install -U pip wheel
|
| 34 |
+
$(PIP) install ruff mypy pytest pytest-cov uvicorn pre-commit
|
| 35 |
|
| 36 |
.PHONY: bootstrap
|
| 37 |
bootstrap: venv dev-install ## Create venv and install dev tools
|
| 38 |
|
| 39 |
+
# ---------- Quality (read-only for CI) ----------
|
| 40 |
+
.PHONY: fmt-check
|
| 41 |
+
fmt-check: ## Verify formatting without modifying files
|
| 42 |
+
$(RUFF) format . --check
|
|
|
|
| 43 |
|
| 44 |
.PHONY: lint
|
| 45 |
+
lint: ## Run linting
|
| 46 |
$(RUFF) check .
|
|
|
|
| 47 |
|
| 48 |
.PHONY: typecheck
|
| 49 |
typecheck: ## Run type checking only
|
| 50 |
+
$(MYPY) . --ignore-missing-imports --explicit-package-bases
|
| 51 |
+
|
| 52 |
+
# ---------- Quality (write mode for local dev) ----------
|
| 53 |
+
.PHONY: format
|
| 54 |
+
format: ## Auto-format & fix with ruff
|
| 55 |
+
$(RUFF) format .
|
| 56 |
+
$(RUFF) check . --fix
|
| 57 |
|
| 58 |
# ---------- Tests ----------
|
| 59 |
.PHONY: test
|
| 60 |
+
test: ## Run fast test suite (exclude slow)
|
| 61 |
+
PYTHONPATH=$$PWD $(PYTEST) -q -m "not slow"
|
| 62 |
+
|
| 63 |
+
.PHONY: test-all
|
| 64 |
+
test-all: ## Run full test suite including slow tests
|
| 65 |
PYTHONPATH=$$PWD $(PYTEST) -q
|
| 66 |
|
| 67 |
.PHONY: cov
|
| 68 |
cov: ## Run tests with coverage
|
| 69 |
PYTHONPATH=$$PWD $(PYTEST) --cov=nl2sql --cov-report=term-missing
|
| 70 |
|
| 71 |
+
# ---------- Unified gate for CI ----------
|
| 72 |
+
.PHONY: check
|
| 73 |
+
check: ## Run format check, lint, typecheck, and fast tests
|
| 74 |
+
make fmt-check
|
| 75 |
+
make lint
|
| 76 |
+
make typecheck
|
| 77 |
+
make test
|
| 78 |
+
|
| 79 |
# ---------- Pre-commit ----------
|
| 80 |
.PHONY: precommit
|
| 81 |
precommit: ## Run all pre-commit hooks on all files
|
|
|
|
| 103 |
# ---------- Clean ----------
|
| 104 |
.PHONY: clean
|
| 105 |
clean: ## Remove Python caches
|
| 106 |
+
rm -rf __pycache__ .pytest_cache .mypy_cache .ruff_cache
|
| 107 |
|
| 108 |
.PHONY: clean-all
|
| 109 |
clean-all: clean ## Remove build artifacts and coverage
|