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

Adding Circle Ci to the template #306

Merged
merged 15 commits into from
Oct 4, 2024
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ jobs:
- automation.sh
- auto-format-tools.sh
- build-systems.sh
- ci.sh
- containers.sh
- docs-jupyter-book.sh
- docs-mkdocs.sh
Expand Down
1 change: 1 addition & 0 deletions .makim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ groups:
run: |
./tests/smoke/auto-format-tools.sh
./tests/smoke/build-systems.sh
./tests/smoke/ci.sh
./tests/smoke/cli.sh
./tests/smoke/containers.sh
./tests/smoke/docs-jupyter-book.sh
Expand Down
1 change: 1 addition & 0 deletions conda/dev-win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ channels:
dependencies:
- m2-bash
- git
- opensciencelabs::circleci-cli
- python >=3.8.1,<3.12
- poetry >=1.5
- nodejs
Expand Down
1 change: 1 addition & 0 deletions conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ channels:
dependencies:
- bash
- git
- opensciencelabs::circleci-cli
- python >=3.8.1,<3.12
- poetry >=1.5
- nodejs
Expand Down
20 changes: 20 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,3 +971,23 @@ By providing this information, you can easily integrate your codebase with
GitHub and take advantage of its powerful version control features. These
functionalities in SciCookie make it easy to manage your project and collaborate
with others, while ensuring that your code is properly versioned and tracked.

## Continuos integration

Continuous Integration (CI) is a development practice where code changes are
frequently merged into a shared repository. Each change is automatically built
and tested to ensure it does not introduce defects or break existing
functionality. This process helps prevent integration issues and improves code
quality.

CI tools provide automated feedback on code changes, allowing developers to
quickly identify and fix problems. By automating repetitive tasks, CI also saves
time and effort. With SciCookie you can integrate tools like GitHub and/or
CircleCI into your project.

- GitHub Actions (**github_actions**): This option allows you to incorporate
GitHub Actions into your project. As a native CI/CD platform integrated with
GitHub, it offers flexible workflows and an easy setup process.
- CircleCI (**circleci**): This option enables you to integrate CircleCI into
your project. Known for its speed and reliability, CircleCI is a cloud-based
CI/CD platform that streamlines the development process.
4 changes: 3 additions & 1 deletion src/scicookie/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@
"git_username": "zoro_roronoa",
"git_https_origin": "",
"git_https_upstream": "",
"git_main_branch": "main"
"git_main_branch": "main",
"use_github_actions": "no",
"use_circleci": "no"
}
10 changes: 10 additions & 0 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
USE_PRE_COMMIT = {{ cookiecutter.use_pre_commit == "yes" }}
USE_PYTEST = {{ cookiecutter.use_pytest == "yes" }}
USE_HYPOTHESIS = {{ cookiecutter.use_hypothesis == "yes" }}
USE_GITHUB_ACTIONS = {{ cookiecutter.use_github_actions == "yes" }}
USE_CIRCLECI = {{ cookiecutter.use_circleci == "yes" }}
{% if cookiecutter.code_of_conduct == "contributor-covenant" -%}
COC_PATH = PROJECT_DIRECTORY / 'coc' / 'CONTRIBUTOR_COVENANT.md'
{%- elif cookiecutter.code_of_conduct == "citizen-code-of-conduct" -%}
Expand Down Expand Up @@ -98,6 +100,7 @@
{%- endif %}



def remove_dirs(dirs: list):
for dirs in dirs:
shutil.rmtree(dirs)
Expand Down Expand Up @@ -319,6 +322,12 @@ def clean_up_build_system():
remove_dir("build-system")


def clean_up_ci():
if not USE_CIRCLECI:
remove_dir(".circleci")
if not USE_GITHUB_ACTIONS:
remove_dir(".github")

def http2ssh(url):
url = url.replace("https://", "git@")
return url.replace("/", ":", 1)
Expand Down Expand Up @@ -420,6 +429,7 @@ def prepare_git() -> None:
def post_gen():
# keep this one first, because it changes the package folder
clean_up_project_layout()
clean_up_ci()
clean_up_automation()
clean_up_cli()
clean_up_code_of_conduct()
Expand Down
9 changes: 9 additions & 0 deletions src/scicookie/profiles/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,12 @@ git_main_branch:
type: "text"
default: main
visible: true

