diff --git a/cookiecutter.json b/cookiecutter.json index be82fea..0a40a2f 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -9,7 +9,7 @@ "package_manager": ["conda", "pip", "poetry"], "use_notebooks": ["no", "yes"], "use_docker": ["no", "yes"], - "ci_pipeline": ["none", "gitlab"], + "ci_pipeline": ["none", "gitlab", "github"], "create_cli": ["no", "yes"], "config_file": ["none", "hocon", "yaml"], "code_formatter": ["none", "black"], diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 3cf7a48..7427d5d 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -73,7 +73,12 @@ ".gitlab-ci.yml", } -files_ci_all = files_ci_gitlab +files_ci_github = { + ".github/workflows/deploy.yml", + ".github/actions/deploy/action.yml" +} + +files_ci_all = files_ci_gitlab | files_ci_github folders_editor = [ '.idea__editor', @@ -169,6 +174,8 @@ def handle_ci(): ci_pipeline = '{{ cookiecutter.ci_pipeline }}' if ci_pipeline == "gitlab": _delete_files(files_ci_all - files_ci_gitlab) + elif ci_pipeline == "github": + _delete_files(files_ci_all - files_ci_github) elif ci_pipeline == 'none': _delete_files(files_ci_all) diff --git a/tests/test_options.py b/tests/test_options.py index 6783bc5..228493c 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -196,6 +196,17 @@ def test_poetry_regression(): test_cli=False, run_pytest=True, ) +def test_no_ci_pipeline(): + check_project( + settings={ + "ci_pipeline": "none" + }, + files_non_existent=[ + ".gitlab-ci.yml", + ".github/workflows/deploy.yml", + ".github/actions/deploy/action.yml", + ] + ) def test_gitlab_pip(): check_project( @@ -224,10 +235,39 @@ def test_gitlab_poetry(): files_existent=[".gitlab-ci.yml"] ) -def test_no_ci_pipeline(): + +def test_github_pip(): check_project( settings={ - "ci_pipeline": "none" + "package_manager": "pip", + "ci_pipeline": "github" + }, + files_existent=[ + ".github/workflows/deploy.yml", + ".github/actions/deploy/action.yml", + ] + ) + +def test_github_conda(): + check_project( + settings={ + "package_manager": "conda", + "ci_pipeline": "github" + }, + files_existent=[ + ".github/workflows/deploy.yml", + ".github/actions/deploy/action.yml", + ] + ) + +def test_github_poetry(): + check_project( + settings={ + "package_manager": "poetry", + "ci_pipeline": "github" }, - files_non_existent=[".gitlab-ci.yml"] + files_existent=[ + ".github/workflows/deploy.yml", + ".github/actions/deploy/action.yml", + ] ) diff --git a/{{cookiecutter.project_slug}}/.github/actions/deploy/action.yml b/{{cookiecutter.project_slug}}/.github/actions/deploy/action.yml new file mode 100644 index 0000000..e69de29 diff --git a/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml b/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml new file mode 100644 index 0000000..d702a08 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml @@ -0,0 +1,94 @@ +name: Deploy my package + +on: + pull_request: + branches: + - "main" + - "master" + +env: + PACKAGE_NAME: {{ cookiecutter.module_name }} + ARTIFACTS_PATH: artifacts + {%- if cookiecutter.package_manager == 'poetry' %} + POETRY_VERSION: 1.0.5 + POETRY_CACHE_DIR: $CI_PROJECT_DIR/.cache/poetry + {%- endif %} + +jobs: + build: + name: Build package + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.10 + + - name: Build wheel + {% if cookiecutter.package_manager == 'poetry' -%} + run: | + pip install poetry==$POETRY_VERSION + poetry build -f wheel + mv dist/ $ARTIFACTS_PATH + {% else -%} + run: | + python -m pip install --upgrade pip + pip install setuptools wheel + python setup.py sdist bdist_wheel + mv dist/ $ARTIFACTS_PATH + {%- endif %} + + - name: Upload wheel as artifact + uses: actions/upload-artifact@master + with: + name: $PACKAGE_NAME-package + path: "$ARTIFACTS_PATH/dist/$PACKAGE_NAME-*.whl" + + test-unit: + name: Run unit tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Download wheel package + uses: actions/download-artifact@v3 + with: + name: $PACKAGE_NAME-package + path: dist/ + {% if cookiecutter.package_manager == 'conda' -%} + - name: Set up miniconda + uses: conda-incubator/setup-miniconda@v2.2.0 + with: + activate-environment: venv + environment-file: environment-dev.yml + python-version: 3.10 + auto-activate-base: false + {% else -%} + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.10 + {%- endif %} + - name: Run unit tests + {% if cookiecutter.package_manager == 'poetry' -%} + run: | + pip install poetry==$POETRY_VERSION + poetry install --no-root + source `poetry env info --path`/bin/activate + pytest tests + + {% elif cookiecutter.package_manager == 'conda' -%} + run: | + source activate venv + pip install dist/{{ cookiecutter.module_name }}-*.whl + pytest tests + {% elif cookiecutter.package_manager == 'pip' -%} + run: | + python -m venv venv + source venv/bin/activate + pip install -r requirements.txt -r requirements-dev.txt + pip install install dist/{{ cookiecutter.module_name }}-*.whl + pytest tests + {%- endif %}