Skip to content

Commit

Permalink
Merge pull request #1 from shaiu/shaiu/fix-tests
Browse files Browse the repository at this point in the history
add lint step
  • Loading branch information
shaiu authored Jul 12, 2024
2 parents 00b880c + ba78bba commit 310de1d
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 18 deletions.
134 changes: 116 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,125 @@ on:
- dev
- master

env:
CACHE_VERSION: 1
DEFAULT_PYTHON: "3.12"
PRE_COMMIT_CACHE: ~/.cache/pre-commit
UV_CACHE_DIR: /tmp/uv-cache

jobs:
info:
name: Collect information & changes data
outputs:
pre-commit_cache_key: ${{ steps.generate_pre-commit_cache_key.outputs.key }}
python_cache_key: ${{ steps.generate_python_cache_key.outputs.key }}
requirements: ${{ steps.core.outputs.requirements }}
python_versions: ${{ steps.info.outputs.python_versions }}
runs-on: ubuntu-22.04
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Generate partial Python venv restore key
id: generate_python_cache_key
run: |
echo key=venv-${{ env.CACHE_VERSION }}-${{
hashFiles('requirements_test.txt') }} >> $GITHUB_OUTPUT
- name: Generate partial pre-commit restore key
id: generate_pre-commit_cache_key
run: >-
echo "key=pre-commit-${{ env.CACHE_VERSION }}-${{
hashFiles('.pre-commit-config.yaml') }}" >> $GITHUB_OUTPUT
pre-commit:
name: Prepare pre-commit base
runs-on: ubuntu-22.04
needs:
- info
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{
needs.info.outputs.pre-commit_cache_key }}
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
python --version
pip install "$(grep '^uv' < requirements_test.txt)"
uv pip install "$(cat requirements_test.txt | grep pre-commit)"
- name: Restore pre-commit environment from cache
id: cache-precommit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
lookup-only: true
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
needs.info.outputs.pre-commit_cache_key }}
- name: Install pre-commit dependencies
if: steps.cache-precommit.outputs.cache-hit != 'true'
run: |
. venv/bin/activate
pre-commit install-hooks
lint-ruff-format:
name: Check ruff-format
runs-on: ubuntu-22.04
needs:
- info
- pre-commit
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/cache/[email protected]
with:
path: venv
fail-on-cache-miss: true
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{
needs.info.outputs.pre-commit_cache_key }}
- name: Restore pre-commit environment from cache
id: cache-precommit
uses: actions/cache/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
fail-on-cache-miss: true
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
needs.info.outputs.pre-commit_cache_key }}
- name: Run ruff-format
run: |
. venv/bin/activate
pre-commit run --hook-stage manual ruff-format --all-files --show-diff-on-failure
env:
RUFF_OUTPUT_FORMAT: github
test:
name: Tests

runs-on: ubuntu-latest
needs:
- lint-ruff-format

strategy:
matrix:
Expand All @@ -43,6 +157,8 @@ jobs:
name: Test Coverage

runs-on: ubuntu-latest
needs:
- test

steps:
- uses: actions/checkout@v3
Expand All @@ -65,21 +181,3 @@ jobs:
- uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

lint:

name: "Linting & Static Analysis"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.x"
architecture: x64

- uses: pre-commit/[email protected]
env:
SKIP: no-commit-to-branch
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ toml==0.10.2
tomlkit==0.13.0
types-pytz==2024.1.0.20240417
typing_extensions==4.12.2
uv==0.2.24
virtualenv==20.26.3
yarl==1.9.4

0 comments on commit 310de1d

Please sign in to comment.