From 2895a6fee80ed8a93c81d9d5ff6aec5da81a2c1a Mon Sep 17 00:00:00 2001 From: "james.richardson" Date: Thu, 8 Dec 2022 11:15:05 +0100 Subject: [PATCH 1/3] include empty github action files in all builds --- cookiecutter.json | 2 +- hooks/post_gen_project.py | 9 +++- tests/test_options.py | 46 +++++++++++++++++-- .../.github/actions/deploy/action.yml | 0 .../.github/workflows/deploy.yml | 0 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/.github/actions/deploy/action.yml create mode 100644 {{cookiecutter.project_slug}}/.github/workflows/deploy.yml 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..e69de29 From 0239bebade32cdfb2c68d2efcfeca6f5fe7c59ad Mon Sep 17 00:00:00 2001 From: "james.richardson" Date: Thu, 8 Dec 2022 17:15:12 +0100 Subject: [PATCH 2/3] correct typo --- .../.github/workflows/deploy.yml | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml b/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml index e69de29..f7cc54e 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml @@ -0,0 +1,98 @@ +name: Deploy my package + +on: + push: + branches: + - "master" + - "features/**" + - "improvements/**" + - "bug-fixes/**" + +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 %} + + From e8060f1bb7884f6fad62782eece9ca55013d3f88 Mon Sep 17 00:00:00 2001 From: Christian Baur Date: Fri, 1 Sep 2023 12:01:48 +0200 Subject: [PATCH 3/3] resolve request if on PR on the branches main and master --- .../.github/workflows/deploy.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml b/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml index f7cc54e..d702a08 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml @@ -1,13 +1,11 @@ name: Deploy my package on: - push: + pull_request: branches: + - "main" - "master" - - "features/**" - - "improvements/**" - - "bug-fixes/**" - + env: PACKAGE_NAME: {{ cookiecutter.module_name }} ARTIFACTS_PATH: artifacts @@ -47,7 +45,7 @@ jobs: with: name: $PACKAGE_NAME-package path: "$ARTIFACTS_PATH/dist/$PACKAGE_NAME-*.whl" - + test-unit: name: Run unit tests runs-on: ubuntu-latest @@ -80,7 +78,7 @@ jobs: poetry install --no-root source `poetry env info --path`/bin/activate pytest tests - + {% elif cookiecutter.package_manager == 'conda' -%} run: | source activate venv @@ -94,5 +92,3 @@ jobs: pip install install dist/{{ cookiecutter.module_name }}-*.whl pytest tests {%- endif %} - -