Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Drone CI #4382

Merged
merged 5 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -130,6 +130,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 @@ -189,4 +190,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 @@ -239,6 +239,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 @@ -494,6 +498,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 @@ -125,6 +125,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
commands:
- pip install -r requirements/local.txt
- pytest
{%- endif%}

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