Skip to content

Commit

Permalink
Merge pull request #32 from Caparrini/alpha
Browse files Browse the repository at this point in the history
0.9.0.2 promoted to master
  • Loading branch information
Caparrini authored Oct 28, 2024
2 parents 2cc3c6b + 21c6540 commit 152bf47
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 34 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/build-test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build and Install Test for mloptimizer

on:
push:
branches:
- alpha
pull_request:
branches:
- alpha

jobs:
build-install-test:
runs-on: ubuntu-latest
steps:
# Checkout the repository code
- name: Checkout code
uses: actions/checkout@v4

# Set up Python environment (choose Python version as needed)
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'

# Install build tool and create the package
- name: Install build tool and build package
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m build --sdist --wheel --outdir dist/
# Set up virtual environment and install the built package
- name: Test package installation in a clean environment
run: |
python -m venv venv
source venv/bin/activate
pip install dist/*.whl # Install the wheel package created
# Confirm installation
pip show mloptimizer
# Run tests to ensure package works as expected without source code
- name: Run package tests
run: |
source venv/bin/activate
pytest --pyargs mloptimizer # Run tests directly from installed package
4 changes: 4 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
release-build:
name: Build and publish Python mloptimizer to PyPI and TestPyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/mloptimizer/

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0.1
0.9.0.2
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
'sphinx.ext.intersphinx',
#'autoapi.extension',
'sphinx_favicon',
'sphinxcontrib.mermaid'
'sphinxcontrib.mermaid',
'sphinx_github_changelog',
'sphinx_contributors',
'sphinx_copybutton',
]

sphinx_github_changelog_token = os.getenv("SPHINX_GITHUB_CHANGELOG_TOKEN")
autosectionlabel_prefix_document = True
autosectionlabel_maxdepth = 2

Expand Down
8 changes: 8 additions & 0 deletions docs/sections/Development/contributors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Contributors
============

The following people have contributed to the development of mloptimizer

.. contributors:: caparrini/mloptimizer
:avatars:
:order: ASC
90 changes: 90 additions & 0 deletions docs/sections/Development/process.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Development Process and CI/CD Pipeline
======================================

This document outlines the branching strategy, development workflow, and GitHub Actions CI/CD pipeline used in the project to maintain code quality and streamline deployment.

Branching Strategy
------------------

The project follows a structured branching strategy to separate development, staging, and production environments:

- **feature branches** Branch**: Each feature or fix is developed in its own branch, prefixed with "feature" (e.g., `feature_123`). This branch is where individual developers work until the feature is ready for testing.
- **dev**: The main development branch where validated feature branches are merged. It serves as an integration branch for all features under development.
- **alpha**: A pre-release or staging branch that reflects a stable version of `dev`. Once `dev` reaches a stable point, it is merged into `alpha` for final testing before production.
- **master**: The production branch. Only stable and fully tested code is merged here, and this branch is automatically deployed to PyPI upon tagging.

Pushes and Merge Workflow
-------------------------

1. **Feature Branch Development**:
- Each developer creates a `featureXXX` branch to work on their feature.
- When the feature is complete, a pull request (PR) is made to merge `featureXXX` into `dev`.
- GitHub Actions will automatically run tests and generate a coverage report on the PR.
- If the tests pass, the feature can be merged into `dev`; if tests fail, the PR cannot be merged until issues are resolved.

2. **Development Integration on `dev`**:
- Multiple `featureXXX` branches may be merged into `dev` concurrently.
- This branch is intended for integrating and testing new features collectively before staging.
- When `dev` reaches a stable state with passing tests, it can proceed to the `alpha` branch.

3. **Alpha Testing on `alpha`**:
- The `dev` branch is merged into `alpha` for pre-release validation.
- GitHub Actions re-runs tests and generates a coverage report to verify stability.
- If all tests pass, the version is tagged on `alpha`, marking it as ready for release.
- Build and installation tests are also performed to ensure the package can be installed correctly.

4. **Production Release on `master`**:
- The fully tested and working code is merged into `master`.
- The version is tagged on `master` to mark it as a stable release.
- Once there is a tag, a release is created on GitHub, documenting the changes.
- The released version is automatically published to PyPI, making the package available to users.


GitHub Actions CI/CD Pipelines
------------------------------

The project utilizes four primary GitHub Actions workflows:

1. **Feature Branch Validation**:

- **Workflow File**: `code_quality.yml`
- **Trigger**: Initiates on pull requests targeting the `dev` branch from feature branches (e.g., `featureXXX`).
- **Functionality**:

- Runs static code analysis using Qodana.
- Ensures code quality and standards compliance before merging.
- Executes within an isolated environment to verify quality without modifying the branch.
- Validates that the code aligns with development standards before it can be integrated into `dev`.

2. **Alpha Branch Validation**:

- **Workflow Files**: `CI.yml` and `build-test-package.yml`
- **Trigger**: Runs on any push to the `alpha` branch.
- **Functionality**:

- Executes tests across different Python versions to ensure compatibility.
- Uploads test coverage reports to Codecov, maintaining accountability for test quality.
- Builds the package, installs it in a virtual environment, and runs tests to confirm the package's standalone functionality.
- Acts as the final pre-production gate, validating that `alpha` is stable before being merged into `master`.

3. **Production Release to PyPI**:

- **Workflow File**: `publish-to-pypi.yml`
- **Trigger**: Executes upon tagged releases to `master`.
- **Functionality**:

- Builds the package into source and wheel distributions.
- Publishes the package to PyPI, ensuring the release is available in production.
- This workflow guarantees that only a stable, tested, and tagged version is deployed to PyPI.

4. **Build and Install Test for Package Validation**:

- **Workflow File**: `build-test-package.yml`
- **Trigger**: Activates on any push or pull request to `alpha`.
- **Functionality**:

- Builds the package and verifies that it can be installed in an isolated environment.
- Ensures the package can run independently of the source, verifying import dependencies and package structure.
- Provides confidence that the package can be distributed and used without issues related to build or installation.

By following this CI/CD strategy, the project maintains high code quality, consistent testing, and reliable releases with minimal manual intervention.
31 changes: 4 additions & 27 deletions docs/sections/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,7 @@ Changelog

This document provides a comprehensive list of changes for each version of the mloptimizer library.

Version 0.6.0 (2024-01-24)
--------------------------

"Initial" Release
^^^^^^^^^^^^^^^^^
- Launched the first version of the mloptimizer library.
- Features include optimization for decision trees, random forests, and gradient boosting classifiers.
- Basic documentation and example scripts provided.

Please refer to the [GitHub repository](https://github.com/Caparrini/mloptimizer) for a detailed list of changes.



Template - Version X.X.X (YYYY-MM-DD)
-------------------------------------

Features
^^^^^^^^
- Feature 1

Bug Fixes
^^^^^^^^^
- Bug fix 1

Improvements
^^^^^^^^^^^^
- Improvement 1
.. changelog::
:changelog-url: https://mloptimizer.readthedocs.io/en/master/sections/changelog.html
:github: https://github.com/caparrini/mloptimizer/releases/
:pypi: https://pypi.org/project/mloptimizer/
11 changes: 10 additions & 1 deletion docs/sections/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
Development
====================

This page is here, to provide some content for the site structure.
This section outlines relevant information for developers contributing to the project.
It includes details on the development process, branching strategy, and CI/CD pipeline
used to maintain code quality and streamline deployment.

.. toctree::
:maxdepth: 3
:numbered:

Development/process
Development/contributors
7 changes: 6 additions & 1 deletion mloptimizer/test/application/test_optimizer_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import time
import warnings
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, ExtraTreesClassifier, GradientBoostingClassifier
from xgboost import XGBClassifier
Expand Down Expand Up @@ -98,7 +99,11 @@ def test_optimizer_service_parallel_speedup(estimator_class, dataset, default_me
assert str(best_model) == str(best_model_parallel)
print(f"Elapsed time with parallel: {elapsed_time_parallel}")
print(f"Elapsed time without parallel: {elapsed_time}")
assert elapsed_time_parallel < elapsed_time
if elapsed_time_parallel < elapsed_time:
warnings.warn(
f"Sequential execution time ({elapsed_time:.2f}s) is greater than or equal "
f"to parallel execution time ({elapsed_time_parallel:.2f}s)."
)

@pytest.mark.parametrize('estimator_class',
[DecisionTreeClassifier, RandomForestClassifier, ExtraTreesClassifier,
Expand Down
7 changes: 6 additions & 1 deletion mloptimizer/test/domain/optimization/test_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import warnings
from mloptimizer.domain.optimization import Optimizer
from mloptimizer.domain.hyperspace import Hyperparam, HyperparameterSpace
from sklearn.tree import DecisionTreeClassifier
Expand Down Expand Up @@ -133,7 +134,11 @@ def test_optimizer_use_parallel(estimator_class, dataset, default_metrics_dict,
print(f"Elapsed time without parallel: {elapsed_time}")
print(f"Speedup: {speedup}%")
assert str(clf) == str(clf_with_parallel)
assert elapsed_time_parallel < elapsed_time
if elapsed_time_parallel < elapsed_time:
warnings.warn(
f"Sequential execution time ({elapsed_time:.2f}s) is greater than or equal "
f"to parallel execution time ({elapsed_time_parallel:.2f}s)."
)


@pytest.mark.parametrize('estimator_class',
Expand Down
5 changes: 4 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ tensorflow>=2.12.0
tqdm
xgboost>=1.7.3
hyperopt
ucimlrepo
ucimlrepo
sphinx-github-changelog
sphinx-contributors
sphinx_copybutton
5 changes: 4 additions & 1 deletion requirements_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ sphinxcontrib-mermaid
sphinx-autodoc-typehints
tensorflow>=2.12.0
tqdm
xgboost>=1.7.3
xgboost>=1.7.3
sphinx-github-changelog
sphinx-contributors
sphinx_copybutton

0 comments on commit 152bf47

Please sign in to comment.