diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..07259c48 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,54 @@ +env: + REGISTRY: ghcr.io/anthropics/anthropic-quickstarts +name: build +on: + pull_request: + paths: + - test/** + push: + branches: + - main + paths: + - test/** +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Login to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{github.actor}} + password: ${{secrets.GITHUB_TOKEN}} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Set image tag + run: | + short_sha=$(git rev-parse --short ${{ github.sha }}) + echo "TAG=${REGISTRY}:test-${short_sha}" >> "$GITHUB_ENV" + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: test/Dockerfile + push: false + tags: ${{ env.TAG }} + cache-from: type=gha + cache-to: type=gha,mode=max + load: true + - name: Determine push tags + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "PUSH_TAGS=${TAG}" >> "$GITHUB_ENV" + else + echo "PUSH_TAGS=${TAG},${REGISTRY}:test-latest" >> "$GITHUB_ENV" + fi + - name: Push Docker image + uses: docker/build-push-action@v5 + with: + context: test/Dockerfile + push: true + tags: ${{ env.PUSH_TAGS }} diff --git a/.github/workflows/lint_and_typecheck.yaml b/.github/workflows/lint_and_typecheck.yaml new file mode 100644 index 00000000..9d5cfe86 --- /dev/null +++ b/.github/workflows/lint_and_typecheck.yaml @@ -0,0 +1,27 @@ +name: lint-and-typecheck +on: [pull_request] +jobs: + ruff: + runs-on: ubuntu-latest + defaults: + run: + working-directory: test + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/ruff-action@v1 + pyright: + runs-on: ubuntu-latest + defaults: + run: + working-directory: test + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + cache: "pip" + - run: | + python -m venv .venv + source .venv/bin/activate + pip install -r dev-requirements.txt + - run: echo "$PWD/.venv/bin" >> $GITHUB_PATH + - uses: jakebailey/pyright-action@v1 diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 00000000..136bce1f --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,3 @@ +.venv +.ruff_cache +__pycache__ diff --git a/test/.pre-commit-config.yaml b/test/.pre-commit-config.yaml new file mode 100644 index 00000000..5687e2ef --- /dev/null +++ b/test/.pre-commit-config.yaml @@ -0,0 +1,23 @@ +default_stages: [pre-commit, pre-push] +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.7 + hooks: + - id: ruff + name: Run `ruff` to autofix lint errors + args: [--fix-only] + - id: ruff + name: Run `ruff` to format code + entry: ruff format --force-exclude + - id: ruff + name: Run `ruff` to lint code + - repo: https://github.com/RobertCraigie/pyright-python + rev: v1.1.384 + hooks: + - id: pyright diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 00000000..4440fb96 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,3 @@ +FROM docker.io/ubuntu:22.04 + +RUN touch test \ No newline at end of file diff --git a/test/dev-requirements.txt b/test/dev-requirements.txt new file mode 100644 index 00000000..4f098b7d --- /dev/null +++ b/test/dev-requirements.txt @@ -0,0 +1,4 @@ +ruff==0.6.7 +pre-commit==3.8.0 +pytest==8.3.3 +pytest-asyncio==0.23.6 diff --git a/test/pyproject.toml b/test/pyproject.toml new file mode 100644 index 00000000..34db860f --- /dev/null +++ b/test/pyproject.toml @@ -0,0 +1,7 @@ +[tool.pyright] +venvPath = "." +venv = ".venv" +useLibraryCodeForTypes = false + +[tool.pytest.ini_options] +asyncio_mode = "auto" diff --git a/test/ruff.toml b/test/ruff.toml new file mode 100644 index 00000000..18d30ac3 --- /dev/null +++ b/test/ruff.toml @@ -0,0 +1,24 @@ +extend-exclude = [".venv"] + +[format] +docstring-code-format = true + +[lint] +select = [ + "A", + "ASYNC", + "B", + "E", + "F", + "I", + "PIE", + "RUF200", + "T20", + "UP", + "W", +] + +ignore = ["E501", "ASYNC230"] + +[lint.isort] +combine-as-imports = true diff --git a/test/setup.sh b/test/setup.sh new file mode 100755 index 00000000..f8b992dd --- /dev/null +++ b/test/setup.sh @@ -0,0 +1,6 @@ +#!/bin/bash +python3 -m venv .venv +source .venv/bin/activate +pip install --upgrade pip +pip install -r dev-requirements.txt +pre-commit install