Skip to content

Commit

Permalink
Add support for Drone (#4382)
Browse files Browse the repository at this point in the history
* Add overall config for drone.io support

* Update docs

* Configure basic CI setup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix python image version for tests step

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
shywn-mrk and pre-commit-ci[bot] authored Jul 28, 2023
1 parent 4e7aff3 commit 40ddc4b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"use_sentry": "n",
"use_whitenoise": "n",
"use_heroku": "n",
"ci_tool": ["None", "Travis", "Gitlab", "Github"],
"ci_tool": ["None", "Travis", "Gitlab", "Github", "Drone"],
"keep_local_envs_in_vcs": "y",
"debug": "n"
}
3 changes: 3 additions & 0 deletions docs/project-generation-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ ci_tool:
2. `Travis CI`_
3. `Gitlab CI`_
4. `Github Actions`_
5. `Drone CI`_

keep_local_envs_in_vcs:
Indicates whether the project's ``.envs/.local/`` should be kept in VCS
Expand Down Expand Up @@ -196,4 +197,6 @@ debug:

.. _GitLab CI: https://docs.gitlab.com/ee/ci/

.. _Drone CI: https://docs.drone.io/pipeline/overview/

.. _Github Actions: https://docs.github.com/en/actions
7 changes: 7 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def remove_dotgithub_folder():
shutil.rmtree(".github")


def remove_dotdrone_file():
os.remove(".drone.yml")


def generate_random_string(length, using_digits=False, using_ascii_letters=False, using_punctuation=False):
"""
Example:
Expand Down Expand Up @@ -491,6 +495,9 @@ def main():
if "{{ cookiecutter.ci_tool }}" != "Github":
remove_dotgithub_folder()

if "{{ cookiecutter.ci_tool }}" != "Drone":
remove_dotdrone_file()

if "{{ cookiecutter.use_drf }}".lower() == "n":
remove_drf_starter_files()

Expand Down
1 change: 1 addition & 0 deletions tests/test_cookiecutter_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def context():
{"ci_tool": "Travis"},
{"ci_tool": "Gitlab"},
{"ci_tool": "Github"},
{"ci_tool": "Drone"},
{"keep_local_envs_in_vcs": "y"},
{"keep_local_envs_in_vcs": "n"},
{"debug": "y"},
Expand Down
48 changes: 48 additions & 0 deletions {{cookiecutter.project_slug}}/.drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
kind: pipeline
name: default

environment:
POSTGRES_USER: '{{ cookiecutter.project_slug }}'
POSTGRES_PASSWORD: ''
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
POSTGRES_HOST_AUTH_METHOD: trust
{%- if cookiecutter.use_celery == 'y' %}
CELERY_BROKER_URL: 'redis://redis:6379/0'
{%- endif %}

steps:
- name: lint
pull: if-not-exists
image: python:3.11
environment:
PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
volumes:
- name: pre-commit cache
path: ${PRE_COMMIT_HOME}
commands:
- export PRE_COMMIT_HOME=$CI_PROJECT_DIR/.cache/pre-commit
- pip install -q pre-commit
- pre-commit run --show-diff-on-failure --color=always --all-files

- name: test
pull: if-not-exists
{%- if cookiecutter.use_docker == 'y' %}
image: docker/compose:1.29.2
environment:
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
commands:
- docker-compose -f local.yml build
- docker-compose -f local.yml run --rm django python manage.py migrate
- docker-compose -f local.yml up -d
- docker-compose -f local.yml run django pytest
{%- else %}
image: python:3.11
commands:
- pip install -r requirements/local.txt
- pytest
{%- endif%}

volumes:
- name: pre-commit cache
host:
path: /tmp/drone/cache/pre-commit

0 comments on commit 40ddc4b

Please sign in to comment.