From 12762f5027abee95bf2a3129d5914bc40700c673 Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 07:58:22 +0200 Subject: [PATCH 1/8] feat(CI): Add Github actions --- .github/workflows/python-app.yml | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..ef7728e --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,41 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Python Poetry Action + # You may pin to the exact commit or the version. + # uses: abatilo/actions-poetry@8284d202bc272a8d0597e26e1c0b4a0d0c73db93 + uses: abatilo/actions-poetry@v2.1.0 + with: + # The version of poetry to install + poetry-version: 1.1.7 + - name: Install dependencies + run: | + poetry install + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 7ef44355abdd4882ee45c1ea67ea6b5e6e7a8312 Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 08:06:31 +0200 Subject: [PATCH 2/8] fix(CI): Fix tool invocation with Poetry, add cache action --- .github/workflows/python-app.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ef7728e..fd1ff32 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -30,12 +30,22 @@ jobs: - name: Install dependencies run: | poetry install + - name: Cache + uses: actions/cache@v2.1.6 + with: + # A list of files, directories, and wildcard patterns to cache and restore + path: .venv + # An explicit key for restoring and saving the cache + key: venv-cache-${{hashfiles("poetry.lock") + restore-keys: | + venv-cache-${{hashfiles("poetry.lock") + venv-cache- - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest + poetry run pytest From cb1b4ecc08b89ba0baa794b4b4ffff4dfc2c870f Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 08:08:03 +0200 Subject: [PATCH 3/8] fix(CI): Fix syntax error in GH action --- .github/workflows/python-app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fd1ff32..0e97ae9 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -36,9 +36,9 @@ jobs: # A list of files, directories, and wildcard patterns to cache and restore path: .venv # An explicit key for restoring and saving the cache - key: venv-cache-${{hashfiles("poetry.lock") + key: venv-cache-${{hashfiles("poetry.lock")}} restore-keys: | - venv-cache-${{hashfiles("poetry.lock") + venv-cache-${{hashfiles("poetry.lock")}} venv-cache- - name: Lint with flake8 run: | From 767392a3bbfcd49ed030abe6285c03d8f6c84a48 Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 08:09:33 +0200 Subject: [PATCH 4/8] fix(CI): Fix cache file pattern --- .github/workflows/python-app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 0e97ae9..18b3aaf 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -36,9 +36,9 @@ jobs: # A list of files, directories, and wildcard patterns to cache and restore path: .venv # An explicit key for restoring and saving the cache - key: venv-cache-${{hashfiles("poetry.lock")}} + key: venv-cache-${{hashFiles('**/poetry.lock')}} restore-keys: | - venv-cache-${{hashfiles("poetry.lock")}} + venv-cache-${{hashFiles('**/poetry.lock')}} venv-cache- - name: Lint with flake8 run: | From 79ec49761490bfac8e6841b4afd9643ff486e1ea Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 08:14:04 +0200 Subject: [PATCH 5/8] feat(tests): Add bogus test suite to prevent pytest errors --- tests/test_example.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/test_example.py diff --git a/tests/test_example.py b/tests/test_example.py new file mode 100644 index 0000000..b2f43a8 --- /dev/null +++ b/tests/test_example.py @@ -0,0 +1,7 @@ +"""Placeholder test suite to Pytest doesn't exit with error code + +TODO: Remove once other tests have been added. +""" + +def test_example(): + assert True From 3fa66f028948666e5c86646b5b58f7858a65eacd Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 08:15:32 +0200 Subject: [PATCH 6/8] fix(CI): Move cache action before poetry install --- .github/workflows/python-app.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 18b3aaf..fd1ad90 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -20,16 +20,6 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 - - name: Python Poetry Action - # You may pin to the exact commit or the version. - # uses: abatilo/actions-poetry@8284d202bc272a8d0597e26e1c0b4a0d0c73db93 - uses: abatilo/actions-poetry@v2.1.0 - with: - # The version of poetry to install - poetry-version: 1.1.7 - - name: Install dependencies - run: | - poetry install - name: Cache uses: actions/cache@v2.1.6 with: @@ -40,6 +30,16 @@ jobs: restore-keys: | venv-cache-${{hashFiles('**/poetry.lock')}} venv-cache- + - name: Python Poetry Action + # You may pin to the exact commit or the version. + # uses: abatilo/actions-poetry@8284d202bc272a8d0597e26e1c0b4a0d0c73db93 + uses: abatilo/actions-poetry@v2.1.0 + with: + # The version of poetry to install + poetry-version: 1.1.7 + - name: Install dependencies + run: | + poetry install - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 5eeb0c5eae938aeb470ba96204e83447362e51a3 Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 08:19:26 +0200 Subject: [PATCH 7/8] fix(CI): Create Poetry venv in project --- .github/workflows/python-app.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fd1ad90..f777788 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -39,6 +39,7 @@ jobs: poetry-version: 1.1.7 - name: Install dependencies run: | + poetry config virtualenvs.in-project true poetry install - name: Lint with flake8 run: | From 68c879583a1e38aaf29323f00a7cd45a483dc0e6 Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Wed, 28 Jul 2021 08:26:36 +0200 Subject: [PATCH 8/8] fix(CI): Exclude venv from linting --- .github/workflows/python-app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index f777788..6f78ce1 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -44,9 +44,9 @@ jobs: - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + poetry run flake8 . --count --exclude .git,.venv --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + poetry run flake8 . --count --exclude .git,.venv --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | poetry run pytest