Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Use custom action, activate linter #97

Merged
merged 5 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/actions/poetry-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "Resolve dependencies with Poetry"
description: "Setup Python, install and cache Poetry and resolves dependencies using it."

inputs:
python-version:
description: "Version of Python to setup"
required: true
poetry-version:
description: "Version of Poetry to install"
default: "1.8.2"

runs:
using: "composite"
steps:
- name: Setup Pipx Local Variables
id: pipx-env-setup
run: |
SEP="${{ startsWith(runner.os, 'windows-') && '\\' || '/' }}"
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT
echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT
echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV
echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV
echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV
echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH
shell: bash

- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
with:
path: |
${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
key: poetry-v${{ inputs.poetry-version }}-${{ runner.os }}-Python${{ inputs.python-version }}

- name: Install Poetry ${{ inputs.poetry-version }}
if: steps.cached-poetry.outputs.cache-hit != 'true'
run: pipx install poetry==${{ inputs.poetry-version }}
shell: bash

- name: Configure Poetry
run: poetry config virtualenvs.in-project true
shell: bash

- name: Setup Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: "poetry"

- name: Install Poetry dependencies
# Should be cached by the action above
run: poetry install
shell: bash
13 changes: 2 additions & 11 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
- name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies
uses: ./.github/actions/poetry-setup
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"

- name: Install poetry
run: pipx install poetry

- name: Setup poetry
run: |
poetry config virtualenvs.in-project true
poetry install --without dev

- name: Build package
run: |
Expand Down
55 changes: 22 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install and configure poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
- name: Setup Python
uses: actions/setup-python@v5

- name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies
uses: ./.github/actions/poetry-setup
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
- name: Setup poetry
run: poetry install

- name: Run tests
run: |
source .venv/bin/activate
Expand All @@ -53,27 +48,25 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install and configure poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
- name: Setup Python
uses: actions/setup-python@v5

- name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies
uses: ./.github/actions/poetry-setup
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
- name: Setup poetry
run: poetry install
- uses: actions/setup-node@v4

- name: Setup NodeJS ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
cache-dependency-path: tests/apollo-server/

- name: Install deps and run server
run: |
cd tests/apollo-server/
npm ci
node src/index.js &

- name: Wait for server
run: |
for i in {0..10}; do
Expand All @@ -88,6 +81,7 @@ jobs:
exit 1
fi
done

- name: Test with pytest
run: |
source .venv/bin/activate
Expand All @@ -96,28 +90,23 @@ jobs:
lint:
runs-on: ubuntu-latest

if: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install and configure poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
- name: Setup Python
uses: actions/setup-python@v5

- name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies
uses: ./.github/actions/poetry-setup
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
- name: Setup poetry
run: poetry install

- name: Run lint
if: always()
# A few checks are skipped for now because the code can't pass them
# TODO: reactivate them
run: |
source .venv/bin/activate
isort -m 9 --line-length 160 $MODULE_NAME tests --check-only
pylint $MODULE_NAME tests
isort -m 9 --line-length 160 $MODULE_NAME tests --gitignore --check-only
# pylint $MODULE_NAME tests
docformatter --wrap-summaries 160 --wrap-descriptions 160 -cr $MODULE_NAME tests
black --check $MODULE_NAME tests
mypy -V
mypy $MODULE_NAME tests
# mypy $MODULE_NAME tests
2 changes: 1 addition & 1 deletion clairvoyance/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from clairvoyance import graphql
from clairvoyance.entities import GraphQLPrimitive
from clairvoyance.entities.errors import EndpointError
from clairvoyance.entities.context import client, config, log
from clairvoyance.entities.errors import EndpointError
from clairvoyance.entities.oracle import FuzzingContext
from clairvoyance.utils import track

Expand Down