continuos_integration:
message: Select one option for Continuous Integration
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide/#continuous-integration"
type: multiple-choices
choices:
- github_actions
- circleci
visible: true
5 changes: 5 additions & 0 deletions src/scicookie/profiles/osl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ git_https_upstream:

git_main_branch:
visible: true

continuos_integration:
choices:
- github_actions
visible: false
81 changes: 81 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
version: 2.1 # Adjust if needed based on CircleCI requirements
executors:
default_image:
docker:
{%- if cookiecutter.use_conda == "yes" %}
- image: continuumio/miniconda3
jobs:
check-branch:
executor: default_image
steps:
- checkout
test:
docker:
- image: continuumio/miniconda3
steps:
- checkout
- run:
name: Create environment
command: |
conda env create -f conda/dev.yaml
conda init bash
source ~/.bashrc
conda activate {{ cookiecutter.project_slug }}
{%- else %}
- image: cimg/python:3.10 # Adjust Python version if needed
jobs:
check-branch:
executor: default_image
steps:
- checkout
test:
executor: default_image
steps:
- checkout
- run:
name: Create environment and install dependencies
command: |
python -m pip install -r requirements.txt
{%- endif %}
{%- if cookiecutter.build_system == "poetry" %}
poetry install
{%- elif cookiecutter.build_system == "flit" %}
flit install
{%- elif cookiecutter.build_system == "pdm" %}
pdm install
{%- else %}
pip install .
{%- endif %}
export PATH=$PATH:/home/circleci/.pyenv/versions/3.10.15/bin;
Anavelyz marked this conversation as resolved.
Show resolved Hide resolved
{%- if cookiecutter.use_pre_commit == "yes" %}
pre-commit install
{%- endif %}
{%- if cookiecutter.use_makim == "yes" %}
makim tests.unit
makim tests.linter
{%- endif %}
{%- if cookiecutter.use_make == "yes" %}
make test
make lint
{%- endif %}
{%- if cookiecutter.use_conda == "yes" %}
- save_cache:
paths:
- ~/.conda/envs/{{ cookiecutter.project_slug }}
key: conda-{% raw %}{{ checksum "conda/dev.yaml" }}{% endraw %}
{%- endif %}
workflows:
main:
jobs:
- check-branch:
filters:
branches:
only:
- main
tags: {}
- test:
filters:
branches:
only:
- main
tags: {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ theme:
name: mkdocs
{% else %}
name: {{ cookiecutter.mkdocs_theme }}
{% endif%}
{% endif %}
features:
- content.code.annotate
- content.tabs.link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_content_pytest():
{%- if cookiecutter.use_hypothesis == "yes" %}


@given(st.text())
@given(st.text().filter(lambda s: s != ""))
def test_content_hypothesis(response_hypothesis):
"""Test with pytest + hypothesis."""
assert response_hypothesis
Expand Down
9 changes: 9 additions & 0 deletions tests/profiles/test-depends-on.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,12 @@ git_main_branch:
type: "text"
default: main
visible: true

continuos_integration:
message: Select one option for Continuous Integration
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide/#continuous-integration"
type: multiple-choices
choices:
- github_actions
- circleci
visible: true
9 changes: 9 additions & 0 deletions tests/profiles/test-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,12 @@ git_main_branch:
type: "text"
default: main
visible: true

continuos_integration:
message: Select one option for Continuous Integration
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide/#continuous-integration"
type: multiple-choices
choices:
- github_actions
- circleci
visible: true
19 changes: 19 additions & 0 deletions tests/smoke/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e

SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# run the complete smoke tests
. ${SMOKE_DIR}/base.sh "use_circleci=yes use_conda=yes"
. ${SMOKE_DIR}/base.sh "use_circleci=yes use_pyenv=yes"

# check the CI files from template
. ${SMOKE_DIR}/base-template.sh "use_circleci=yes use_conda=yes"
Anavelyz marked this conversation as resolved.
Show resolved Hide resolved
pushd /tmp/osl/osl-python-package
circleci config validate
popd

. ${SMOKE_DIR}/base-template.sh "use_circleci=yes use_pyenv=yes"
pushd /tmp/osl/osl-python-package
circleci config validate
popd
Loading