Skip to content

Commit

Permalink
test github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
x5a committed Oct 21, 2024
1 parent 9d5bb66 commit ec6d90c
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
27 changes: 27 additions & 0 deletions .github/workflows/lint_and_typecheck.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
.ruff_cache
__pycache__
23 changes: 23 additions & 0 deletions test/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM docker.io/ubuntu:22.04

RUN touch test
4 changes: 4 additions & 0 deletions test/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ruff==0.6.7
pre-commit==3.8.0
pytest==8.3.3
pytest-asyncio==0.23.6
7 changes: 7 additions & 0 deletions test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tool.pyright]
venvPath = "."
venv = ".venv"
useLibraryCodeForTypes = false

[tool.pytest.ini_options]
asyncio_mode = "auto"
24 changes: 24 additions & 0 deletions test/ruff.toml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/setup.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ec6d90c

Please sign in to comment.