From 97935112664cb5c267f3099a395f004ff8c7e873 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 2 Mar 2021 19:48:26 +0000 Subject: [PATCH 1/5] Support both master and main branches --- {{cookiecutter.project_slug}}/.github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index 378ee30b..c8bda217 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -7,11 +7,11 @@ env: on: pull_request: - branches: [ "master" ] + branches: [ "master", "main" ] paths-ignore: [ "docs/**" ] push: - branches: [ "master" ] + branches: [ "master", "main" ] paths-ignore: [ "docs/**" ] From c1ec7e3cd1fe6d4fc578430cf013b098611d5557 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 2 Mar 2021 20:03:14 +0000 Subject: [PATCH 2/5] Add necessary services for GH actions without Docker --- .../.github/workflows/ci.yml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index c8bda217..c84d3eeb 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -37,6 +37,30 @@ jobs: # With no caching at all the entire ci process takes 4m 30s to complete! pytest: runs-on: ubuntu-latest + {%- if cookiecutter.use_docker == 'n' %} + + services: + {%- if cookiecutter.use_celery == 'y' %} + redis: + image: redis:5.0 + ports: + - 6379:6379 + {%- endif %} + postgres: + image: postgres:12 + ports: + - 5432:5432 + env: + POSTGRES_PASSWORD: postgres + + env: + {%- if cookiecutter.use_celery == 'y' %} + CELERY_BROKER_URL: "redis://localhost:6379/0" + {%- endif %} + # postgres://user:password@host:port/database + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres" + {%- endif %} + steps: - name: Checkout Code Repository From c3ee08fbb2be2688af155e3eb36a14be438f5d3d Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 2 Mar 2021 20:03:27 +0000 Subject: [PATCH 3/5] Tweak formatting of workflow file --- {{cookiecutter.project_slug}}/.github/workflows/ci.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index c84d3eeb..7799cf41 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: - 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! + # With no caching at all the entire ci process takes 4m 30s to complete! pytest: runs-on: ubuntu-latest {%- if cookiecutter.use_docker == 'n' %} @@ -65,7 +65,7 @@ jobs: - name: Checkout Code Repository uses: actions/checkout@v2 - {% if cookiecutter.use_docker == 'y' -%} + {%- if cookiecutter.use_docker == 'y' %} - name: Build the Stack run: docker-compose -f local.yml build @@ -81,7 +81,6 @@ jobs: - name: Tear down the Stack run: docker-compose -f local.yml down - {%- else %} - name: Set up Python 3.8 @@ -93,8 +92,8 @@ jobs: id: pip-cache-location run: | echo "::set-output name=dir::$(pip cache dir)" + {%- raw %} - {% raw %} - name: Cache pip Project Dependencies uses: actions/cache@v2 with: @@ -104,7 +103,7 @@ jobs: key: ${{ runner.os }}-pip-${{ hashFiles('**/local.txt') }} restore-keys: | ${{ runner.os }}-pip- - {% endraw %} + {%- endraw %} - name: Install Dependencies run: | @@ -113,5 +112,4 @@ jobs: - name: Test with pytest run: pytest - {%- endif %} From d999846ca27693dfa0efb0813e477a03f968d704 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 2 Mar 2021 20:11:15 +0000 Subject: [PATCH 4/5] Fix Github CI with Docker --- {{cookiecutter.project_slug}}/.github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index 7799cf41..9798e6c8 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -70,14 +70,11 @@ jobs: - name: Build the Stack run: docker-compose -f local.yml build - - name: Make DB Migrations + - name: Run DB Migrations run: docker-compose -f local.yml run --rm django python manage.py migrate - - name: Run the Stack - run: docker-compose -f local.yml up -d - - name: Run Django Tests - run: docker-compose -f local.yml exec -T django pytest + run: docker-compose -f local.yml run django pytest - name: Tear down the Stack run: docker-compose -f local.yml down From a6e45554500fa7b2c2883710d1085833d635bb9d Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 2 Mar 2021 21:20:20 +0000 Subject: [PATCH 5/5] Update tests --- 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 c8514493..7e585ea4 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -231,7 +231,7 @@ def test_gitlab_invokes_flake8_and_pytest( ["use_docker", "expected_test_script"], [ ("n", "pytest"), - ("y", "docker-compose -f local.yml exec -T django pytest"), + ("y", "docker-compose -f local.yml run django pytest"), ], ) def test_github_invokes_linter_and_pytest(