From 22119f8956119e567690ec8e8df4e694c8447ac3 Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Sat, 4 May 2024 12:52:31 +0200 Subject: [PATCH 1/5] CI: Use custom action, activate linter --- .github/workflows/cd.yml | 13 ++------ .github/workflows/tests.yml | 60 ++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 45 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 22a4b0f..6f82238 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -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: Privat33r-dev/pymonster@master 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: | diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 97e036c..692cb24 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: Privat33r-dev/pymonster@master with: python-version: ${{ env.PYTHON_VERSION }} - cache: "poetry" - - name: Setup poetry - run: poetry install + - name: Run tests run: | source .venv/bin/activate @@ -53,27 +48,28 @@ 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: Privat33r-dev/pymonster@master with: python-version: ${{ env.PYTHON_VERSION }} - cache: "poetry" - - name: Setup poetry - run: poetry install + + - uses: pnpm/action-setup@v3 + with: + version: 9 + - uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - cache: "npm" + cache: "pnpm" cache-dependency-path: tests/apollo-server/ + - name: Install deps and run server run: | cd tests/apollo-server/ - npm ci + pnpm install node src/index.js & + - name: Wait for server run: | for i in {0..10}; do @@ -88,6 +84,7 @@ jobs: exit 1 fi done + - name: Test with pytest run: | source .venv/bin/activate @@ -96,28 +93,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: Privat33r-dev/pymonster@master 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 From a40d2fb01662a4558fb0f61b08920dcd83e19549 Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Sat, 4 May 2024 13:15:31 +0200 Subject: [PATCH 2/5] Fix linting faliure on isort oracle.py --- clairvoyance/oracle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clairvoyance/oracle.py b/clairvoyance/oracle.py index d4dc9f6..3d2c8a6 100644 --- a/clairvoyance/oracle.py +++ b/clairvoyance/oracle.py @@ -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 From 30b754412953fedf0cb09d91ff294ff21141fb14 Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Sat, 4 May 2024 13:33:03 +0200 Subject: [PATCH 3/5] Change pnpm to npm to speed up action --- .github/workflows/tests.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 692cb24..02f0db7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -54,20 +54,17 @@ jobs: with: python-version: ${{ env.PYTHON_VERSION }} - - uses: pnpm/action-setup@v3 - with: - version: 9 - - - uses: actions/setup-node@v4 + - name: Setup NodeJS ${{ env.NODE_VERSION }} + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - cache: "pnpm" + cache: "npm" cache-dependency-path: tests/apollo-server/ - name: Install deps and run server run: | cd tests/apollo-server/ - pnpm install + npm ci node src/index.js & - name: Wait for server From 28aba24504684f56a6e51d0956425a69faf0f474 Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Sat, 10 Aug 2024 14:46:43 +0200 Subject: [PATCH 4/5] Move custom action inside --- .github/actions/poetry-setup/action.yml | 54 +++++++++++++++++++++++++ .github/workflows/cd.yml | 2 +- .github/workflows/tests.yml | 6 +-- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 .github/actions/poetry-setup/action.yml diff --git a/.github/actions/poetry-setup/action.yml b/.github/actions/poetry-setup/action.yml new file mode 100644 index 0000000..5cba405 --- /dev/null +++ b/.github/actions/poetry-setup/action.yml @@ -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 diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 6f82238..510e54d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -34,7 +34,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies - uses: Privat33r-dev/pymonster@master + uses: ./.github/actions/poetry-setup with: python-version: ${{ env.PYTHON_VERSION }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 02f0db7..a749856 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,7 +34,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies - uses: Privat33r-dev/pymonster@master + uses: ./.github/actions/poetry-setup with: python-version: ${{ env.PYTHON_VERSION }} @@ -50,7 +50,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies - uses: Privat33r-dev/pymonster@master + uses: ./.github/actions/poetry-setup with: python-version: ${{ env.PYTHON_VERSION }} @@ -95,7 +95,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Python ${{ env.PYTHON_VERSION }} and resolve Poetry dependencies - uses: Privat33r-dev/pymonster@master + uses: ./.github/actions/poetry-setup with: python-version: ${{ env.PYTHON_VERSION }} From 0835f788b51d7b4edc89370719e4de1f9fe0e964 Mon Sep 17 00:00:00 2001 From: Kerim Kabirov Date: Sat, 10 Aug 2024 17:24:41 +0200 Subject: [PATCH 5/5] Simplify path separator calculation Co-authored-by: Nikita Stupin <18281368+nikitastupin@users.noreply.github.com> --- .github/actions/poetry-setup/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/poetry-setup/action.yml b/.github/actions/poetry-setup/action.yml index 5cba405..2095ff1 100644 --- a/.github/actions/poetry-setup/action.yml +++ b/.github/actions/poetry-setup/action.yml @@ -15,7 +15,7 @@ runs: - name: Setup Pipx Local Variables id: pipx-env-setup run: | - SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}" + 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