Add option to choose CI tool

This commit is contained in:
Ivan Khomutov 2019-12-06 10:55:00 +03:00
parent efbf164e84
commit 113ce88d9c
5 changed files with 75 additions and 6 deletions

View File

@ -40,7 +40,11 @@
"use_sentry": "n",
"use_whitenoise": "n",
"use_heroku": "n",
"use_travisci": "n",
"ci_tool": [
"None",
"Travis",
"Gitlab"
],
"keep_local_envs_in_vcs": "y",
"debug": "n"

View File

@ -94,8 +94,12 @@ use_heroku:
Indicates whether the project should be configured so as to be deployable
to Heroku_.
use_travisci:
Indicates whether the project should be configured to use `Travis CI`_.
ci_tool:
Select a CI tool for running tests. The choices are:
1. None
2. Travis_
3. Gitlab_
keep_local_envs_in_vcs:
Indicates whether the project's ``.envs/.local/`` should be kept in VCS
@ -138,3 +142,6 @@ debug:
.. _Heroku: https://github.com/heroku/heroku-buildpack-python
.. _Travis CI: https://travis-ci.org/
.. _GitLab CI: https://docs.gitlab.com/ee/ci/

View File

@ -70,7 +70,7 @@ def remove_heroku_files():
for file_name in file_names:
if (
file_name == "requirements.txt"
and "{{ cookiecutter.use_travisci }}".lower() == "y"
and "{{ cookiecutter.ci_tool }}".lower() == "travis"
):
# don't remove the file if we are using travisci but not using heroku
continue
@ -105,6 +105,10 @@ def remove_dottravisyml_file():
os.remove(".travis.yml")
def remove_dotgitlabciyml_file():
os.remove(".gitlab-ci.yml")
def append_to_project_gitignore(path):
gitignore_file_path = ".gitignore"
with open(gitignore_file_path, "a") as gitignore_file:
@ -349,9 +353,12 @@ def main():
if "{{ cookiecutter.use_docker }}".lower() == "y":
remove_celery_compose_dirs()
if "{{ cookiecutter.use_travisci }}".lower() == "n":
if "{{ cookiecutter.ci_tool }}".lower() != "travis":
remove_dottravisyml_file()
if "{{ cookiecutter.ci_tool }}".lower() != "gitlab":
remove_dotgitlabciyml_file()
print(SUCCESS + "Project initialized, keep up the good work!" + TERMINATOR)

View File

@ -140,7 +140,7 @@ def test_black_passes(cookies, context_combination):
def test_travis_invokes_pytest(cookies, context):
context.update({"use_travisci": "y"})
context.update({"ci_tool": "Travis"})
result = cookies.bake(extra_context=context)
assert result.exit_code == 0
@ -155,6 +155,24 @@ def test_travis_invokes_pytest(cookies, context):
pytest.fail(e)
def test_gitlab_invokes_flake8_and_pytest(cookies, context):
context.update({"ci_tool": "Gitlab"})
result = cookies.bake(extra_context=context)
assert result.exit_code == 0
assert result.exception is None
assert result.project.basename == context["project_slug"]
assert result.project.isdir()
with open(f"{result.project}/.gitlab-ci.yml", "r") as gitlab_yml:
try:
gitlab_config = yaml.load(gitlab_yml)
assert gitlab_config["flake8"]["script"] == ["flake8"]
assert gitlab_config["pytest"]["script"] == ["pytest"]
except yaml.YAMLError as e:
pytest.fail(e)
@pytest.mark.parametrize("slug", ["project slug", "Project_Slug"])
def test_invalid_slug(cookies, context, slug):
"""Invalid slug should failed pre-generation hook."""

View File

@ -0,0 +1,33 @@
stages:
- lint
- test
variables:
POSTGRES_USER: '{{ cookiecutter.project_slug }}'
POSTGRES_PASSWORD: ''
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
flake8:
stage: lint
image: python:3.7-alpine
before_script:
- pip install -q flake8
script:
- flake8
pytest:
stage: test
image: python:3.7
tags:
- docker
services:
- postgres:11
variables:
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
before_script:
- pip install -r requirements/local.txt
script:
- pytest