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 github actions to the CI options for the cookiecutter template #80

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -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"],
Expand Down
9 changes: 8 additions & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)

Expand Down
46 changes: 43 additions & 3 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
]
)
Empty file.
98 changes: 98 additions & 0 deletions {{cookiecutter.project_slug}}/.github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Deploy my package

on:
push:
branches:
- "master"
- "features/**"
- "improvements/**"
- "bug-fixes/**"
ChrsBaur marked this conversation as resolved.
Show resolved Hide resolved

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/[email protected]
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 %}