Skip to content

Commit

Permalink
fix: Automate publishing
Browse files Browse the repository at this point in the history
The `nvector` project now use python-semantic-release for automating its releases
in order to simplify the process.
  • Loading branch information
pbrod committed Oct 2, 2024
1 parent b570b09 commit 279ec70
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 25 deletions.
122 changes: 115 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# This workflow will install Python dependencies and run tests with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# This workflow will do Continous Integration (CI) and Continous Deployment (CD).
# It will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see:
# https://py-pkgs.org/08-ci-cd
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: nvector-test
name: ci-cd

# Controls when the workflow will run
on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run
# sequentially or in parallel
jobs:
test:

ci:
# Set up operating system
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ["3.12"] #, "3.11", "3.10", "3.9"]
os: [ubuntu-latest] #, macOS-latest, windows-latest]
fail-fast: false

steps:
Expand All @@ -27,3 +33,105 @@ jobs:
- name: Run Tests
run: |
pdm run pytest
release1:
concurrency: release1
permissions:
contents: write
# Only run this job if the "ci" job passes
needs: ci

# Only run this job if new work is pushed to the "master" branch
if: github.event_name == 'push' && github.ref == 'refs/heads/master'

# Set up operating system
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.release.outputs.tag }}
released: ${{ steps.release.outputs.released }}

# Define job steps
steps:
- name: Set up Python 3.12
uses: actions/setup-python@main
with:
python-version: 3.12
- name: Check-out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: master
submodules: recursive

- name: Use Python Semantic Release to prepare release
id: release
uses: python-semantic-release/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish package distributions to GitHub Releases
uses: python-semantic-release/publish-action@main
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Store the distribution packages
uses: actions/upload-artifact@v4
if: steps.release.outputs.released == 'true'
with:
name: python-package-distributions
path: dist/

# testpypi-publish:
# needs: release1
# if: needs.release1.outputs.released == 'true'
# runs-on: ubuntu-latest
# permissions:
# # IMPORTANT: this permission is mandatory for trusted publishing
# id-token: write
# # Dedicated environments with protections for publishing are strongly recommended.
# environment:
# name: pypi
# # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
# url: https://test.pypi.org/p/nvector
#
# steps:
# - name: Retrieve release distributions
# uses: actions/download-artifact@v4
# with:
# name: python-package-distributions
# path: dist/
#
# - name: Publish release distributions to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# - name: Test install from TestPyPI
# run: |
# pip install \
# --index-url https://test.pypi.org/simple/ \
# --extra-index-url https://pypi.org/simple/ \
# nvector

pypi-publish:
runs-on: ubuntu-latest
needs: release1
# if: needs.release1.outputs.released == 'true'
# needs: testpypi-publish

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

# Dedicated environments with protections for publishing are strongly recommended.
environment:
name: pypi
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
url: https://pypi.org/p/nvector

steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
91 changes: 75 additions & 16 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Short version
-------------

