diff --git a/.actrc b/.actrc new file mode 100644 index 0000000..d3e0780 --- /dev/null +++ b/.actrc @@ -0,0 +1 @@ +-P ubuntu-24.04=catthehacker/ubuntu:act-latest diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..e276052 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,54 @@ +name: Run Tests + +on: + pull_request: + push: + branches: + - master + +jobs: + tests: + runs-on: ubuntu-24.04 + + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + env: + E2E_PG_HOST: 127.0.0.1 + E2E_PG_PORT: 5432 + E2E_PG_USER: postgres + E2E_PG_PASSWORD: postgres + E2E_PG_DB: postgres + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y postgresql-client + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest pytest-timeout + + - name: Run tests + run: | + python -m pytest -vv + diff --git a/Makefile b/Makefile index c70b861..13120da 100644 --- a/Makefile +++ b/Makefile @@ -63,4 +63,13 @@ test: ## Start local PostgreSQL container and run all tests E2E_PG_DB=$(PG_TEST_DB) \ $(VENV_DIR)/bin/$(PYTHON_CMD) -m pytest -vv -.PHONY: usage install install-test install-lint clean publish test lint +ACT_CMD ?= act +ACT_WORKFLOW ?= .github/workflows/tests.yml +ACT_JOB ?= tests +ACT_PULL ?= false +ACT_CONTAINER_ARCH ?= linux/arm64 + +test-act: ## Run the CI test workflow locally with act + $(ACT_CMD) -W $(ACT_WORKFLOW) -j $(ACT_JOB) --pull=$(ACT_PULL) --container-architecture $(ACT_CONTAINER_ARCH) + +.PHONY: usage install install-test install-lint clean publish test test-act lint diff --git a/README.md b/README.md index 6283025..8fca98d 100644 --- a/README.md +++ b/README.md @@ -148,3 +148,27 @@ python -m pytest tests/test_plugins.py -vv ``` If PostgreSQL is not reachable, tests fail fast at startup. + +#### 3) Run CI locally with `act` + +Run the GitHub Actions test workflow locally with [`act`](https://github.com/nektos/act): + +On macOS, install `act` with Homebrew: + +```bash +brew install act +``` + +```bash +make test-act +``` + +Useful overrides for local runs: + +```bash +# Refresh images explicitly when needed +make test-act ACT_PULL=true + +# Match GitHub runner architecture on Apple Silicon (slower) +make test-act ACT_CONTAINER_ARCH=linux/amd64 +```