From a4f1acf17e952cb058676d75b3e0054ffee57643 Mon Sep 17 00:00:00 2001 From: Arnav Choudhury Date: Tue, 23 Feb 2021 10:59:30 +0530 Subject: [PATCH 1/4] Updated the github action to run all pre-commit hooks on all files in the linter stage so that there is only 1 place that is used to maange all code quality tools. --- {{cookiecutter.project_slug}}/.github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index 57add2c0..3a6b0284 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -16,7 +16,7 @@ on: jobs: - flake8: + linter: runs-on: ubuntu-latest steps: @@ -28,13 +28,13 @@ jobs: with: python-version: 3.8 - - name: Install flake8 + - name: Install flake8, flake8-isort, and black run: | python -m pip install --upgrade pip - pip install flake8 + pip install flake8 flake8-isort black - - name: Lint with flake8 - run: flake8 + - name: Install and Run Pre-commit + uses: pre-commit/action@v2.0.0 # With no caching at all the entire ci process takes 4m 30s to complete! pytest: From db636c8e3675132106ddc8ea99024a84ee594659 Mon Sep 17 00:00:00 2001 From: Arnav Choudhury Date: Tue, 23 Feb 2021 11:11:03 +0530 Subject: [PATCH 2/4] Updated tests with the updated github stage names. --- tests/test_cookiecutter_generation.py | 12 ++++++------ .../.github/workflows/ci.yml | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index af6e4588..a1dcf796 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -234,7 +234,7 @@ def test_gitlab_invokes_flake8_and_pytest( ("y", "docker-compose -f local.yml exec -T django pytest"), ], ) -def test_github_invokes_flake8_and_pytest( +def test_github_invokes_linter_and_pytest( cookies, context, use_docker, expected_test_script ): context.update({"ci_tool": "Github", "use_docker": use_docker}) @@ -248,11 +248,11 @@ def test_github_invokes_flake8_and_pytest( with open(f"{result.project}/.github/workflows/ci.yml", "r") as github_yml: try: github_config = yaml.safe_load(github_yml) - flake8_present = False - for action_step in github_config["jobs"]["flake8"]["steps"]: - if action_step.get("run") == "flake8": - flake8_present = True - assert flake8_present + linter_present = False + for action_step in github_config["jobs"]["linter"]["steps"]: + if action_step.get("run") == "linter": + linter_present = True + assert linter_present expected_test_script_present = False for action_step in github_config["jobs"]["pytest"]["steps"]: diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index 3a6b0284..a69b2c92 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -33,6 +33,9 @@ jobs: python -m pip install --upgrade pip pip install flake8 flake8-isort black + # Run all pre-commit hooks on all the files. + # Getting only staged files can be tricky in case a new PR is opened + # since the action is run on a branch in detached head state - name: Install and Run Pre-commit uses: pre-commit/action@v2.0.0 From fbc9b89e0d37d70b0e65db0f7b1d77f311989b50 Mon Sep 17 00:00:00 2001 From: Arnav Choudhury Date: Tue, 23 Feb 2021 11:28:37 +0530 Subject: [PATCH 3/4] Updated tests with the updated github stage names. --- tests/test_cookiecutter_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index a1dcf796..c8514493 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -250,7 +250,7 @@ def test_github_invokes_linter_and_pytest( github_config = yaml.safe_load(github_yml) linter_present = False for action_step in github_config["jobs"]["linter"]["steps"]: - if action_step.get("run") == "linter": + if action_step.get("uses", "NA").startswith("pre-commit"): linter_present = True assert linter_present From c988a6fbdc02eae7343749439ca01d81279dc7f2 Mon Sep 17 00:00:00 2001 From: Arnav Choudhury Date: Tue, 23 Feb 2021 19:20:17 +0530 Subject: [PATCH 4/4] Removed the step for installing dependencies --- {{cookiecutter.project_slug}}/.github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index a69b2c92..378ee30b 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -28,11 +28,6 @@ jobs: with: python-version: 3.8 - - name: Install flake8, flake8-isort, and black - run: | - python -m pip install --upgrade pip - pip install flake8 flake8-isort black - # Run all pre-commit hooks on all the files. # Getting only staged files can be tricky in case a new PR is opened # since the action is run on a branch in detached head state