* Submit bug reports and feature requests at
[GitHub](https://github.com/pbrod/nvector/issues)
`GitHub <https://github.com/pbrod/nvector/issues>`_

* Make pull requests to the ``develop`` branch.

Bug reports
-----------

When [reporting a bug](https://github.com/pbrod/nvector/issues) please
When `reporting a bug <https://github.com/pbrod/nvector/issues>`_ please
include:

* Your operating system name and version
Expand All @@ -28,7 +28,7 @@ Feature requests and feedback
-----------------------------

The best way to send feedback is to file an issue at
[GitHub](https://github.com/pbrod/nvector/issues).
`GitHub. <https://github.com/pbrod/nvector/issues>`_

If you are proposing a feature:

Expand All @@ -50,27 +50,28 @@ The following are optional, but recommended.

* The CPython interpreter version 3.12
* You can install it using official binaries, pyenv, or any Anaconda-like distribution
* The [PDM](https://pdm-project.org/latest/) application for locking, building, and testing.
* Dedicated IDE like PyCharm, Spyder, or [VSCodium](https://vscodium.com/) to name a few. These allow more flexible git
* The `PDM <https://pdm-project.org/latest/>`_ application for locking, building, and testing.
* Dedicated IDE like PyCharm, Spyder, or `VSCodium <https://vscodium.com/>`_ to name a few. These allow more flexible git
control.


Development Steps
-----------------

1. [Fork nvector on GitHub](https://github.com/pbrod/nvector)
1. `Fork nvector on GitHub <https://github.com/pbrod/nvector>`_

2. Clone your fork locally. Using the command line would be:

```shell
git clone [email protected]/<USER>/nvector.git
```

3. Create a branch for local development. Using the command line would be:

```shell
git checkout -b name-of-your-bugfix-or-feature
```

Now you can make changes and commit them.

4. When you're done making changes, run all the checks to ensure that nothing
Expand All @@ -95,7 +96,7 @@ Development Steps
pdm run nox
```

5. For linting the source code you can use `ruff <https://pypi.org/project/ruff/#description>`_
5. For linting the source code you can use `ruff <https://pypi.org/project/ruff/#description>`_:

```shell
ruff format ./src
Expand All @@ -109,11 +110,11 @@ Development Steps

```shell
git add <FILE1> <FILE2> ... <FILEN>
git commit -m "TAG: Brief description. Longer description later."
git commit -m "<type>(<scope>): <subject> <BLANK LINE> <body> <BLANK LINE> <footer>"
```
The `nvector` package does not follow any development workflows at this time, but one should be adopted like NumPy
workflow with tags.

See :ref:`commit-message-guidelines`.


9. Once you are happy with the local changes, push to GitHub:

Expand All @@ -128,6 +129,64 @@ Development Steps
made to the ``develop`` branch (subject to change). Note that automated tests will be run on
GitHub actions, but these must be initialized by a member of the team.

.. _commit-message-guidelines:

Commit message guidelines
-------------------------
The `nvector` project uses python-semantic-release for automating the releases.
By analyzing the commit messages it takes care of incrementing the version number
and update the changelog as well as publish the package.

Therefore the commit messages must follow the
`angular commit message style <https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits>`_
This leads to more readable messages that are easy to follow when looking through the
project history.
Each commit message consists of a ``header``, a ``body`` and a ``footer``.
The header has a special format that includes a ``type``, a ``scope`` and a ``subject``::

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

The ``header`` is mandatory and the ``scope`` of the ``header`` is optional.

Any line of the commit message cannot be longer than 100 characters!
This allows the message to be easier to read on GitHub as well as in various git tools.
The ``body`` or ``footer`` can begin with BREAKING CHANGE:
followed by a short description to create a major release.

The ``type`` must be one of the following:

* feat: A new feature
* fix: A bug fix
* docs: Documentation only changes
* style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
* refactor: A code change that neither fixes a bug nor adds a feature
* perf: A code change that improves performance
* test: Adding missing or correcting existing tests
* chore: Changes to the build process or auxiliary tools and libraries such as documentation generation

The ``scope`` could be anything specifying place of the commit change.
For example $core, $objects, $rotation, etc...

The ``subject`` contains succinct description of the change:

* use the imperative, present tense: "change" not "changed" nor "changes"
* don't capitalize first letter
* no dot (.) at the end

The ``body`` should include the motivation for the change and contrast this
with previous behavior. Use the imperative, present tense:
"change" not "changed" nor "changes".

The ``footer`` should contain any information about Breaking Changes and is
also the place to reference GitHub issues that this commit closes.

Breaking Changes should start with the word BREAKING CHANGE: with a space or two newlines.
The rest of the commit message is then used for this.


Pull Request Guidelines
-----------------------
Expand All @@ -138,9 +197,8 @@ make a pull request. Pull requests should be made to the ``develop`` branch (sub
For merging, you should:

1. Include an example for use
2. Add a note to `CHANGELOG.rst` about the changes
3. Update the author list in `AUTHORS.rst` if applicable
4. Ensure that all checks passed (current checks include GitHub Actions)
2. Update the author list in `AUTHORS.rst` if applicable
3. Ensure that all checks passed (current checks include GitHub Actions)

If you don't have all the necessary Python versions available locally or have
trouble building all the testing environments, you can rely on GitHub Actions
Expand All @@ -152,7 +210,8 @@ Project Style Guidelines
------------------------

The `nvector` project follows the
[Napoleon NumPy style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/#google-vs-numpy) with type-hinting.
`Napoleon NumPy style <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/#google-vs-numpy>`_
with type-hinting.
A good example is the following:

.. code-block:: python
Expand Down
37 changes: 36 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@ plot =["matplotlib>=3.8.0",
repository = "https://github.com/pbrod/nvector/"
documentation = "https://nvector.readthedocs.io/en/latest/"

[tool.semantic_release]
commit_parser = "angular"
logging_use_named_masks = true
allow_zero_version = true
tag_format = "v{version}"
version_variables = ["./src/nvector/__init__.py:__version__"]

commit_message = "chore(release): {version}\n\nAutomatically generated by python-semantic-release"

branch= "master" # branch to make releases of
build_command = "pip install pdm && pdm build" # build dists

[tool.semantic_release.changelog]

changelog_file = "CHANGELOG.rst" # changelog file
exclude_commit_patterns = [".*\\n\\nAutomatically generated by python-semantic-release", "chore: pre-commit autoupdate\n\nAutomatically generated by pre-commit.ci"]

[tool.semantic_release.commit_parser_options]
allowed_types = [
"build", "chore", "ci", "docs", "feat", "fix",
"perf", "style", "refactor", "test",
]
minor_types = ["feat"]
patch_types = ["fix", "perf"]

# chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
# docs: Documentation only changes
# feat: A new feature
# fix: A bug fix
# perf: A code change that improves performance
# refactor: A code change that neither fixes a bug nor adds a feature
# style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
# test: Adding missing or correcting existing tests


[build-system]
requires = ["pdm-backend"]
Expand All @@ -71,7 +105,8 @@ lock_linux = "pdm lock -L pdm_linux.lock --python 3.12 --strategy no_direct_mini
[tool.pdm.dev-dependencies]
build = [
"setuptools>=39.2", # MHogan: Pycharm complains oddly without this on Windows platform
"spyder-kernels" # Mhogan: If you want to use Spyder
"spyder-kernels", # Mhogan: If you want to use Spyder
"python-semantic-release>=9.0.3",
]
test = [
"nox",
Expand Down
2 changes: 1 addition & 1 deletion src/nvector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .objects import * # noqa
from ._common import use_docstring

__version__ = "1.0.0"
__version__ = "1.0.1"

_PACKAGE_NAME = __name__

Expand Down

0 comments on commit 279ec70

Please sign in to comment.