Skip to content

Commit

Permalink
Refactor GitHub worflow for tests (#1913)
Browse files Browse the repository at this point in the history
* Remove custom cache and use GitHub's one

* Update actions's version, remove arg with default value

* Install poetry as soon as possible

* Remove stale comment

* Use correct python version for poetry

* Cache for django tests

* Split mypy tests

* Move pyright tests out

* Windows tests

* Update codeql

* More emojis

* Split starlette tests

* Less versions of starlette for now
  • Loading branch information
patrick91 committed May 19, 2022
1 parent 1b85e0c commit 35a627d
Show file tree
Hide file tree
Showing 14 changed files with 598 additions and 494 deletions.
40 changes: 13 additions & 27 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "CodeQL"
name: 馃攼 CodeQL

on:
push:
Expand All @@ -10,35 +10,21 @@ on:

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: ['python']
permissions:
security-events: write
actions: read
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
- name: Checkout repository
uses: actions/checkout@v3

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion .github/workflows/invite-contributors.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Invite contributors
name: 馃懃 Invite contributors

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: MyPy
name: 馃 MyPy

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ok-to-preview.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ok to preview
name: 馃啑 Ok to preview

on:
pull_request_target:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release test pre-release version
name: 馃巵 Release test pre-release version

on:
repository_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release file check
name: 馃啓 Release file check

on:
pull_request_target:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: 馃啓 Release

concurrency: release

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/slash-commands.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Slash Command Dispatch
name: 馃挰 Slash Command Dispatch

on:
issue_comment:
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/test-type-checkers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: 馃 Type checkers tests

concurrency:
group: type-checkers-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
push:
branches: [main]
pull_request:
branches: [main]
paths:
- "strawberry/**"
- "tests/mypy/**"
- "tests/pyright/**"
- "pyproject.toml"
- "poetry.lock"
- ".github/workflows/test-type-checkers.yml"

jobs:
mypy:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

name: Mypy on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/setup-python@v3.1.2
id: setup-python
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"

- run: poetry env use ${{ matrix.python-version }}
- run: poetry run python --version
- run: poetry install
if: steps.setup-python.outputs.cache-hit != 'true'

- name: pytest
run:
poetry run pytest tests/mypy

pyright:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

name: Pyright on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/setup-python@v3.1.2
id: setup-python
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"

- uses: actions/setup-node@v2
- run: npm install -g --no-package-lock --no-save pyright

- run: poetry env use ${{ matrix.python-version }}
- run: poetry run python --version
- run: poetry install
if: steps.setup-python.outputs.cache-hit != 'true'

- name: pytest
run:
poetry run pytest tests/pyright
139 changes: 88 additions & 51 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend tests
name: 馃攤 Unit tests

concurrency:
group: ${{ github.head_ref || github.run_id }}
Expand All @@ -20,48 +20,60 @@ jobs:
unit-tests:
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
cache-path: ~/.cache/pypoetry/virtualenvs
- os: windows-latest
cache-path: ~\AppData\Local\pypoetry\Cache
python-version: ["3.7", "3.8", "3.9", "3.10"]

name: Test ${{ matrix.os }} - Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/setup-python@v3.1.2
id: setup-python
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: "poetry"

- run: poetry env use ${{ matrix.python-version }}
- run: poetry run python --version
- run: poetry install
if: steps.setup-python.outputs.cache-hit != 'true'

- name: pytest
run:
poetry run pytest --cov-report xml --cov=. --showlocals -vv -m "not
starlette" -m "not django" --ignore=tests/mypy --ignore=tests/pyright

- uses: actions/setup-node@v2
- uses: codecov/codecov-action@v1
if: ${{ always() }}
with:
node-version: '14'
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true

- run: npm install -g --no-package-lock --no-save pyright
- run: pip install poetry
- run: poetry config experimental.new-installer false
unit-tests-on-windows:
name: Python 3.10 on Windows
runs-on: windows-latest

- name: "Python dependencies cache"
id: cache-poetry-dependencies
uses: actions/cache@v2
steps:
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/setup-python@v3.1.2
id: setup-python
with:
path: ${{ matrix.cache-path }}
key: ${{ runner.os }}-py-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: ${{ runner.os }}-py-${{ steps.setup-python.outputs.python-version }}-poetry-
python-version: "3.10"
cache: "poetry"

- name: Install dependencies
run: poetry install
if: steps.cache-poetry-dependencies.outputs.cache-hit != 'true'
- run:
poetry env use C:\hostedtoolcache\windows\Python\3.8.10\x86\python.exe
- run: poetry run python --version
- run: poetry install
if: steps.setup-python.outputs.cache-hit != 'true'

- name: pytest
run: poetry run pytest --cov-report xml --cov=. --showlocals -vv -m "not django"
run:
poetry run pytest --cov-report xml --cov=. --showlocals -vv -m "not
django" --ignore=tests/mypy --ignore=tests/pyright

- uses: codecov/codecov-action@v1
if: ${{ always() }}
Expand All @@ -75,40 +87,65 @@ jobs:
matrix:
django: ["4.0", "3.2"]

name: Test Django ${{ matrix.django }}
name: Django ${{ matrix.django }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/setup-python@v3.1.2
id: setup-python
with:
# Pin to 3.9 because Django 2.2 does not support 3.10
python-version: '3.9'
architecture: x64
python-version: "3.10"
cache: "poetry"

- run: poetry env use python3.10
- run: poetry install
if: steps.setup-python.outputs.cache-hit != 'true'

- name: Install django ${{ matrix.django }}
run: poetry add --python ^3.10 django@^${{ matrix.django }}

- name: pytest
run:
poetry run pytest --cov-report xml --cov=. --showlocals -vv -m django

- uses: codecov/codecov-action@v1
if: ${{ always() }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true

starlette-unit-tests:
strategy:
matrix:
# starlette: ["0.17.1", "0.18.0", "0.19.1", "0.20.0"]
starlette: ["0.17.1"]

- run: pip install poetry
- run: poetry config experimental.new-installer false
name: Starlette ${{ matrix.starlette }}
runs-on: ubuntu-latest

- name: "Python dependencies cache"
id: cache-poetry-dependencies
uses: actions/cache@v2
steps:
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/setup-python@v3.1.2
id: setup-python
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-py-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: ${{ runner.os }}-py-${{ steps.setup-python.outputs.python-version }}-poetry-
python-version: "3.10"
cache: "poetry"

- name: Install dependencies
run: poetry install
if: steps.cache-poetry-dependencies.outputs.cache-hit != 'true'
- run: poetry env use python3.10
- run: poetry install
if: steps.setup-python.outputs.cache-hit != 'true'

- name: Install django ${{ matrix.django }}
# Add --python ^3.9 marker because django 4.0 does not support 3.7
run: poetry add --python ^3.9 django@^${{ matrix.django }}
- name: Install django ${{ matrix.starlette }}
run: poetry add --python ^3.10 starlette@^${{ matrix.starlette }}

- name: pytest
run: poetry run pytest --cov-report xml --cov=. --showlocals -vv -m django
run:
poetry run pytest --cov-report xml --cov=. --showlocals -vv -m
starlette

- uses: codecov/codecov-action@v1
if: ${{ always() }}
Expand Down

0 comments on commit 35a627d

Please sign in to comment.