From 40ddc4b6af57c53b137981bf7b1c06c0d51c27d7 Mon Sep 17 00:00:00 2001 From: Shayan Karimi Date: Fri, 28 Jul 2023 15:33:47 +0330 Subject: [PATCH] Add support for Drone (#4382) * 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> --- cookiecutter.json | 2 +- docs/project-generation-options.rst | 3 ++ hooks/post_gen_project.py | 7 ++++ tests/test_cookiecutter_generation.py | 1 + {{cookiecutter.project_slug}}/.drone.yml | 48 ++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 {{cookiecutter.project_slug}}/.drone.yml diff --git a/cookiecutter.json b/cookiecutter.json index 3fcab4a7..f66e281f 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -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" } diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index edf2306d..bd368ae8 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -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 @@ -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 diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index a913f759..b2578262 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -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: @@ -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() diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index 853935e8..87e52ef0 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -127,6 +127,7 @@ SUPPORTED_COMBINATIONS = [ {"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"}, diff --git a/{{cookiecutter.project_slug}}/.drone.yml b/{{cookiecutter.project_slug}}/.drone.yml new file mode 100644 index 00000000..dc08bfba --- /dev/null +++ b/{{cookiecutter.project_slug}}/.drone.yml @@ -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